Search in sources :

Example 31 with UserStoreException

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;
}
Also used : UserRealm(org.wso2.carbon.user.api.UserRealm) RealmService(org.wso2.carbon.user.core.service.RealmService) UserStoreException(org.wso2.carbon.user.api.UserStoreException) SMSOTPException(org.wso2.carbon.identity.authenticator.smsotp.exception.SMSOTPException)

Example 32 with UserStoreException

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;
}
Also used : UserRealm(org.wso2.carbon.user.core.UserRealm) UserStoreException(org.wso2.carbon.user.core.UserStoreException)

Aggregations

UserStoreException (org.wso2.carbon.user.api.UserStoreException)21 UserRealm (org.wso2.carbon.user.api.UserRealm)10 AuthenticationFailedException (org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException)6 RealmService (org.wso2.carbon.user.core.service.RealmService)6 ArrayList (java.util.ArrayList)5 SMSOTPException (org.wso2.carbon.identity.authenticator.smsotp.exception.SMSOTPException)5 ActivitiException (org.activiti.engine.ActivitiException)4 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)4 UserRealm (org.wso2.carbon.user.core.UserRealm)4 UserStoreException (org.wso2.carbon.user.core.UserStoreException)4 IOException (java.io.IOException)3 List (java.util.List)3 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)3 BPMNAuthenticationException (org.wso2.carbon.bpmn.core.exception.BPMNAuthenticationException)3 BPMNForbiddenException (org.wso2.carbon.bpmn.rest.common.exception.BPMNForbiddenException)3 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2