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());
}
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;
}
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");
}
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;
}
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));
}
Aggregations