use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project carbon-identity-framework by wso2.
the class DefaultStepHandler method handleResponse.
protected void handleResponse(HttpServletRequest request, HttpServletResponse response, AuthenticationContext context) throws FrameworkException {
if (LOG.isDebugEnabled()) {
LOG.debug("Receive a response from the external party");
}
SequenceConfig sequenceConfig = context.getSequenceConfig();
int currentStep = context.getCurrentStep();
boolean isNoneCanHandle = true;
StepConfig stepConfig = sequenceConfig.getStepMap().get(currentStep);
for (AuthenticatorConfig authenticatorConfig : stepConfig.getAuthenticatorList()) {
ApplicationAuthenticator authenticator = authenticatorConfig.getApplicationAuthenticator();
// Call authenticate if canHandle
if (authenticator != null && authenticator.canHandle(request) && (context.getCurrentAuthenticator() == null || authenticator.getName().equals(context.getCurrentAuthenticator()))) {
isNoneCanHandle = false;
if (LOG.isDebugEnabled()) {
LOG.debug(authenticator.getName() + " can handle the request.");
}
doAuthentication(request, response, context, authenticatorConfig);
break;
}
}
if (isNoneCanHandle) {
throw new FrameworkException("No authenticator can handle the request in step : " + currentStep);
}
}
use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project carbon-identity-framework by wso2.
the class JITProvisioningPostAuthenticationHandlerTest method testHandleWithAuthenticatedUserWithFederatedIdp.
@Test(description = "This test case tests the Post JIT provisioning handling flow with an authenticated user")
public void testHandleWithAuthenticatedUserWithFederatedIdp() throws FrameworkException, FederatedAssociationManagerException, AccountLockServiceException, UserStoreException {
AuthenticationContext context = processAndGetAuthenticationContext(sp, true, true);
FederatedAssociationManager federatedAssociationManager = mock(FederatedAssociationManagerImpl.class);
when(FrameworkUtils.getFederatedAssociationManager()).thenReturn(federatedAssociationManager);
doReturn("test").when(federatedAssociationManager).getUserForFederatedAssociation(Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
when(FrameworkUtils.getStepBasedSequenceHandler()).thenReturn(Mockito.mock(StepBasedSequenceHandler.class));
mockStatic(FrameworkServiceDataHolder.class);
PowerMockito.when(FrameworkServiceDataHolder.getInstance()).thenReturn(frameworkServiceDataHolder);
mockStatic(AccountLockService.class);
when(frameworkServiceDataHolder.getAccountLockService()).thenReturn(accountLockService);
when(accountLockService.isAccountLocked(anyString(), anyString())).thenReturn(false);
RealmService mockRealmService = mock(RealmService.class);
PowerMockito.when(FrameworkServiceDataHolder.getInstance().getRealmService()).thenReturn(mockRealmService);
UserRealm mockUserRealm = mock(UserRealm.class);
UserStoreManager mockUserStoreManager = mock(UserStoreManager.class);
Map<String, String> mockClaimValues = mock(HashMap.class);
mockStatic(IdentityTenantUtil.class);
when(IdentityTenantUtil.getTenantId(anyString())).thenReturn(1);
when(mockRealmService.getTenantUserRealm(anyInt())).thenReturn(mockUserRealm);
when(mockUserRealm.getUserStoreManager()).thenReturn(mockUserStoreManager);
when(mockUserStoreManager.getUserClaimValues(anyString(), eq(new String[] { AccountConstants.ACCOUNT_DISABLED_CLAIM }), eq(UserCoreConstants.DEFAULT_PROFILE))).thenReturn(mockClaimValues);
when(mockClaimValues.get(AccountConstants.ACCOUNT_DISABLED_CLAIM)).thenReturn("false");
PostAuthnHandlerFlowStatus postAuthnHandlerFlowStatus = postJITProvisioningHandler.handle(request, response, context);
Assert.assertEquals(postAuthnHandlerFlowStatus, PostAuthnHandlerFlowStatus.SUCCESS_COMPLETED, "Post JIT provisioning handler executed while having a authenticated user without federated " + "authenticator");
}
use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project carbon-identity-framework by wso2.
the class JITProvisioningPostAuthenticationHandlerTest method testHandleWithAuthenticatedUserWithoutFederatedIdp.
@Test(description = "This test case tests the Post JIT provisioning handling flow with an authenticated user")
public void testHandleWithAuthenticatedUserWithoutFederatedIdp() throws FrameworkException {
AuthenticationContext context = processAndGetAuthenticationContext(sp, true, false);
PostAuthnHandlerFlowStatus postAuthnHandlerFlowStatus = postJITProvisioningHandler.handle(request, response, context);
Assert.assertEquals(postAuthnHandlerFlowStatus, PostAuthnHandlerFlowStatus.SUCCESS_COMPLETED, "Post JIT provisioning handler executed while having a authenticated user without federated " + "authenticator");
}
use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project carbon-identity-framework by wso2.
the class DefaultRequestPathBasedSequenceHandlerTest method testHandleInvalidCredentialException.
/*
Request path authenticator throws an InvalidCredentialsException
*/
@Test
public void testHandleInvalidCredentialException() throws Exception {
// mock the behaviour of the request path authenticator
when(requestPathAuthenticator.canHandle(any(HttpServletRequest.class))).thenReturn(true);
doThrow(new InvalidCredentialsException("Invalid Credentials.")).when(requestPathAuthenticator).process(request, response, context);
requestPathBasedSequenceHandler.handle(request, response, context);
assertEquals(context.isRequestAuthenticated(), false);
}
use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project carbon-identity-framework by wso2.
the class DefaultRequestPathBasedSequenceHandlerTest method testHandleLogoutFailedException.
/*
Request path authenticator throws a LogoutFailedException
*/
@Test(expectedExceptions = FrameworkException.class)
public void testHandleLogoutFailedException() throws Exception {
// mock the behaviour of the request path authenticator
when(requestPathAuthenticator.canHandle(any(HttpServletRequest.class))).thenReturn(true);
doThrow(new LogoutFailedException("Logout Failed.")).when(requestPathAuthenticator).process(request, response, context);
requestPathBasedSequenceHandler.handle(request, response, context);
}
Aggregations