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