protected String getRememberedUserName(Serializable principal) { PortofinoRealm realm = ShiroUtils.getPortofinoRealm(); return realm.getUserPrettyName(principal); }
public Serializable getUserId() { return ShiroUtils.getUserId(getSubject()); }
public static Serializable getUserId(Subject subject) { PortofinoRealm portofinoRealm = getPortofinoRealm(); Serializable principal = (Serializable) getPrimaryPrincipal(subject); if(portofinoRealm != null) { return portofinoRealm.getUserId(principal); } else { return principal; } }
@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(); }
/** * Returns the primary principal for a Subject - that is, in Portofino, the username. * @param s the subject * @return the username. */ public static Object getPrimaryPrincipal(Subject s) { return getPrincipal(s, 0); }
/** * Wrapper for ShiroUtils.getPrimaryPrincipal(Subject) */ public Object getPrimaryPrincipal() { return ShiroUtils.getPrimaryPrincipal(getSubject()); }
/** * Returns the primary principal for a Subject - that is, in Portofino, the result of authenticating with * Security.groovy, which typically is a map of user properties as loaded from the database or other authentication * sources. * @param s the subject * @return the principal. */ public static Object getPrimaryPrincipal(Subject s) { return getPrincipal(s, 0); }
/** * Wrapper for ShiroUtils.getPrimaryPrincipal(Subject) */ public Object getPrimaryPrincipal() { return ShiroUtils.getPrimaryPrincipal(getSubject()); }
public Serializable getUserId() { return ShiroUtils.getUserId(getSubject()); }
protected void setupGroups() { PortofinoRealm portofinoRealm = ShiroUtils.getPortofinoRealm(); groups = portofinoRealm.getGroups(); }
public static Serializable getUserId(Subject subject) { PortofinoRealm portofinoRealm = getPortofinoRealm(); Serializable principal = (Serializable) getPrimaryPrincipal(subject); if(portofinoRealm != null) { return portofinoRealm.getUserId(principal); } else { return principal; } }
/** * Wrapper for ShiroUtils.getPrincipal(Subject, int) */ public Object getPrincipal(int index) { return ShiroUtils.getPrincipal(getSubject(), index); }
public Resolution authenticate() { Subject subject = SecurityUtils.getSubject(); context.getResponse().setStatus(401); context.getResponse().setHeader( AuthenticationRequiredResolution.LOGIN_PAGE_HEADER, context.getRequest().getRequestURL().toString()); if(subject.isRemembered()) { Serializable principal = (Serializable) ShiroUtils.getPrimaryPrincipal(subject); userName = getRememberedUserName(principal); rememberMe = true; return new ForwardResolution(getAuthenticationPage()); } else { return new ForwardResolution(getLoginPage()); } }
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 String getRememberedUserName(Serializable principal) { PortofinoRealm realm = ShiroUtils.getPortofinoRealm(); return realm.getUserPrettyName(principal); }
/** * Wrapper for ShiroUtils.getPrincipal(Subject, int) */ public Object getPrincipal(int index) { return ShiroUtils.getPrincipal(getSubject(), index); }
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()); } }
@GET @Produces(MediaType.APPLICATION_JSON) @RequiresAuthentication public String checkJWT() { Subject subject = SecurityUtils.getSubject(); PortofinoRealm portofinoRealm = ShiroUtils.getPortofinoRealm(); String jwt = JWTFilter.getJSONWebToken(context.getRequest()); if(jwt == null) { subject.logout(); throw new WebApplicationException(Response.Status.FORBIDDEN); } return userInfo(subject, portofinoRealm, jwt); }
/** * 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); }
public Resolution signUp() { Subject subject = SecurityUtils.getSubject(); if (subject.getPrincipal() != null) { logger.debug("Already logged in"); return redirectToReturnUrl(); } setupSignUpForm(ShiroUtils.getPortofinoRealm()); return getSignUpView(); }