Search in sources :

Example 6 with IdProviderKey

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

the class AuthenticationInfoTest method testCopy.

@Test
public void testCopy() {
    final User user = User.create().login("userlogin").displayName("my user").key(PrincipalKey.ofUser(IdProviderKey.from("myidprovider"), "userid")).email("user@email").modifiedTime(Instant.now(clock)).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 AuthenticationInfo copy = AuthenticationInfo.copyOf(info).build();
    assertEquals(info, copy);
    assertEquals(info.hashCode(), copy.hashCode());
}
Also used : User(com.enonic.xp.security.User) IdProviderKey(com.enonic.xp.security.IdProviderKey) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 7 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 8 with IdProviderKey

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

the class IdProviderNodeTranslator method createIdProviderFromNode.

private static IdProvider createIdProviderFromNode(final Node node) {
    if (node.name().toString().equalsIgnoreCase(PrincipalKey.ROLES_NODE_NAME)) {
        return null;
    }
    final PropertySet nodeAsSet = node.data().getRoot();
    final IdProviderKey idProviderKey = IdProviderNodeTranslator.toKey(node);
    final IdProvider.Builder idProvider = IdProvider.create().displayName(nodeAsSet.getString(IdProviderPropertyNames.DISPLAY_NAME_KEY)).key(idProviderKey).description(nodeAsSet.getString(IdProviderPropertyNames.DESCRIPTION_KEY));
    if (nodeAsSet.hasProperty(IdProviderPropertyNames.APPLICATION)) {
        final String applicationKey = nodeAsSet.getString(IdProviderPropertyNames.ID_PROVIDER_APPLICATION_KEY);
        final PropertySet config = nodeAsSet.getSet(IdProviderPropertyNames.ID_PROVIDER_CONFIG_FORM_KEY);
        final IdProviderConfig idProviderConfig = IdProviderConfig.create().applicationKey(ApplicationKey.from(applicationKey)).config(config.toTree()).build();
        idProvider.idProviderConfig(idProviderConfig);
    } else if (IdProviderKey.system().equals(idProviderKey)) {
        // TODO Remove after next dump upgrade
        final IdProviderConfig idProviderConfig = IdProviderConfig.create().applicationKey(SYSTEM_ID_PROVIDER_KEY).build();
        idProvider.idProviderConfig(idProviderConfig);
    }
    return idProvider.build();
}
Also used : IdProvider(com.enonic.xp.security.IdProvider) IdProviderKey(com.enonic.xp.security.IdProviderKey) PropertySet(com.enonic.xp.data.PropertySet) IdProviderConfig(com.enonic.xp.security.IdProviderConfig)

Example 9 with IdProviderKey

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

the class VirtualHostHandlerTest method setUp.

@BeforeEach
public void setUp() {
    Mockito.when(virtualHostService.isEnabled()).thenReturn(true);
    virtualHost = Mockito.mock(VirtualHost.class);
    Mockito.when(virtualHost.getName()).thenReturn("a");
    Mockito.when(virtualHost.getSource()).thenReturn("/a");
    Mockito.when(virtualHost.getTarget()).thenReturn("/other/a");
    Mockito.when(virtualHost.getHost()).thenReturn("localhost");
    final IdProviderKey defaultIdProviderKey = IdProviderKey.from("default");
    Mockito.when(virtualHost.getDefaultIdProviderKey()).thenReturn(defaultIdProviderKey);
    Mockito.when(virtualHost.getIdProviderKeys()).thenReturn(IdProviderKeys.from(defaultIdProviderKey));
}
Also used : IdProviderKey(com.enonic.xp.security.IdProviderKey) VirtualHost(com.enonic.xp.web.vhost.VirtualHost) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with IdProviderKey

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

the class BasicAuthFilterTest method setup.

@BeforeEach
public void setup() {
    this.request = Mockito.mock(HttpServletRequest.class);
    this.response = Mockito.mock(HttpServletResponse.class);
    this.chain = Mockito.mock(FilterChain.class);
    this.securityService = Mockito.mock(SecurityService.class);
    this.filter = new BasicAuthFilter();
    this.filter.setSecurityService(this.securityService);
    final IdProviderKey idProviderKey = IdProviderKey.from("store");
    final IdProvider idProvider = IdProvider.create().key(idProviderKey).build();
    final IdProviders idProviders = IdProviders.from(idProvider);
    when(this.securityService.getIdProviders()).thenReturn(idProviders);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IdProviders(com.enonic.xp.security.IdProviders) SecurityService(com.enonic.xp.security.SecurityService) FilterChain(javax.servlet.FilterChain) IdProvider(com.enonic.xp.security.IdProvider) IdProviderKey(com.enonic.xp.security.IdProviderKey) HttpServletResponse(javax.servlet.http.HttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

IdProviderKey (com.enonic.xp.security.IdProviderKey)12 PrincipalKey (com.enonic.xp.security.PrincipalKey)4 User (com.enonic.xp.security.User)4 Test (org.junit.jupiter.api.Test)4 IdProvider (com.enonic.xp.security.IdProvider)3 PropertySet (com.enonic.xp.data.PropertySet)2 PortalRequest (com.enonic.xp.portal.PortalRequest)2 PortalResponse (com.enonic.xp.portal.PortalResponse)2 VirtualHost (com.enonic.xp.web.vhost.VirtualHost)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