Search in sources :

Example 16 with UserRealm

use of org.wso2.carbon.user.api.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)

Example 17 with UserRealm

use of org.wso2.carbon.user.api.UserRealm in project jaggery by wso2.

the class RegistryHostObject method isAuthorized.

private boolean isAuthorized(UserRegistry registry, String resourcePath, String action) throws RegistryException {
    UserRealm userRealm = registry.getUserRealm();
    String userName = registry.getUserName();
    try {
        if (!userRealm.getAuthorizationManager().isUserAuthorized(userName, resourcePath, action)) {
            return false;
        }
    } catch (UserStoreException e) {
        throw new org.wso2.carbon.registry.core.exceptions.RegistryException("Error at Authorizing " + resourcePath + " with user " + userName + ":" + e.getMessage(), e);
    }
    return true;
}
Also used : UserRealm(org.wso2.carbon.user.core.UserRealm) UserStoreException(org.wso2.carbon.user.core.UserStoreException)

Aggregations

UserRealm (org.wso2.carbon.user.api.UserRealm)11 UserStoreException (org.wso2.carbon.user.api.UserStoreException)9 AuthenticationFailedException (org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException)6 SMSOTPException (org.wso2.carbon.identity.authenticator.smsotp.exception.SMSOTPException)5 UserRealm (org.wso2.carbon.user.core.UserRealm)4 RealmService (org.wso2.carbon.user.core.service.RealmService)4 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)3 UserStoreException (org.wso2.carbon.user.core.UserStoreException)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Test (org.testng.annotations.Test)2 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)2 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)2 IOException (java.io.IOException)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 CarbonException (org.wso2.carbon.CarbonException)1 BPMNForbiddenException (org.wso2.carbon.bpmn.rest.common.exception.BPMNForbiddenException)1 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)1 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)1 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)1