/** * Get the tenant id of the given tenant domain. * * @param tenantDomain Tenant Domain * @return Tenant Id of domain user belongs to. * @throws UserStoreException Error when getting tenant id from tenant domain */ public static int getTenantIdOfDomain(String tenantDomain) throws UserStoreException { if (tenantDomain != null) { TenantManager tenantManager = IdPManagementServiceComponent.getRealmService() .getTenantManager(); int tenantId = tenantManager.getTenantId(tenantDomain); return tenantId; } else { log.debug("Invalid tenant domain: \'NULL\'"); throw new IllegalArgumentException("Invalid tenant domain: \'NULL\'"); } }
public static String getTenantDomainFromTenantId(int tenantId) throws APIKeyMgtException { try { TenantManager tenantManager = APIKeyMgtDataHolder.getRealmService().getTenantManager(); return tenantManager.getDomain(tenantId); } catch (UserStoreException e) { String errorMsg = "Error when getting the Tenant domain name for the given Tenant Id"; log.error(errorMsg, e); throw new APIKeyMgtException(errorMsg, e); } }
/** * Get the tenant id of the given user. * * @param username Username * @return Tenant Id of domain user belongs to. * @throws IdentityRuntimeException Error when getting the tenant Id from tenant domain */ public static int getTenantIdOfUser(String username) throws IdentityRuntimeException { int tenantId = MultitenantConstants.INVALID_TENANT_ID; String domainName = MultitenantUtils.getTenantDomain(username); if (domainName != null) { try { TenantManager tenantManager = IdentityTenantUtil.getRealmService().getTenantManager(); tenantId = tenantManager.getTenantId(domainName); } catch (UserStoreException e) { String errorMsg = "Error when getting the tenant id from the tenant domain : " + domainName; throw IdentityRuntimeException.error(errorMsg, e); } } if(tenantId == MultitenantConstants.INVALID_TENANT_ID){ throw IdentityRuntimeException.error("Invalid tenant domain of user " + username); } else { return tenantId; } } }
RealmService realmService = IdentityMgtServiceDataHolder.getInstance().getRealmService(); TenantManager tenantManager = realmService.getTenantManager(); userTenantDomain = tenantManager.getDomain(tenantId); } catch (org.wso2.carbon.user.api.UserStoreException e) { log.error("Unable to get the get the domain from realmService for tenant: " + tenantId, e);
/** * Get the tenant id of the given user. * * @param username Username * @return Tenant Id of domain user belongs to. * @throws IdentityRuntimeException Error when getting the tenant Id from tenant domain */ public static int getTenantIdOfUser(String username) throws IdentityRuntimeException { int tenantId = MultitenantConstants.INVALID_TENANT_ID; String domainName = MultitenantUtils.getTenantDomain(username); if (domainName != null) { try { TenantManager tenantManager = IdentityTenantUtil.getRealmService().getTenantManager(); tenantId = tenantManager.getTenantId(domainName); } catch (UserStoreException e) { String errorMsg = "Error when getting the tenant id from the tenant domain : " + domainName; throw IdentityRuntimeException.error(errorMsg, e); } } if(tenantId == MultitenantConstants.INVALID_TENANT_ID){ throw IdentityRuntimeException.error("Invalid tenant domain of user " + username); } else { return tenantId; } } }
(UserRealmService) PrivilegedCarbonContext.getThreadLocalCarbonContext() .getOSGiService(UserRealmService.class); String requestedTenantDomain = realmService.getTenantManager().getDomain(tenantIdOfStore);
/** * Get the tenant id of the given user. * * @param username Username * @return Tenant Id of domain user belongs to. * @throws IdentityRuntimeException Error when getting the tenant Id from tenant domain */ public static int getTenantIdOfUser(String username) throws IdentityRuntimeException { int tenantId = MultitenantConstants.INVALID_TENANT_ID; String domainName = MultitenantUtils.getTenantDomain(username); if (domainName != null) { try { TenantManager tenantManager = IdentityTenantUtil.getRealmService().getTenantManager(); tenantId = tenantManager.getTenantId(domainName); } catch (UserStoreException e) { String errorMsg = "Error when getting the tenant id from the tenant domain : " + domainName; throw IdentityRuntimeException.error(errorMsg, e); } } if(tenantId == MultitenantConstants.INVALID_TENANT_ID){ throw IdentityRuntimeException.error("Invalid tenant domain of user " + username); } else { return tenantId; } } }
public void changePasswordByUser(String userName, String oldPassword, String newPassword) throws UserAdminException { try { String tenantDomain = MultitenantUtils.getTenantDomain(userName); String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(userName); UserRealmService realmService = UserMgtDSComponent.getRealmService(); int tenantId = realmService.getTenantManager().getTenantId(tenantDomain); org.wso2.carbon.user.api.UserRealm userRealm = realmService.getTenantUserRealm(tenantId); org.wso2.carbon.user.api.UserStoreManager userStore = userRealm.getUserStoreManager(); userStore.updateCredential(tenantAwareUsername, newPassword, oldPassword); } catch (UserStoreException e) { // previously logged so logging not needed throw new UserAdminException(e.getMessage(), e); } catch (org.wso2.carbon.user.api.UserStoreException e) { log.error("Error while getting tenant user realm", e); throw new UserAdminException("Error while getting tenant user realm" , e); } }
public void changePasswordByUser(String userName, String oldPassword, String newPassword) throws UserAdminException { try { String tenantDomain = MultitenantUtils.getTenantDomain(userName); String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(userName); UserRealmService realmService = UserMgtDSComponent.getRealmService(); int tenantId = realmService.getTenantManager().getTenantId(tenantDomain); org.wso2.carbon.user.api.UserRealm userRealm = realmService.getTenantUserRealm(tenantId); org.wso2.carbon.user.api.UserStoreManager userStore = userRealm.getUserStoreManager(); userStore.updateCredential(tenantAwareUsername, newPassword, oldPassword); } catch (UserStoreException e) { // previously logged so logging not needed throw new UserAdminException(e.getMessage(), e); } catch (org.wso2.carbon.user.api.UserStoreException e) { log.error("Error while getting tenant user realm", e); throw new UserAdminException("Error while getting tenant user realm" , e); } }
TenantManager tenantManager = SignedJWTAuthenticatorServiceComponent .getRealmService().getTenantManager(); int tenantId = tenantManager.getTenantId(tenantDomain);
int tenantId = realmService.getTenantManager().getTenantId(tenantDomain); org.wso2.carbon.user.api.UserRealm userRealm = realmService.getTenantUserRealm(tenantId); String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(userName);
/** * @param oldPassword * @param newPassword * @throws UserAdminException * @throws AxisFault */ public void changePasswordByUser(String userName, String oldPassword, String newPassword) throws UserAdminException { String result = null; try { String tenantDomain = MultitenantUtils.getTenantDomain(userName); UserRealmService realmService = UserMgtDSComponent.getRealmService(); int tenantId = realmService.getTenantManager().getTenantId(tenantDomain); org.wso2.carbon.user.api.UserRealm userRealm = realmService.getTenantUserRealm(tenantId); String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(userName); boolean isAuthenticated = userRealm.getUserStoreManager().authenticate(tenantAwareUsername, oldPassword); if (isAuthenticated) { getUserAdminProxy().changePasswordByUser(userName, oldPassword, newPassword); } else { throw new UserAdminException("Error while updating password. Wrong old credential provided "); } } catch (UserAdminException e) { throw e; } catch (org.wso2.carbon.user.api.UserStoreException e) { throw new UserAdminException("Error while updating password. Please enter tenant unaware username", e); } }
/** * @param oldPassword * @param newPassword * @throws UserAdminException * @throws AxisFault */ public void changePasswordByUser(String userName, String oldPassword, String newPassword) throws UserAdminException { String result = null; try { String tenantDomain = MultitenantUtils.getTenantDomain(userName); UserRealmService realmService = UserMgtDSComponent.getRealmService(); int tenantId = realmService.getTenantManager().getTenantId(tenantDomain); org.wso2.carbon.user.api.UserRealm userRealm = realmService.getTenantUserRealm(tenantId); String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(userName); boolean isAuthenticated = userRealm.getUserStoreManager().authenticate(tenantAwareUsername, oldPassword); if (isAuthenticated) { getUserAdminProxy().changePasswordByUser(userName, oldPassword, newPassword); } else { throw new UserAdminException("The current password you entered is incorrect. "); } } catch (UserAdminException e) { throw e; } catch (org.wso2.carbon.user.api.UserStoreException e) { throw new UserAdminException("Error while updating password. Please enter tenant unaware username", e); } }