principal java,Java Session.setPrincipal方法代码示例

import org.apache.catalina.Session; //导入方法依赖的package包/类

/**

* Register an authenticated Principal and authentication type in our

* request, in the current session (if there is one), and with our

* SingleSignOn valve, if there is one. Set the appropriate cookie

* to be returned.

*

* @param request The servlet request we are processing

* @param response The servlet response we are generating

* @param principal The authenticated Principal to be registered

* @param authType The authentication type to be registered

* @param username Username used to authenticate (if any)

* @param password Password used to authenticate (if any)

*/

protected void register(HttpRequest request, HttpResponse response,

Principal principal, String authType,

String username, String password) {

if (debug >= 1)

log("Authenticated '" + principal.getName() + "' with type '"

+ authType + "'");

// Cache the authentication information in our request

request.setAuthType(authType);

request.setUserPrincipal(principal);

// Cache the authentication information in our session, if any

if (cache) {

Session session = getSession(request, false);

if (session != null) {

session.setAuthType(authType);

session.setPrincipal(principal);

if (username != null)

session.setNote(Constants.SESS_USERNAME_NOTE, username);

else

session.removeNote(Constants.SESS_USERNAME_NOTE);

if (password != null)

session.setNote(Constants.SESS_PASSWORD_NOTE, password);

else

session.removeNote(Constants.SESS_PASSWORD_NOTE);

}

}

// Construct a cookie to be returned to the client

if (sso == null)

return;

HttpServletRequest hreq =

(HttpServletRequest) request.getRequest();

HttpServletResponse hres =

(HttpServletResponse) response.getResponse();

String value = generateSessionId();

Cookie cookie = new Cookie(Constants.SINGLE_SIGN_ON_COOKIE, value);

cookie.setMaxAge(-1);

cookie.setPath("/");

hres.addCookie(cookie);

// Register this principal with our SSO valve

sso.register(value, principal, authType, username, password);

request.setNote(Constants.REQ_SSOID_NOTE, value);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值