Search in sources :

Example 11 with IdProviderKey

use of com.enonic.xp.security.IdProviderKey in project xp by enonic.

the class AuthenticationInfoTest method testSerializationWithUserProfile.

@Test
void testSerializationWithUserProfile() throws Exception {
    final PropertySet data = new PropertySet();
    data.setString("subString", "subStringValue");
    data.setLong("subLong", 123L);
    final PropertyTree userProfile = new PropertyTree();
    userProfile.setSet("myApp", data);
    userProfile.setString("string", "stringValue");
    final User user = User.create().login("userlogin").displayName("my user").key(PrincipalKey.ofUser(IdProviderKey.from("myidprovider"), "userid")).email("user@email").modifiedTime(Instant.now(clock)).profile(userProfile).build();
    final IdProviderKey idProvider = IdProviderKey.from("myStore");
    final PrincipalKey group1 = PrincipalKey.ofGroup(idProvider, "group1");
    final PrincipalKey group2 = PrincipalKey.from("group:myStore:group2");
    final PrincipalKey role1 = PrincipalKey.from("role:administrators");
    final AuthenticationInfo info = AuthenticationInfo.create().user(user).principals(group1).principals(PrincipalKeys.from(group2, role1)).build();
    final byte[] serializedObject = serialize(info);
    final AuthenticationInfo deserializedObject = (AuthenticationInfo) deserialize(serializedObject);
    assertEquals(deserializedObject, info);
}
Also used : User(com.enonic.xp.security.User) PropertyTree(com.enonic.xp.data.PropertyTree) IdProviderKey(com.enonic.xp.security.IdProviderKey) PropertySet(com.enonic.xp.data.PropertySet) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 12 with IdProviderKey

use of com.enonic.xp.security.IdProviderKey in project xp by enonic.

the class VirtualHostConfigMap method getHostIdProvidersMapping.

private VirtualHostIdProvidersMapping getHostIdProvidersMapping(final String mappingPrefix) {
    final String idProviderPrefix = mappingPrefix + "idProvider" + ".";
    final VirtualHostIdProvidersMapping.Builder hostIdProvidersMapping = VirtualHostIdProvidersMapping.create();
    getIdProviders(idProviderPrefix).forEach((idProviderName, idProviderStatus) -> {
        final IdProviderKey idProviderKey = IdProviderKey.from(idProviderName);
        if (DEFAULT_ID_PROVIDER_VALUE.equals(idProviderStatus)) {
            hostIdProvidersMapping.setDefaultIdProvider(idProviderKey);
        }
        if (ENABLED_ID_PROVIDER_VALUE.equals(idProviderStatus)) {
            hostIdProvidersMapping.addIdProviderKey(idProviderKey);
        }
    });
    return hostIdProvidersMapping.build();
}
Also used : IdProviderKey(com.enonic.xp.security.IdProviderKey) VirtualHostIdProvidersMapping(com.enonic.xp.web.vhost.impl.mapping.VirtualHostIdProvidersMapping)

Example 13 with IdProviderKey

use of com.enonic.xp.security.IdProviderKey in project app-auth0-idprovider by enonic.

the class Auth0CallbackService method handle.

public boolean handle(final HttpServletRequest request) {
    try {
        final IdProviderKey idProviderKey = getIdProviderKey(request);
        final AuthenticationController authController = createAuthController(idProviderKey);
        final Tokens tokens = authController.handle(request);
        final UserInfo userInfo = retrieveUserInfo(idProviderKey, tokens);
        loginService.login(request, new UserInfoAdapter(userInfo), idProviderKey);
        return true;
    } catch (Exception e) {
        LOG.error("Error while handling auth0 callback", e);
    }
    return false;
}
Also used : AuthenticationController(com.auth0.AuthenticationController) IdProviderKey(com.enonic.xp.security.IdProviderKey) UserInfo(com.auth0.json.auth.UserInfo) UserInfoAdapter(com.enonic.app.auth0.impl.user.UserInfoAdapter) Auth0Exception(com.auth0.exception.Auth0Exception) Tokens(com.auth0.Tokens)

Aggregations

IdProviderKey (com.enonic.xp.security.IdProviderKey)13 Test (org.junit.jupiter.api.Test)5 PrincipalKey (com.enonic.xp.security.PrincipalKey)4 User (com.enonic.xp.security.User)4 IdProvider (com.enonic.xp.security.IdProvider)3 VirtualHost (com.enonic.xp.web.vhost.VirtualHost)3 PropertySet (com.enonic.xp.data.PropertySet)2 PortalRequest (com.enonic.xp.portal.PortalRequest)2 PortalResponse (com.enonic.xp.portal.PortalResponse)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 AuthenticationController (com.auth0.AuthenticationController)1 Tokens (com.auth0.Tokens)1 Auth0Exception (com.auth0.exception.Auth0Exception)1 UserInfo (com.auth0.json.auth.UserInfo)1 UserInfoAdapter (com.enonic.app.auth0.impl.user.UserInfoAdapter)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 IdProviderDescriptor (com.enonic.xp.idprovider.IdProviderDescriptor)1 NodeQuery (com.enonic.xp.node.NodeQuery)1 ContentResolver (com.enonic.xp.portal.impl.ContentResolver)1