Search in sources :

Example 1 with IdProvider

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

the class LoginHandlerTest method testLoginMultipleIdProvidersInOrder.

@Test
public void testLoginMultipleIdProvidersInOrder() {
    final IdProvider idProvider1 = IdProvider.create().displayName("Id Provider 1").key(IdProviderKey.from("idprovider1")).build();
    final IdProvider idProvider3 = IdProvider.create().displayName("Id Provider 3").key(IdProviderKey.from("idprovider3")).build();
    final IdProvider idProvider2 = IdProvider.create().displayName("Id Provider 2").key(IdProviderKey.from("idprovider2")).build();
    final IdProviders idProviders = IdProviders.from(idProvider1, idProvider3, idProvider2);
    final AuthenticationInfo authInfo = TestDataFixtures.createAuthenticationInfo();
    final EmailPasswordAuthToken expectedAuthToken = new EmailPasswordAuthToken();
    expectedAuthToken.setEmail("user1@enonic.com");
    expectedAuthToken.setPassword("pwd123");
    expectedAuthToken.setIdProvider(idProvider3.getKey());
    final AuthTokenMatcher matcher = new AuthTokenMatcher(expectedAuthToken);
    Mockito.when(this.securityService.authenticate(Mockito.argThat(matcher))).thenReturn(authInfo);
    Mockito.when(this.securityService.getIdProviders()).thenReturn(idProviders);
    runFunction("/test/login-test.js", "loginMultipleIdProvidersInOrder");
    final Session session = ContextAccessor.current().getLocalScope().getSession();
    final AuthenticationInfo sessionAuthInfo = session.getAttribute(AuthenticationInfo.class);
    assertEquals(authInfo, sessionAuthInfo);
    assertEquals(3, matcher.loginIdProviderAttempts.size());
    assertEquals("idprovider1", matcher.loginIdProviderAttempts.get(0).toString());
    assertEquals("idprovider2", matcher.loginIdProviderAttempts.get(1).toString());
    assertEquals("idprovider3", matcher.loginIdProviderAttempts.get(2).toString());
}
Also used : IdProviders(com.enonic.xp.security.IdProviders) IdProvider(com.enonic.xp.security.IdProvider) EmailPasswordAuthToken(com.enonic.xp.security.auth.EmailPasswordAuthToken) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Session(com.enonic.xp.session.Session) Test(org.junit.jupiter.api.Test)

Example 2 with IdProvider

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

the class GetCurrentIdProviderKeyHandler method retrieveIdProviderKey.

private IdProviderKey retrieveIdProviderKey(final HttpServletRequest req) {
    final IdProvider idProvider = this.request.getIdProvider();
    if (idProvider != null) {
        return idProvider.getKey();
    }
    final VirtualHost virtualHost = VirtualHostHelper.getVirtualHost(req);
    if (virtualHost != null) {
        return virtualHost.getDefaultIdProviderKey();
    }
    return null;
}
Also used : IdProvider(com.enonic.xp.security.IdProvider) VirtualHost(com.enonic.xp.web.vhost.VirtualHost)

Example 3 with IdProvider

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

the class GetCurrentIdProviderKeyHandlerTest method testExample.

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

Example 4 with IdProvider

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

the class IdProviderControllerServiceImpl method execute.

@Override
public PortalResponse execute(final IdProviderControllerExecutionParams params) throws IOException {
    final IdProviderKey idProviderKey = retrieveIdProviderKey(params);
    final IdProvider idProvider = retrieveIdProvider(idProviderKey);
    final IdProviderDescriptor idProviderDescriptor = retrieveIdProviderDescriptor(idProvider);
    if (idProviderDescriptor != null) {
        final IdProviderControllerScript idProviderControllerScript = idProviderControllerScriptFactory.fromScript(idProviderDescriptor.getResourceKey());
        final String functionName = params.getFunctionName();
        if (idProviderControllerScript.hasMethod(functionName)) {
            PortalRequest portalRequest = params.getPortalRequest();
            if (portalRequest == null) {
                portalRequest = new PortalRequestAdapter().adapt(params.getServletRequest());
            }
            portalRequest.setApplicationKey(idProviderDescriptor.getKey());
            portalRequest.setIdProvider(idProvider);
            final PortalResponse portalResponse = idProviderControllerScript.execute(functionName, portalRequest);
            if (portalResponse != null) {
                final HttpServletResponse response = params.getResponse();
                if (response != null) {
                    responseSerializationService.serialize(portalRequest, portalResponse, response);
                }
            }
            return portalResponse;
        }
    }
    return null;
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) PortalRequestAdapter(com.enonic.xp.portal.impl.PortalRequestAdapter) IdProvider(com.enonic.xp.security.IdProvider) IdProviderDescriptor(com.enonic.xp.idprovider.IdProviderDescriptor) IdProviderKey(com.enonic.xp.security.IdProviderKey) HttpServletResponse(javax.servlet.http.HttpServletResponse) PortalRequest(com.enonic.xp.portal.PortalRequest)

Example 5 with IdProvider

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

the class ApplicationInfoServiceImplTest method mockIdProviderApplication.

private void mockIdProviderApplication(final ApplicationKey applicationKey) {
    final IdProviderDescriptor idProviderDescriptor = IdProviderDescriptor.create().config(Form.create().build()).key(applicationKey).mode(IdProviderDescriptorMode.EXTERNAL).build();
    final IdProvider idProvider1 = IdProvider.create().displayName("idProvider1").key(IdProviderKey.from("idProvider1")).idProviderConfig(IdProviderConfig.create().applicationKey(applicationKey).config(new PropertyTree()).build()).build();
    final IdProvider idProvider2 = IdProvider.create().displayName("idProvider2").key(IdProviderKey.from("idProvider2" + "")).idProviderConfig(IdProviderConfig.create().applicationKey(applicationKey).config(new PropertyTree()).build()).build();
    Mockito.when(this.idProviderDescriptorService.getDescriptor(applicationKey)).thenReturn(idProviderDescriptor);
    Mockito.when(this.securityService.getIdProviders()).thenReturn(IdProviders.from(idProvider1, idProvider2));
}
Also used : IdProviderDescriptor(com.enonic.xp.idprovider.IdProviderDescriptor) IdProvider(com.enonic.xp.security.IdProvider) PropertyTree(com.enonic.xp.data.PropertyTree)

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