Search in sources :

Example 1 with SMSOTPAuthenticator

use of org.wso2.carbon.identity.authenticator.smsotp.SMSOTPAuthenticator in project identity-outbound-auth-sms-otp by wso2-extensions.

the class SMSOTPAuthenticatorTest method testRetryAuthenticationEnabled.

@Test
public void testRetryAuthenticationEnabled() throws Exception {
    SMSOTPAuthenticator smsotp = PowerMockito.spy(smsotpAuthenticator);
    Assert.assertTrue((Boolean) Whitebox.invokeMethod(smsotp, "retryAuthenticationEnabled"));
}
Also used : SMSOTPAuthenticator(org.wso2.carbon.identity.authenticator.smsotp.SMSOTPAuthenticator) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with SMSOTPAuthenticator

use of org.wso2.carbon.identity.authenticator.smsotp.SMSOTPAuthenticator in project identity-outbound-auth-sms-otp by wso2-extensions.

the class SMSOTPAuthenticatorTest method testProcessWithLogoutFalse.

@Test
public void testProcessWithLogoutFalse() throws Exception {
    mockStatic(FederatedAuthenticatorUtil.class);
    mockStatic(SMSOTPUtils.class);
    mockStatic(FrameworkUtils.class);
    when(context.isLogoutRequest()).thenReturn(false);
    when(httpServletRequest.getParameter(SMSOTPConstants.MOBILE_NUMBER)).thenReturn("true");
    context.setTenantDomain("carbon.super");
    when((AuthenticatedUser) context.getProperty(SMSOTPConstants.AUTHENTICATED_USER)).thenReturn(AuthenticatedUser.createLocalAuthenticatedUserFromSubjectIdentifier("admin"));
    FederatedAuthenticatorUtil.setUsernameFromFirstStep(context);
    when(SMSOTPUtils.isSMSOTPMandatory(context, SMSOTPConstants.AUTHENTICATOR_NAME)).thenReturn(true);
    when(SMSOTPUtils.getErrorPageFromXMLFile(context, SMSOTPConstants.AUTHENTICATOR_NAME)).thenReturn(SMSOTPConstants.ERROR_PAGE);
    when(SMSOTPUtils.isSendOTPDirectlyToMobile(context, SMSOTPConstants.AUTHENTICATOR_NAME)).thenReturn(false);
    when(FrameworkUtils.getQueryStringWithFrameworkContextId(context.getQueryParams(), context.getCallerSessionKey(), context.getContextIdentifier())).thenReturn(null);
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    Whitebox.invokeMethod(smsotpAuthenticator, "processSMSOTPFlow", context, httpServletRequest, httpServletResponse, false, "John@carbon.super", "", "carbon.super", SMSOTPConstants.ERROR_PAGE);
    verify(httpServletResponse).sendRedirect(captor.capture());
    AuthenticatorFlowStatus status = spy.process(httpServletRequest, httpServletResponse, context);
    Assert.assertTrue(captor.getValue().contains(SMSOTPConstants.SEND_OTP_DIRECTLY_DISABLE));
    Assert.assertEquals(status, AuthenticatorFlowStatus.INCOMPLETE);
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) AuthenticatorFlowStatus(org.wso2.carbon.identity.application.authentication.framework.AuthenticatorFlowStatus) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with SMSOTPAuthenticator

use of org.wso2.carbon.identity.authenticator.smsotp.SMSOTPAuthenticator in project identity-outbound-auth-sms-otp by wso2-extensions.

the class SMSOTPAuthenticatorServiceComponent method activate.

protected void activate(ComponentContext ctxt) {
    try {
        SMSOTPAuthenticator authenticator = new SMSOTPAuthenticator();
        Hashtable<String, String> props = new Hashtable<String, String>();
        ctxt.getBundleContext().registerService(ApplicationAuthenticator.class.getName(), authenticator, props);
        if (log.isDebugEnabled()) {
            log.debug("SMSOTP authenticator is activated");
        }
    } catch (Throwable e) {
        log.fatal("Error while activating the SMSOTP authenticator ", e);
    }
}
Also used : SMSOTPAuthenticator(org.wso2.carbon.identity.authenticator.smsotp.SMSOTPAuthenticator) ApplicationAuthenticator(org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator) Hashtable(java.util.Hashtable)

Example 4 with SMSOTPAuthenticator

use of org.wso2.carbon.identity.authenticator.smsotp.SMSOTPAuthenticator in project identity-outbound-auth-sms-otp by wso2-extensions.

the class SMSOTPAuthenticatorTest method testCheckWithBackUpCodes.

@Test
public void testCheckWithBackUpCodes() throws Exception {
    mockStatic(IdentityTenantUtil.class);
    context.setProperty(SMSOTPConstants.USER_NAME, "admin");
    when(IdentityTenantUtil.getTenantId("carbon.super")).thenReturn(-1234);
    when(IdentityTenantUtil.getRealmService()).thenReturn(realmService);
    when(realmService.getTenantUserRealm(-1234)).thenReturn(userRealm);
    when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
    when((AuthenticatedUser) context.getProperty(SMSOTPConstants.AUTHENTICATED_USER)).thenReturn(AuthenticatedUser.createLocalAuthenticatedUserFromSubjectIdentifier("admin"));
    when(userRealm.getUserStoreManager().getUserClaimValue(MultitenantUtils.getTenantAwareUsername("admin"), SMSOTPConstants.SAVED_OTP_LIST, null)).thenReturn("12345,4568,1234,7896");
    AuthenticatedUser user = (AuthenticatedUser) context.getProperty(SMSOTPConstants.AUTHENTICATED_USER);
    Whitebox.invokeMethod(smsotpAuthenticator, "checkWithBackUpCodes", context, "1234", user);
}
Also used : AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with SMSOTPAuthenticator

use of org.wso2.carbon.identity.authenticator.smsotp.SMSOTPAuthenticator in project identity-outbound-auth-sms-otp by wso2-extensions.

the class SMSOTPAuthenticatorTest method testCheckWithInvalidBackUpCodes.

@Test(expectedExceptions = { AuthenticationFailedException.class })
public void testCheckWithInvalidBackUpCodes() throws Exception {
    mockStatic(IdentityTenantUtil.class);
    context.setProperty(SMSOTPConstants.USER_NAME, "admin");
    when(IdentityTenantUtil.getTenantId("carbon.super")).thenReturn(-1234);
    when(IdentityTenantUtil.getRealmService()).thenReturn(realmService);
    when(realmService.getTenantUserRealm(-1234)).thenReturn(userRealm);
    when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
    when((AuthenticatedUser) context.getProperty(SMSOTPConstants.AUTHENTICATED_USER)).thenReturn(AuthenticatedUser.createLocalAuthenticatedUserFromSubjectIdentifier("admin"));
    when(userRealm.getUserStoreManager().getUserClaimValue(MultitenantUtils.getTenantAwareUsername("admin"), SMSOTPConstants.SAVED_OTP_LIST, null)).thenReturn("12345,4568,1234,7896");
    AuthenticatedUser user = (AuthenticatedUser) context.getProperty(SMSOTPConstants.AUTHENTICATED_USER);
    Whitebox.invokeMethod(smsotpAuthenticator, "checkWithBackUpCodes", context, "45698789", user);
}
Also used : AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 Test (org.testng.annotations.Test)8 SMSOTPAuthenticator (org.wso2.carbon.identity.authenticator.smsotp.SMSOTPAuthenticator)5 Matchers.anyString (org.mockito.Matchers.anyString)3 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)3 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)2 Hashtable (java.util.Hashtable)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 ApplicationAuthenticator (org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator)1 AuthenticatorFlowStatus (org.wso2.carbon.identity.application.authentication.framework.AuthenticatorFlowStatus)1