List of usage examples for javax.servlet.http HttpServletRequest getUserPrincipal
public java.security.Principal getUserPrincipal();
java.security.Principal
object containing the name of the current authenticated user. From source file:cn.edu.zjnu.acm.judge.service.UserDetailService.java
@Nonnull public static Optional<UserModel> getCurrentUser(@Nonnull HttpServletRequest request) { return Optional.ofNullable(request.getUserPrincipal()).filter(x -> x instanceof Authentication) .map(Authentication.class::cast).map(Authentication::getPrincipal) .filter(x -> x instanceof UserModel).map(UserModel.class::cast); }
From source file:org.nuxeo.ecm.platform.ui.web.auth.plugins.AnonymousAuthenticator.java
public static boolean isAnonymousRequest(HttpServletRequest httpRequest) { Principal user = httpRequest.getUserPrincipal(); if (user != null && user instanceof NuxeoPrincipal) { return ((NuxeoPrincipal) user).isAnonymous(); }/*from w w w .ja v a2 s . co m*/ return false; }
From source file:com.hortonworks.example.util.Util.java
public static String getPrincipalName(HttpServletRequest request) { String n = null;//from www. java2s .c o m Principal p = request.getUserPrincipal(); if (p != null) { n = p.getName(); } return n; }
From source file:nl.b3p.catalog.security.GisPrincipal.java
public static GisPrincipal getGisPrincipal(HttpServletRequest request) { Principal user = request.getUserPrincipal(); if (!(user instanceof GisPrincipal && request instanceof SecurityRequestWrapper)) { return null; }//ww w . j a v a2 s . c o m GisPrincipal gp = (GisPrincipal) user; String code = request.getParameter(URL_AUTH); if (code != null && code.length() != 0) { if (gp != null && code.equals(gp.getCode())) { return gp; } // user is using different code, so invalidate session and login again HttpSession session = request.getSession(); session.invalidate(); String url = GisSecurityRealm.createCapabilitiesURL(code); gp = GisSecurityRealm.authenticateHttp(url, ConfigServlet.ANONYMOUS_USER, null, code); } // log in found principal if (gp != null) { SecurityRequestWrapper srw = (SecurityRequestWrapper) request; srw.setUserPrincipal(gp); log.debug("Automatic login for user: " + gp.name); } return gp; }
From source file:nl.b3p.datastorelinker.security.GisPrincipal.java
public static GisPrincipal getGisPrincipal(HttpServletRequest request) { Principal user = request.getUserPrincipal(); if (!(user instanceof GisPrincipal && request instanceof SecurityRequestWrapper)) { return null; }// w w w .jav a 2s . c o m GisPrincipal gp = (GisPrincipal) user; String code = request.getParameter(URL_AUTH); if (code != null && code.length() != 0) { if (gp != null && code.equals(gp.getCode())) { return gp; } // user is using different code, so invalidate session and login again HttpSession session = request.getSession(); session.invalidate(); //String url = GisSecurityRealm.createCapabilitiesURL(code); //gp = GisSecurityRealm.authenticateHttp(url, ConfigServlet.ANONYMOUS_USER, null, code); } // log in found principal if (gp != null) { SecurityRequestWrapper srw = (SecurityRequestWrapper) request; srw.setUserPrincipal(gp); log.debug("Automatic login for user: " + gp.name); } return gp; }
From source file:com.yahoo.dba.perf.myperf.springmvc.MyPerfBaseController.java
public static String findUserFromRequest(HttpServletRequest req) { if (req.getUserPrincipal() != null) return req.getUserPrincipal().getName();//find from security login JAAS if (req.getSession() != null) { try {/*w w w . j av a2 s . c o m*/ return retrieveAppUser(req).getName();//find from session } catch (Exception ex) { } } return null; }
From source file:it.geosolutions.geostore.services.rest.auditing.AuditInfoExtractor.java
private static void fillAuthInfo(Map<String, String> info, HttpServletRequest httpServletRequest) { Principal userPrincipal = httpServletRequest.getUserPrincipal(); String userName = ""; String userRole = ""; String userGroups = ""; if (userPrincipal != null && userPrincipal instanceof Authentication) { Authentication authentication = (Authentication) userPrincipal; Object principal = authentication.getPrincipal(); if (principal != null && principal instanceof User) { User user = (User) principal; userName = user.getName();// ww w .j a v a2s . c om userRole = user.getRole().name(); userGroups = groupsToString(user.getGroups()); } } info.put(AuditInfo.USER_NAME.getKey(), userName); info.put(AuditInfo.USER_ROLE.getKey(), userRole); info.put(AuditInfo.USER_GROUPS.getKey(), userGroups); }
From source file:com.jdon.strutsutil.FormBeanUtil.java
public static String getName(HttpServletRequest request) throws Exception { Principal principal = request.getUserPrincipal(); if (principal == null) { Debug.logError("[JdonFramework] No Principal", module); throw new Exception(" No Principal"); }/*from w w w . ja v a 2s .c o m*/ return principal.getName(); }
From source file:net.sourceforge.vulcan.web.struts.actions.ManualBuildAction.java
static String getRequestUsernameOrHostname(HttpServletRequest request) { final Principal userPrincipal = request.getUserPrincipal(); if (userPrincipal != null) { return userPrincipal.getName(); }//w w w . j ava 2 s .co m return request.getRemoteHost(); }
From source file:net.sourceforge.vulcan.web.SignedRequestAuthorizationFilterTest.java
private static HttpServletRequest matchRequestWithPrincipal(final HttpServletRequest expected, final String principalName) { EasyMock.reportMatcher(new IArgumentMatcher() { private String message; public boolean matches(Object argument) { if (!(argument instanceof HttpServletRequest)) { message = "instanceof HttpServletRequest"; return false; }/*w w w .j a v a 2s. c o m*/ final HttpServletRequest w = (HttpServletRequest) argument; final Principal userPrincipal = w.getUserPrincipal(); final String actualName = userPrincipal != null ? userPrincipal.getName() : null; if (!StringUtils.equals(actualName, principalName)) { message = "userPrincipal " + principalName; return false; } return true; } public void appendTo(StringBuffer buffer) { buffer.append(message); } }); return null; }