Search in sources :

Example 1 with GaeUserServiceProfile

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);
        }
    });
}
Also used : GaeUserServiceProfile(org.pac4j.gae.profile.GaeUserServiceProfile) User(com.google.appengine.api.users.User) GaeUserCredentials(org.pac4j.gae.credentials.GaeUserCredentials)

Example 2 with GaeUserServiceProfile

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());
}
Also used : GaeUserServiceProfile(org.pac4j.gae.profile.GaeUserServiceProfile) User(com.google.appengine.api.users.User) GaeUserCredentials(org.pac4j.gae.credentials.GaeUserCredentials) Test(org.junit.Test)

Aggregations

User (com.google.appengine.api.users.User)2 GaeUserCredentials (org.pac4j.gae.credentials.GaeUserCredentials)2 GaeUserServiceProfile (org.pac4j.gae.profile.GaeUserServiceProfile)2 Test (org.junit.Test)1