use of org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException in project identity-outbound-auth-sms-otp by wso2-extensions.
the class SMSOTPUtils method getUserRealm.
/**
* Get the user realm of the logged in user.
*
* @param tenantDomain the tenantDomain
* @return th user realm
* @throws AuthenticationFailedException
*/
public static UserRealm getUserRealm(String tenantDomain) throws AuthenticationFailedException {
UserRealm userRealm;
try {
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
RealmService realmService = IdentityTenantUtil.getRealmService();
userRealm = realmService.getTenantUserRealm(tenantId);
} catch (Exception e) {
throw new AuthenticationFailedException("Cannot find the user realm for the tenant domain " + tenantDomain, e);
}
return userRealm;
}
use of org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException in project identity-outbound-auth-sms-otp by wso2-extensions.
the class SMSOTPUtils method isSMSOTPDisableForLocalUser.
/**
* Check whether SMSOTP is disable by user.
*
* @param username the Username
* @param context the AuthenticationContext
* @return true or false
* @throws SMSOTPException
*/
public static boolean isSMSOTPDisableForLocalUser(String username, AuthenticationContext context, String authenticatorName) throws SMSOTPException, AuthenticationFailedException {
UserRealm userRealm;
try {
String tenantDomain = MultitenantUtils.getTenantDomain(username);
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
RealmService realmService = IdentityTenantUtil.getRealmService();
userRealm = realmService.getTenantUserRealm(tenantId);
username = MultitenantUtils.getTenantAwareUsername(String.valueOf(username));
boolean isEnablingControlledByUser = isSMSOTPEnableOrDisableByUser(context, authenticatorName);
if (userRealm != null) {
if (isEnablingControlledByUser) {
Map<String, String> claimValues = userRealm.getUserStoreManager().getUserClaimValues(username, new String[] { SMSOTPConstants.USER_SMSOTP_DISABLED_CLAIM_URI }, null);
return Boolean.parseBoolean(claimValues.get(SMSOTPConstants.USER_SMSOTP_DISABLED_CLAIM_URI));
}
} else {
throw new SMSOTPException("Cannot find the user realm for the given tenant domain : " + CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
}
} catch (UserStoreException e) {
throw new SMSOTPException("Failed while trying to access userRealm of the user : " + username, e);
}
return false;
}
use of org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException in project identity-outbound-auth-sms-otp by wso2-extensions.
the class SMSOTPAuthenticatorTest method testProcessWithLogout.
@Test
public void testProcessWithLogout() throws AuthenticationFailedException, LogoutFailedException {
mockStatic(FederatedAuthenticatorUtil.class);
mockStatic(SMSOTPUtils.class);
mockStatic(FrameworkUtils.class);
when(context.isLogoutRequest()).thenReturn(false);
when(httpServletRequest.getParameter(SMSOTPConstants.CODE)).thenReturn("");
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);
when(SMSOTPUtils.getBackupCode(context, SMSOTPConstants.AUTHENTICATOR_NAME)).thenReturn("false");
AuthenticatorFlowStatus status = spy.process(httpServletRequest, httpServletResponse, context);
Assert.assertEquals(status, AuthenticatorFlowStatus.INCOMPLETE);
}
use of org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException in project identity-outbound-auth-sms-otp by wso2-extensions.
the class SMSOTPAuthenticatorTest method testProcessWithLogoutTrue.
@Test
public void testProcessWithLogoutTrue() throws AuthenticationFailedException, LogoutFailedException {
when(context.isLogoutRequest()).thenReturn(true);
AuthenticatorFlowStatus status = smsotpAuthenticator.process(httpServletRequest, httpServletResponse, context);
Assert.assertEquals(status, AuthenticatorFlowStatus.SUCCESS_COMPLETED);
}
use of org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException in project identity-outbound-auth-sms-otp by wso2-extensions.
the class SMSOTPUtilsTest method testIsSMSOTPMandatoryFromLocalFile.
@Test
public void testIsSMSOTPMandatoryFromLocalFile() throws AuthenticationFailedException {
AuthenticationContext authenticationContext = new AuthenticationContext();
authenticationContext.setProperty(IdentityHelperConstants.GET_PROPERTY_FROM_REGISTRY, IdentityHelperConstants.GET_PROPERTY_FROM_REGISTRY);
authenticationContext.setProperty(SMSOTPConstants.IS_SMSOTP_MANDATORY, "true");
authenticationContext.setTenantDomain("carbon.super");
AuthenticatorConfig authenticatorConfig = new AuthenticatorConfig();
Map<String, String> parameters = new HashMap<String, String>();
parameters.put(SMSOTPConstants.IS_SMSOTP_MANDATORY, "true");
when(FileBasedConfigurationBuilder.getInstance()).thenReturn(fileBasedConfigurationBuilder);
authenticatorConfig.setParameterMap(parameters);
when(fileBasedConfigurationBuilder.getAuthenticatorBean(anyString())).thenReturn(authenticatorConfig);
Assert.assertEquals(SMSOTPUtils.isSMSOTPMandatory(authenticationContext, SMSOTPConstants.AUTHENTICATOR_NAME), true);
}
Aggregations