public Serializable getUserId() { return ShiroUtils.getUserId(getSubject()); }
public Serializable getUserId() { return ShiroUtils.getUserId(getSubject()); }
protected void fillMDC() { logger.debug("Retrieving user"); Serializable userId = null; Subject subject = SecurityUtils.getSubject(); Object principal = subject.getPrincipal(); if (principal == null) { logger.debug("No user found"); } else { userId = ShiroUtils.getUserId(subject); logger.debug("Retrieved userId={}", userId); } logger.debug("Setting up logging MDC"); MDC.clear(); if(userId != null) { //Issue #755 MDC.put("userId", userId.toString()); } HttpServletRequest request = ElementsThreadLocals.getHttpServletRequest(); if(request != null) { MDC.put("req.requestURI", request.getRequestURI()); } }
protected void fillMDC() { logger.debug("Retrieving user"); Serializable userId = null; Subject subject = SecurityUtils.getSubject(); Object principal = subject.getPrincipal(); if (principal == null) { logger.debug("No user found"); } else { userId = ShiroUtils.getUserId(subject); logger.debug("Retrieved userId={}", userId); } logger.debug("Setting up logging MDC"); MDC.clear(); if(userId != null) { //Issue #755 MDC.put("userId", userId.toString()); } HttpServletRequest request = ElementsThreadLocals.getHttpServletRequest(); if(request != null) { MDC.put("req.requestURI", request.getRequestURI()); } }
try { subject.login(new ServletContainerToken(req)); Serializable userId = ShiroUtils.getUserId(SecurityUtils.getSubject()); logger.info("User {} login", userId); } catch (AuthenticationException e) { Serializable userId = ShiroUtils.getUserId(SecurityUtils.getSubject()); subject.logout(); logger.info("User {} logout", userId);
/** * Executes an action if the current logged in user's credential is known, * otherwise redirects to the authorization page. * @param action * @return */ public Resolution doWithCredential(Callable<Resolution> action) { Subject subject = SecurityUtils.getSubject(); Object principal = subject.getPrincipal(); String userId; if(principal == null) { throw new IllegalStateException("User is not logged in, can not determine the user id"); } else { userId = OgnlUtils.convertValueToString(ShiroUtils.getUserId(subject)); } return doWithCredential(userId, action); }
try { subject.login(new ServletContainerToken(req)); Serializable userId = ShiroUtils.getUserId(SecurityUtils.getSubject()); logger.info("User {} login", userId); } catch (AuthenticationException e) { Serializable userId = ShiroUtils.getUserId(SecurityUtils.getSubject()); subject.logout(); logger.info("User {} logout", userId);
/** * Handles the callback from the OAuth provider, returning a valid Credential if successful. Automatically uses * the current request and the logged in user. * @return * @throws IOException */ public Credential authorize() throws IOException { HttpServletRequest request = ElementsThreadLocals.getHttpServletRequest(); Subject subject = SecurityUtils.getSubject(); Object principal = subject.getPrincipal(); String userId; if(principal == null) { throw new IllegalStateException("User is not logged in, can not determine the user id"); } else { userId = OgnlUtils.convertValueToString(ShiroUtils.getUserId(subject)); } return authorize(request, userId); }
logger.debug("No user found"); } else { userId = ShiroUtils.getUserId(subject); logger.debug("Retrieved userId={}", userId);
@POST @Produces("application/json") public String login(@FormParam("username") String username, @FormParam("password") String password) throws AuthenticationException{ Subject subject = SecurityUtils.getSubject(); if(!subject.isAuthenticated()) try { UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password); usernamePasswordToken.setRememberMe(false); subject.login(usernamePasswordToken); logger.info("User {} login", ShiroUtils.getUserId(subject)); Session session = subject.getSession(true); JSONStringer stringer = new JSONStringer(); stringer.object().key("portofinoSessionId").value(session.getId()).endObject(); return stringer.toString(); } catch (AuthenticationException e) { logger.warn("Login failed for '" + username + "': " + e.getMessage(), e); } return "{}"; }
@POST @Produces("application/json") public String login(@FormParam("username") String username, @FormParam("password") String password) throws AuthenticationException{ Subject subject = SecurityUtils.getSubject(); if(!subject.isAuthenticated()) try { UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password); usernamePasswordToken.setRememberMe(false); subject.login(usernamePasswordToken); logger.info("User {} login", ShiroUtils.getUserId(subject)); Session session = subject.getSession(true); JSONStringer stringer = new JSONStringer(); stringer.object().key("portofinoSessionId").value(session.getId()).endObject(); return stringer.toString(); } catch (AuthenticationException e) { logger.warn("Login failed for '" + username + "': " + e.getMessage(), e); } return "{}"; }
@Override @POST @Produces("application/json") public String login(@FormParam("username") String username, @FormParam("password") String password) throws AuthenticationException { Subject subject = SecurityUtils.getSubject(); if(!subject.isAuthenticated()) try { UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password); usernamePasswordToken.setRememberMe(false); subject.login(usernamePasswordToken); logger.info("User {} login", ShiroUtils.getUserId(subject)); Object principal = subject.getPrincipal(); subject.logout(); PortofinoRealm portofinoRealm = ShiroUtils.getPortofinoRealm(); String jwt = portofinoRealm.generateWebToken(principal); subject.login(new JSONWebToken(jwt)); return userInfo(subject, portofinoRealm, jwt); } catch (AuthenticationException e) { logger.warn("Login failed for '" + username + "': " + e.getMessage(), e); throw new WebApplicationException(Response.Status.UNAUTHORIZED); } return checkJWT(); }
usernamePasswordToken.setRememberMe(rememberMe); subject.login(usernamePasswordToken); logger.info("User {} login", ShiroUtils.getUserId(subject)); String successMsg = ElementsThreadLocals.getText("user._.logged.in.successfully", userName); SessionMessages.addInfoMessage(successMsg);
public String userInfo(Subject subject, PortofinoRealm portofinoRealm, String jwt) { boolean administrator = SecurityLogic.isAdministrator(portofinoConfiguration); Session session = subject.getSession(true); JSONStringer stringer = new JSONStringer(); stringer. object(). key("portofinoSessionId").value(session.getId()). key("userId").value(ShiroUtils.getUserId(subject)). key("displayName").value(portofinoRealm.getUserPrettyName((Serializable) subject.getPrincipal())). key("administrator").value(administrator). key("groups").value(portofinoRealm.getGroups(subject.getPrincipal())). key("jwt").value(jwt). endObject(); return stringer.toString(); }