本文整理汇总了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);
}
示例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;
}
示例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();
}*/
}
示例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;
}
示例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)
);
}
示例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;
}
示例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 "";
}
示例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);
}
示例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;
}
示例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";
}
示例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);
}
示例14: isLoggedIn
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public boolean isLoggedIn(HttpServletRequest req) {
return req.getUserPrincipal() != null;
}
示例15: getAccount
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
private SamlPrincipal getAccount(HttpServletRequest req) {
SamlPrincipal principal = (SamlPrincipal)req.getUserPrincipal();
return principal;
}