/** * Return the set of User/Principal roles from the token. * @param principal the Principal associated with the token * @param subject the JAAS Subject associated with a successful validation of the token * @param token The JWTToken * @return the set of User/Principal roles from the token. */ public Set<Principal> parseRolesFromToken( Principal principal, Subject subject, JwtToken token ) { if (subject != null && useJaasSubject) { return super.parseRolesFromSubject(principal, subject); } Set<Principal> roles = null; if (roleClaim != null && token != null && token.getClaims().containsProperty(roleClaim)) { roles = new HashSet<>(); String role = token.getClaims().getStringProperty(roleClaim).trim(); for (String r : role.split(",")) { roles.add(new SimpleGroup(r)); } } else { roles = Collections.emptySet(); } return roles; }
/** * Return the set of User/Principal roles from the token. * @param principal the Principal associated with the token * @param subject the JAAS Subject associated with a successful validation of the token * @param token The JWTToken * @return the set of User/Principal roles from the token. */ public Set<Principal> parseRolesFromToken( Principal principal, Subject subject, JwtToken token ) { if (subject != null && useJaasSubject) { return super.parseRolesFromSubject(principal, subject); } Set<Principal> roles = null; if (roleClaim != null && token != null && token.getClaims().containsProperty(roleClaim)) { roles = new HashSet<>(); String role = token.getClaims().getStringProperty(roleClaim).trim(); for (String r : role.split(",")) { roles.add(new SimpleGroup(r)); } } else { roles = Collections.emptySet(); } return roles; }
public JwtTokenSecurityContext(JwtToken jwt, String roleClaim) { principal = new SimplePrincipal(jwt.getClaims().getSubject()); this.token = jwt; if (roleClaim != null && jwt.getClaims().containsProperty(roleClaim)) { roles = new HashSet<>(); String role = jwt.getClaims().getStringProperty(roleClaim).trim(); for (String r : role.split(",")) { roles.add(new SimpleGroup(r)); } } else { roles = Collections.emptySet(); } // Parse JwtToken into ClaimCollection jwt.getClaims().asMap().forEach((String name, Object values) -> { Claim claim = new Claim(); claim.setClaimType(name); if (values instanceof List<?>) { claim.setValues(CastUtils.cast((List<?>)values)); } else { claim.setValues(Collections.singletonList(values)); } claims.add(claim); }); }