use of org.pac4j.gae.profile.GaeUserServiceProfile in project pac4j by pac4j.
the class GaeUserServiceClient method clientInit.
@Override
protected void clientInit() {
service = UserServiceFactory.getUserService();
CommonHelper.assertNotNull("service", this.service);
defaultRedirectActionBuilder(ctx -> {
final String destinationUrl = computeFinalCallbackUrl(ctx);
final String loginUrl = authDomain == null ? service.createLoginURL(destinationUrl) : service.createLoginURL(destinationUrl, authDomain);
return RedirectAction.redirect(loginUrl);
});
defaultCredentialsExtractor(ctx -> {
final GaeUserCredentials credentials = new GaeUserCredentials();
credentials.setUser(service.getCurrentUser());
return credentials;
});
defaultAuthenticator((credentials, ctx) -> {
final User user = credentials.getUser();
if (user != null) {
final GaeUserServiceProfile profile = PROFILE_DEFINITION.newProfile();
profile.setId(user.getEmail());
PROFILE_DEFINITION.convertAndAdd(profile, PROFILE_ATTRIBUTE, CommonProfileDefinition.EMAIL, user.getEmail());
PROFILE_DEFINITION.convertAndAdd(profile, PROFILE_ATTRIBUTE, CommonProfileDefinition.DISPLAY_NAME, user.getNickname());
if (service.isUserAdmin()) {
profile.addRole(GaeUserServiceProfile.PAC4J_GAE_GLOBAL_ADMIN_ROLE);
}
credentials.setUserProfile(profile);
}
});
}
use of org.pac4j.gae.profile.GaeUserServiceProfile in project pac4j by pac4j.
the class GaeUserServiceClientTests method testGetCredentialsUserProfile.
@Test
public void testGetCredentialsUserProfile() {
final GaeUserCredentials credentials = client.getCredentials(context);
final User user = credentials.getUser();
assertEquals(EMAIL, user.getEmail());
assertEquals("", user.getAuthDomain());
final GaeUserServiceProfile profile = client.getUserProfile(credentials, context);
logger.debug("userProfile: {}", profile);
assertEquals(EMAIL, profile.getId());
assertEquals(GaeUserServiceProfile.class.getName() + CommonProfile.SEPARATOR + EMAIL, profile.getTypedId());
assertTrue(ProfileHelper.isTypedIdOf(profile.getTypedId(), GaeUserServiceProfile.class));
assertEquals("test", profile.getDisplayName());
assertTrue(profile.getRoles().contains("GLOBAL_ADMIN"));
assertEquals(2, profile.getAttributes().size());
}
Aggregations