當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServletRequest.getUserPrincipal方法代碼示例

本文整理匯總了Java中javax.servlet.http.HttpServletRequest.getUserPrincipal方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletRequest.getUserPrincipal方法的具體用法?Java HttpServletRequest.getUserPrincipal怎麽用?Java HttpServletRequest.getUserPrincipal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.http.HttpServletRequest的用法示例。


在下文中一共展示了HttpServletRequest.getUserPrincipal方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doGet

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    req.login(USER, PWD);

    if (!req.getRemoteUser().equals(USER))
        throw new ServletException();
    if (!req.getUserPrincipal().getName().equals(USER))
        throw new ServletException();

    req.logout();

    if (req.getRemoteUser() != null)
        throw new ServletException();
    if (req.getUserPrincipal() != null)
        throw new ServletException();

    resp.getWriter().write(OK);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:21,代碼來源:TestRequest.java

示例2: constructCredentialsFromRequest

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
protected Credential constructCredentialsFromRequest(
        final RequestContext context) {
    final HttpServletRequest request = WebUtils
            .getHttpServletRequest(context);
    final Principal principal = request.getUserPrincipal();

    if (principal != null) {

        logger.debug("UserPrincipal [{}] found in HttpServletRequest", principal.getName());
        return new PrincipalBearingCredential(this.principalFactory.createPrincipal(principal.getName()));
    }

    logger.debug("UserPrincipal not found in HttpServletRequest.");
    return null;
}
 
開發者ID:yuweijun,項目名稱:cas-server-4.2.1,代碼行數:17,代碼來源:PrincipalFromRequestUserPrincipalNonInteractiveCredentialsAction.java

示例3: getUsername

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
    * TODO default proper exception at lams level to replace RuntimeException TODO isTesting should be removed when
    * login is done properly.
    *
    * @param req
    *            -
    * @return username from principal object
    */
   public static String getUsername(HttpServletRequest req, boolean isTesting) throws RuntimeException {
if (isTesting) {
    return "test";
}

Principal prin = req.getUserPrincipal();
if (prin == null) {
    throw new RuntimeException(
	    "Trying to get username but principal object missing. Request is " + req.toString());
}

String username = prin.getName();
if (username == null) {
    throw new RuntimeException("Name missing from principal object. Request is " + req.toString()
	    + " Principal object is " + prin.toString());
}

return username;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:28,代碼來源:WebUtil.java

示例4: reAuthenticate

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/** On entry it is assumed that a UserSession object exists. The purpose of this
 * function is to implement any required logic to re-validate that this UserSession is
 * still ok.
 *
 * On exit, if the UserSession object still exists in the HttpSession it is assumed that
 * it has been re-validated (regardless of whether it has been updated, or re-used for
 * another user). If it has been removed from the session, the assumtion is that
 * the reAuthentication failed.
 *
 * @param request HttpRequest that holds any log in context information
 */
private void reAuthenticate(HttpServletRequest request)
        throws IOException, ServletException {
    // Get the Current Session
    UserSession us = UserSession.getUserSession(request);

    // If we have an authenticated user ...
    if (request.getUserPrincipal() != null) {
        // ...and it is the same user that the valid session is for, we are ok
        if (us.isValid() && us.getUserId().equals(request.getUserPrincipal().getName())) {
            // no nothing, life is peachy!
            return;
        } else {
            // this is a differnt user, or an invalid session, so kill this UserSession and try an auto-authenticate
            us.kill();
            autoAuthenticate(request);
            return;
        }
    }/* else {
// We have reached the security manager, with out and authenticatic user,
// but we have a user session. We must therefore just kill it and continue.
us.kill();
}*/
}
 
開發者ID:jaffa-projects,項目名稱:jaffa-framework,代碼行數:35,代碼來源:PortletFilter.java

示例5: constructCredentialsFromRequest

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
protected Credential constructCredentialsFromRequest(
        final RequestContext context) {
    final HttpServletRequest request = WebUtils
            .getHttpServletRequest(context);
    final Principal principal = request.getUserPrincipal();

    if (principal != null) {

        logger.debug("UserPrincipal [{}] found in HttpServletRequest", principal.getName());
        return new PrincipalBearingCredential(new SimplePrincipal(
                principal.getName()));
    }

    logger.debug("UserPrincipal not found in HttpServletRequest.");
    return null;
}
 
開發者ID:luotuo,項目名稱:cas4.0.x-server-wechat,代碼行數:18,代碼來源:PrincipalFromRequestUserPrincipalNonInteractiveCredentialsAction.java

示例6: getCallerUserGroupInformation

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private UserGroupInformation getCallerUserGroupInformation(
    HttpServletRequest hsr, boolean usePrincipal) {

  String remoteUser = hsr.getRemoteUser();
  if (usePrincipal) {
    Principal princ = hsr.getUserPrincipal();
    remoteUser = princ == null ? null : princ.getName();
  }

  UserGroupInformation callerUGI = null;
  if (remoteUser != null) {
    callerUGI = UserGroupInformation.createRemoteUser(remoteUser);
  }

  return callerUGI;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:17,代碼來源:RMWebServices.java

示例7: httpRequestTags

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public Iterable<Tag> httpRequestTags(HttpServletRequest request,
           HttpServletResponse response,
           Throwable ex) {
	
	String principalName = null;
	if (request.getUserPrincipal() != null )
		principalName = request.getUserPrincipal().getName();

	return asList(WebMvcTags.method(request), WebMvcTags.uri(request), WebMvcTags.exception(ex), WebMvcTags.status(response),
			principal(principalName),
               projectName(principalName),
			deploymentName(principalName),
               deploymentVersion(principalName)
               );

	
}
 
開發者ID:SeldonIO,項目名稱:seldon-core,代碼行數:19,代碼來源:AuthorizedWebMvcTagsProvider.java

示例8: bindPage

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * 轉發綁定頁麵
 *
 * @param client
 * @return
 */
@RequestMapping("/bind/{client}")
public String bindPage(@PathVariable("client") String client, Model model, HttpServletRequest request) {
    Pac4jPrincipal pac4jPrincipal = (Pac4jPrincipal) request.getUserPrincipal();
    model.addAttribute("user", pac4jPrincipal.getProfile().getId());
    return "bind/" + client;
}
 
開發者ID:kawhii,項目名稱:sso,代碼行數:13,代碼來源:BindController.java

示例9: getLabelEditorLink

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/** A convenience method to return a hyperlink to the LabelEditor component.
 * A blank string will be returned, if the user does not have access to the component 'Jaffa.Admin.LabelEditor'.
 * @param pageContext The PageContext of the jsp.
 * @param labelFilter The label to be edited. The labelFilter should be of the type 'xyz', '[xyz]'. Values of the type 'abc [xyz] efg [zzz]' will be ignored and a blank string will be returned.
 * @return the HTML for the hyperlink to the LabelEditor component.
 */
public static String getLabelEditorLink(PageContext pageContext, String labelFilter) {
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    
    // Perform the logic only if the user has been authenticated
    if (request.getUserPrincipal() != null) {
        String labelEditorPrefix = null;
        HttpSession session = request.getSession(false);
        if (session != null) {
            // Check the session for the cached prefix
            labelEditorPrefix = (String) session.getAttribute(ATTRIBUTE_LABEL_EDITOR_LINK_PREFIX);
            if (labelEditorPrefix == null) {
                labelEditorPrefix = constructLabelEditorLinkPrefix(request);
                session.setAttribute(ATTRIBUTE_LABEL_EDITOR_LINK_PREFIX, labelEditorPrefix);
            }
        } else {
            // No session, so simply create the prefix each time
            labelEditorPrefix = constructLabelEditorLinkPrefix(request);
        }
        
        if (labelEditorPrefix.length() > 0) {
            // Ensure that the labelFilter is of the type 'xyz' or '[xyz]'
            // Remove the outer token markers, if any
            // Then proceed only if no more token-markers exist
            labelFilter = MessageHelper.removeTokenMarkers(labelFilter);
            if (!MessageHelper.hasTokens(labelFilter))
                return labelEditorPrefix + labelFilter + LABEL_EDITOR_LINK_SUFFIX;
        }
    }
    
    // We'll reach this point if the user is not aunthenticated or has no access to the component or if the labelFilter is invalid
    // Just return a blank String
    return "";
}
 
開發者ID:jaffa-projects,項目名稱:jaffa-framework,代碼行數:40,代碼來源:TagHelper.java

示例10: process

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public void process(Exchange exchange) throws Exception {
    HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class);

    // KeycloakPrincipal encapsulates informations like token etc
    KeycloakPrincipal keycloakPrincipal = (KeycloakPrincipal) req.getUserPrincipal();

    String suffix = (String) exchange.getIn().getHeader("id");

    exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/json");
    Message message = new Message("camel - " + suffix);
    String jsonResponse = JsonSerialization.writeValueAsString(message);
    exchange.getOut().setBody(jsonResponse);
}
 
開發者ID:nmajorov,項目名稱:keycloak_training,代碼行數:15,代碼來源:CamelHelloProcessor.java

示例11: encryptRequest

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private HttpServletRequest encryptRequest(HttpServletRequest request) {
	ModifiableHttpServletRequest modifiableRequest = new ModifiableHttpServletRequest(request);
	Principal principal = request.getUserPrincipal();
	AuthUserResponse userDetails = userService.getUserInfoFromAuthEmail(principal.getName());
	
	try {
		InputStream encryptedNoteStream = encryptionService.encryptNote(request.getInputStream(), userDetails.getCryptKey(), principal.getName());
		modifiableRequest.setInputStream(new SimpleServletInputStream(encryptedNoteStream));
	} catch (IOException e) {
		logger.warn("Cannot fetch ServletRequest InputStream!",e);
	}
	return modifiableRequest;
}
 
開發者ID:daflockinger,項目名稱:poppynotes,代碼行數:14,代碼來源:InCommingNoteEncryptingFilter.java

示例12: index

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@GetMapping("/")
public String index(HttpServletRequest request, Model model) {
    //用戶詳細信息
    Principal principal = request.getUserPrincipal();
    model.addAttribute("user", principal);
    //打開index.html頁麵
    return "index";
}
 
開發者ID:kawhii,項目名稱:sso,代碼行數:9,代碼來源:IndexController.java

示例13: doPost

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
public void doPost(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse) throws ServletException, IOException {
    final SecurityManager instance = SecurityManager.getInstance();
    final Principal userPrincipal = httpServletRequest.getUserPrincipal();
    final String name = userPrincipal.getName();
    final User userByName = instance.getUserByName(name);
//    final RightSet userRights = instance.getUserRights();
    if (!userByName.isAdmin()) httpServletResponse.sendError(401);
    super.doPost(httpServletRequest, httpServletResponse);
  }
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:10,代碼來源:ParabuildWebServiceServlet.java

示例14: isLoggedIn

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
public boolean isLoggedIn(HttpServletRequest req) {
    return req.getUserPrincipal() != null;
}
 
開發者ID:nmajorov,項目名稱:keycloak_training,代碼行數:4,代碼來源:Controller.java

示例15: getAccount

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private SamlPrincipal getAccount(HttpServletRequest req) {
    SamlPrincipal principal = (SamlPrincipal)req.getUserPrincipal();
    return principal;
}
 
開發者ID:nmajorov,項目名稱:keycloak_training,代碼行數:5,代碼來源:Controller.java


注:本文中的javax.servlet.http.HttpServletRequest.getUserPrincipal方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。