Search in sources :

Example 11 with IdProvider

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

the class SecurityServiceImplTest method testCreateIdProvider.

@Test
public void testCreateIdProvider() throws Exception {
    runAsAdmin(() -> {
        final PrincipalKey userKey = PrincipalKey.ofUser(SYSTEM, "User1");
        final PrincipalKey groupKey1 = PrincipalKey.ofGroup(SYSTEM, "group-a");
        final PrincipalKey groupKey2 = PrincipalKey.ofGroup(SYSTEM, "group-b");
        final IdProviderAccessControlList permissions = IdProviderAccessControlList.of(IdProviderAccessControlEntry.create().principal(userKey).access(CREATE_USERS).build(), IdProviderAccessControlEntry.create().principal(groupKey1).access(ADMINISTRATOR).build(), IdProviderAccessControlEntry.create().principal(groupKey2).access(WRITE_USERS).build());
        final CreateIdProviderParams createIdProvider = CreateIdProviderParams.create().key(IdProviderKey.from("enonic")).displayName("Enonic Id Provider").permissions(permissions).description("id provider description").build();
        final IdProvider idProviderCreated = securityService.createIdProvider(createIdProvider);
        assertNotNull(idProviderCreated);
        assertEquals("enonic", idProviderCreated.getKey().toString());
        assertEquals("Enonic Id Provider", idProviderCreated.getDisplayName());
        assertEquals("id provider description", idProviderCreated.getDescription());
        final IdProviderAccessControlList createdPermissions = securityService.getIdProviderPermissions(IdProviderKey.from("enonic"));
        assertNotNull(idProviderCreated);
        assertEquals(CREATE_USERS, createdPermissions.getEntry(userKey).getAccess());
        assertEquals(ADMINISTRATOR, createdPermissions.getEntry(groupKey1).getAccess());
        assertEquals(WRITE_USERS, createdPermissions.getEntry(groupKey2).getAccess());
    });
}
Also used : IdProviderAccessControlList(com.enonic.xp.security.acl.IdProviderAccessControlList) IdProvider(com.enonic.xp.security.IdProvider) PrincipalKey(com.enonic.xp.security.PrincipalKey) CreateIdProviderParams(com.enonic.xp.security.CreateIdProviderParams) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 12 with IdProvider

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

the class GetIdProviderConfigHandlerTest method testExample.

@Test
public void testExample() {
    final IdProvider idProvider = TestDataFixtures.getTestIdProvider();
    this.portalRequest.setIdProvider(idProvider);
    runScript("/lib/xp/examples/auth/getIdProviderConfig.js");
}
Also used : IdProvider(com.enonic.xp.security.IdProvider) Test(org.junit.jupiter.api.Test)

Example 13 with IdProvider

use of com.enonic.xp.security.IdProvider 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)

Example 14 with IdProvider

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

the class IdProviderControllerServiceImplTest method setup.

@BeforeEach
public void setup() throws Exception {
    // Mocks the IdProviderDescriptorService
    final IdProviderDescriptorService idProviderDescriptorService = Mockito.mock(IdProviderDescriptorService.class);
    Mockito.when(idProviderDescriptorService.getDescriptor(ApplicationKey.from("myapplication"))).thenReturn(IdProviderDescriptor.create().key(ApplicationKey.from("myapplication")).build());
    // Mocks the SecurityService
    final SecurityService securityService = Mockito.mock(SecurityService.class);
    final IdProvider emptyIdProvider = IdProvider.create().build();
    final IdProviderConfig idProviderConfig = IdProviderConfig.create().applicationKey(ApplicationKey.from("myapplication")).build();
    final IdProvider idProvider = IdProvider.create().idProviderConfig(idProviderConfig).build();
    Mockito.when(securityService.getIdProvider(IdProviderKey.from("myemptyidprovider"))).thenReturn(emptyIdProvider);
    Mockito.when(securityService.getIdProvider(IdProviderKey.from("myidprovider"))).thenReturn(idProvider);
    Mockito.when(securityService.getIdProvider(IdProviderKey.from("myemptyuserstore"))).thenReturn(emptyIdProvider);
    Mockito.when(securityService.getIdProvider(IdProviderKey.from("myuserstore"))).thenReturn(idProvider);
    // Mocks the PortalScriptService
    final PortalScriptService portalScriptService = setupPortalScriptService();
    // Creates IdProviderControllerScriptFactoryImpl
    final IdProviderControllerScriptFactoryImpl idProviderControllerScriptFactory = new IdProviderControllerScriptFactoryImpl();
    idProviderControllerScriptFactory.setScriptService(portalScriptService);
    // Creates IdProviderControllerServiceImpl
    idProviderControllerService = new IdProviderControllerServiceImpl();
    idProviderControllerService.setIdProviderControllerScriptFactory(idProviderControllerScriptFactory);
    idProviderControllerService.setIdProviderDescriptorService(idProviderDescriptorService);
    idProviderControllerService.setSecurityService(securityService);
}
Also used : IdProviderDescriptorService(com.enonic.xp.idprovider.IdProviderDescriptorService) PortalScriptService(com.enonic.xp.portal.script.PortalScriptService) SecurityService(com.enonic.xp.security.SecurityService) IdProvider(com.enonic.xp.security.IdProvider) IdProviderConfig(com.enonic.xp.security.IdProviderConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

IdProvider (com.enonic.xp.security.IdProvider)14 Test (org.junit.jupiter.api.Test)6 IdProviderKey (com.enonic.xp.security.IdProviderKey)4 IdProviderAccessControlList (com.enonic.xp.security.acl.IdProviderAccessControlList)4 AbstractElasticsearchIntegrationTest (com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest)3 CreateIdProviderParams (com.enonic.xp.security.CreateIdProviderParams)3 IdProviders (com.enonic.xp.security.IdProviders)3 PrincipalKey (com.enonic.xp.security.PrincipalKey)3 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)3 IdProviderDescriptor (com.enonic.xp.idprovider.IdProviderDescriptor)2 IdProviderConfig (com.enonic.xp.security.IdProviderConfig)2 SecurityService (com.enonic.xp.security.SecurityService)2 UpdateIdProviderParams (com.enonic.xp.security.UpdateIdProviderParams)2 EmailPasswordAuthToken (com.enonic.xp.security.auth.EmailPasswordAuthToken)2 VerifiedEmailAuthToken (com.enonic.xp.security.auth.VerifiedEmailAuthToken)2 VerifiedUsernameAuthToken (com.enonic.xp.security.auth.VerifiedUsernameAuthToken)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Context (com.enonic.xp.context.Context)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 PropertySet (com.enonic.xp.data.PropertySet)1