Search in sources :

Example 61 with UserRealm

use of org.wso2.carbon.user.core.UserRealm 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 62 with UserRealm

use of org.wso2.carbon.user.core.UserRealm 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

RealmService (org.wso2.carbon.user.core.service.RealmService)34 UserRealm (org.wso2.carbon.user.core.UserRealm)32 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)23 Test (org.junit.Test)21 UserRealm (org.wso2.carbon.user.api.UserRealm)20 UserStoreException (org.wso2.carbon.user.api.UserStoreException)18 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)15 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)14 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)13 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)11 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)10 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)9 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)9 UserStoreException (org.wso2.carbon.user.core.UserStoreException)7 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)6 AuthenticationFailedException (org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException)6 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)5 RealmConfiguration (org.wso2.carbon.user.api.RealmConfiguration)5 Matchers.anyString (org.mockito.Matchers.anyString)4 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)4