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