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