/** * Update the principal, to be called on any modification of the profiles map internally. */ private void updatePrincipal() { principal = new JsonObject(); profiles.forEach((name, profile) -> { final JsonObject jsonProfile = new JsonObject(); profile.getAttributes() .forEach((attributeName, attributeValue) -> jsonProfile.put(attributeName, attributeValue.toString())); principal.put(name, jsonProfile); }); }
/** * Update the principal, to be called on any modification of the profiles map internally. */ private void updatePrincipal() { principal = new JsonObject(); profiles.forEach((name, profile) -> { final JsonObject jsonProfile = new JsonObject(); profile.getAttributes() .forEach((attributeName, attributeValue) -> jsonProfile.put(attributeName, attributeValue.toString())); principal.put(name, jsonProfile); }); }
/** * Validates the token and returns the corresponding user profile. * * @param token the JWT * @return the corresponding user profile */ public Map<String, Object> validateTokenAndGetClaims(final String token) { final CommonProfile profile = validateToken(token); final Map<String, Object> claims = new HashMap<>(profile.getAttributes()); claims.put(JwtClaims.SUBJECT, profile.getId()); return claims; }
protected JWTClaimsSet buildJwtClaimsSet(final U profile) { // claims builder with subject and issue time final JWTClaimsSet.Builder builder = new JWTClaimsSet.Builder() .subject(profile.getTypedId()) .issueTime(new Date()); if (this.expirationTime != null) { builder.expirationTime(this.expirationTime); } // add attributes final Map<String, Object> attributes = profile.getAttributes(); for (final Map.Entry<String, Object> entry : attributes.entrySet()) { builder.claim(entry.getKey(), entry.getValue()); } builder.claim(INTERNAL_ROLES, profile.getRoles()); builder.claim(INTERNAL_PERMISSIONS, profile.getPermissions()); // claims return builder.build(); }
ticket.getClaims().putAll(profileResult.getAttributes()); this.ticketRegistry.updateTicket(ticket);
@Test public void testGetUserProfile() { final DirectFormClient formClient = getFormClient(); formClient.setProfileCreator((credentials, context) -> { String username = credentials.getUsername(); final CommonProfile profile = new CommonProfile(); profile.setId(username); profile.addAttribute(Pac4jConstants.USERNAME, username); return profile; }); final MockWebContext context = MockWebContext.create(); final CommonProfile profile = formClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, USERNAME), context); assertEquals(USERNAME, profile.getId()); assertEquals(CommonProfile.class.getName() + CommonProfile.SEPARATOR + USERNAME, profile.getTypedId()); assertTrue(ProfileHelper.isTypedIdOf(profile.getTypedId(), CommonProfile.class)); assertEquals(USERNAME, profile.getUsername()); assertEquals(1, profile.getAttributes().size()); } }
@Test public void testGetUserProfile() { final FormClient formClient = getFormClient(); formClient.setProfileCreator((credentials, context) -> { String username = credentials.getUsername(); final CommonProfile profile = new CommonProfile(); profile.setId(username); profile.addAttribute(Pac4jConstants.USERNAME, username); return profile; }); final MockWebContext context = MockWebContext.create(); final CommonProfile profile = formClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, USERNAME), context); assertEquals(USERNAME, profile.getId()); assertEquals(CommonProfile.class.getName() + CommonProfile.SEPARATOR + USERNAME, profile.getTypedId()); assertTrue(ProfileHelper.isTypedIdOf(profile.getTypedId(), CommonProfile.class)); assertEquals(USERNAME, profile.getUsername()); assertEquals(1, profile.getAttributes().size()); } }