@Override public void addRole(String roleName, String[] userList, Permission[] permissions) throws org.wso2.carbon.user.api.UserStoreException { for (Iterator<Entry<String, WSUserStoreManager>> iterator = remoteServers.entrySet() .iterator(); iterator.hasNext(); ) { Entry<String, WSUserStoreManager> remoteStore = iterator.next(); try { remoteStore.getValue().addRole(roleName, userList, permissions); } catch (org.wso2.carbon.user.api.UserStoreException e) { if (!CONNECTION_REFUSED.equalsIgnoreCase(e.getMessage())) { throw e; } log.error("Failed to update the remote server : " + remoteStore.getKey()); } } }
public boolean isReadOnlyUserStore() throws UserProfileException { try { UserRealm realm = getUserRealm(); if ("true".equals(realm.getRealmConfiguration().getUserStoreProperty( UserCoreConstants.RealmConfig.PROPERTY_READ_ONLY))) { return true; } return false; } catch (UserStoreException e) { log.error(e.getMessage(), e); throw new UserProfileException(e.getMessage(), e); } }
public boolean isReadOnlyUserStore() throws UserProfileException { try { UserRealm realm = getUserRealm(); if ("true".equals(realm.getRealmConfiguration().getUserStoreProperty( UserCoreConstants.RealmConfig.PROPERTY_READ_ONLY))) { return true; } return false; } catch (UserStoreException e) { log.error(e.getMessage(), e); throw new UserProfileException(e.getMessage(), e); } }
/** * Get the tenant id of the given tenant domain. * * @param tenantDomain Tenant Domain * @return Tenant Id of domain user belongs to. * @throws IdentityApplicationManagementException Error when getting tenant id from tenant * domain */ private static int getTenantIdOfDomain(String tenantDomain) throws IdentityApplicationManagementException { try { return IdPManagementUtil.getTenantIdOfDomain(tenantDomain); } catch (UserStoreException e) { log.error(e.getMessage(), e); String msg = "Error occurred while getting Tenant Id from Tenant domain " + tenantDomain; throw new IdentityApplicationManagementException(msg); } }
/** * Get the tenant id of the given tenant domain. * * @param tenantDomain Tenant Domain * @return Tenant Id of domain user belongs to. * @throws IdentityApplicationManagementException Error when getting tenant id from tenant * domain */ private static int getTenantIdOfDomain(String tenantDomain) throws IdentityApplicationManagementException { try { return IdPManagementUtil.getTenantIdOfDomain(tenantDomain); } catch (UserStoreException e) { log.error(e.getMessage(), e); String msg = "Error occurred while getting Tenant Id from Tenant domain " + tenantDomain; throw new IdentityApplicationManagementException(msg); } }
private boolean isUserNameWithAllowedDomainName(String userName, UserRealm realm) throws IdentityException { int index; index = userName.indexOf("/"); // Check whether we have a secondary UserStoreManager setup. if (index > 0) { // Using the short-circuit. User name comes with the domain name. try { return !realm.getRealmConfiguration().isRestrictedDomainForSlefSignUp( userName.substring(0, index)); } catch (UserStoreException e) { throw IdentityException.error(e.getMessage(), e); } } return true; }
private boolean isUserNameWithAllowedDomainName(String userName, UserRealm realm) throws IdentityException { int index; index = userName.indexOf("/"); // Check whether we have a secondary UserStoreManager setup. if (index > 0) { // Using the short-circuit. User name comes with the domain name. try { return !realm.getRealmConfiguration().isRestrictedDomainForSlefSignUp( userName.substring(0, index)); } catch (UserStoreException e) { throw IdentityException.error(e.getMessage(), e); } } return true; }
public static boolean isUserAuthorized(int tenantId, String username, String permission) throws AnalyticsException { if (logger.isDebugEnabled()) { logger.debug("User[" + username + "] calling method (" + Thread.currentThread().getStackTrace()[2] .getMethodName() + ") with permission[" + permission + "]"); } try { UserRealm userRealm = AnalyticsServiceHolder.getRealmService().getTenantUserRealm(tenantId); return userRealm.getAuthorizationManager().isUserAuthorized(MultitenantUtils.getTenantAwareUsername(username), permission, CarbonConstants.UI_PERMISSION_ACTION); } catch (UserStoreException e) { throw new AnalyticsException("Unable to get user permission information for user[" + username + "] due to " + e.getMessage(), e); } } }
public static String getTenantDomain(UserStoreManager userStoreManager) { try { return IdentityTenantUtil.getTenantDomain(userStoreManager.getTenantId()); } catch (UserStoreException e) { throw AccountLockRuntimeException.error(e.getMessage(), e); } }
public static String getTenantDomain(UserStoreManager userStoreManager) { try { return IdentityTenantUtil.getTenantDomain(userStoreManager.getTenantId()); } catch (UserStoreException e) { throw AccountLockRuntimeException.error(e.getMessage(), e); } }
private UserStoreManager getUserStoreManager(OAuth2AccessTokenReqDTO tokenReq) throws IdentityOAuth2Exception { int tenantId = getTenantId(tokenReq); RealmService realmService = OAuthComponentServiceHolder.getInstance().getRealmService(); UserStoreManager userStoreManager; try { userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager(); } catch (UserStoreException e) { throw new IdentityOAuth2Exception(e.getMessage(), e); } if (log.isDebugEnabled()) { log.debug("Retrieved user store manager for tenant id: " + tenantId); } return userStoreManager; }
@Override public void execute() { String includeTableNames = this.getProperties().get(Constants.INCLUDE_TABLES); String[] includeTables = includeTableNames.split(Constants.INCLUDE_CLASS_SPLITTER); purge(includeTables, MultitenantConstants.SUPER_TENANT_ID); TenantManager tenantManager = AnalyticsServiceHolder.getRealmService().getTenantManager(); if (tenantManager != null) { try { Tenant[] allTenants = tenantManager.getAllTenants(); if (allTenants != null) { for (Tenant tenant : allTenants) { purge(includeTables, tenant.getId()); } } } catch (UserStoreException e) { logger.error("Unable to get tenant related information: " + e.getMessage(), e); } } }
public static String getTenantDomain(int tenantId) throws IdentityRuntimeException { String tenantDomain = null; try { tenantDomain = realmService.getTenantManager().getDomain(tenantId); } catch (UserStoreException e) { // Ideally user.core should be throwing an unchecked exception, in which case no need to wrap at this // level once more without adding any valuable contextual information. Because we don't have exception // enrichment properly implemented, we are appending the error message from the UserStoreException to the // new message throw IdentityRuntimeException.error("Error occurred while retrieving tenantDomain for tenantId: " + tenantId + e.getMessage(), e); } if(tenantDomain == null){ throw IdentityRuntimeException.error("Invalid tenant domain " + tenantDomain); } else { return tenantDomain; } }
public static String getTenantDomain(int tenantId) throws IdentityRuntimeException { String tenantDomain = null; try { tenantDomain = realmService.getTenantManager().getDomain(tenantId); } catch (UserStoreException e) { // Ideally user.core should be throwing an unchecked exception, in which case no need to wrap at this // level once more without adding any valuable contextual information. Because we don't have exception // enrichment properly implemented, we are appending the error message from the UserStoreException to the // new message throw IdentityRuntimeException.error("Error occurred while retrieving tenantDomain for tenantId: " + tenantId + e.getMessage(), e); } if (tenantDomain == null) { throw IdentityRuntimeException.error("Can not find the tenant domain for the tenant id " + tenantId); } else { return tenantDomain; } }
public static int getTenantId(String tenantDomain) throws IdentityRuntimeException { int tenantId = MultitenantConstants.INVALID_TENANT_ID; try { tenantId = realmService.getTenantManager().getTenantId(tenantDomain); } catch (UserStoreException e) { // Ideally user.core should be throwing an unchecked exception, in which case no need to wrap at this // level once more without adding any valuable contextual information. Because we don't have exception // enrichment properly implemented, we are appending the error message from the UserStoreException to the // new message throw IdentityRuntimeException.error("Error occurred while retrieving tenantId for tenantDomain: " + tenantDomain + e.getMessage(), e); } if(tenantId == MultitenantConstants.INVALID_TENANT_ID){ throw IdentityRuntimeException.error("Invalid tenant domain " + tenantDomain); } else { return tenantId; } }
public static String getTenantDomain(int tenantId) throws IdentityRuntimeException { String tenantDomain = null; try { tenantDomain = realmService.getTenantManager().getDomain(tenantId); } catch (UserStoreException e) { // Ideally user.core should be throwing an unchecked exception, in which case no need to wrap at this // level once more without adding any valuable contextual information. Because we don't have exception // enrichment properly implemented, we are appending the error message from the UserStoreException to the // new message throw IdentityRuntimeException.error("Error occurred while retrieving tenantDomain for tenantId: " + tenantId + e.getMessage(), e); } if (tenantDomain == null) { throw IdentityRuntimeException.error("Can not find the tenant domain for the tenant id " + tenantId); } else { return tenantDomain; } }
public static int getTenantId(String tenantDomain) throws IdentityRuntimeException { int tenantId = MultitenantConstants.INVALID_TENANT_ID; try { if (realmService != null) { tenantId = realmService.getTenantManager().getTenantId(tenantDomain); } } catch (UserStoreException e) { // Ideally user.core should be throwing an unchecked exception, in which case no need to wrap at this // level once more without adding any valuable contextual information. Because we don't have exception // enrichment properly implemented, we are appending the error message from the UserStoreException to the // new message throw IdentityRuntimeException.error("Error occurred while retrieving tenantId for tenantDomain: " + tenantDomain + e.getMessage(), e); } if(tenantId == MultitenantConstants.INVALID_TENANT_ID){ throw IdentityRuntimeException.error("Invalid tenant domain " + tenantDomain); } else { return tenantId; } }
public static int getTenantId(String tenantDomain) throws IdentityRuntimeException { int tenantId = MultitenantConstants.INVALID_TENANT_ID; try { if (realmService != null) { tenantId = realmService.getTenantManager().getTenantId(tenantDomain); } } catch (UserStoreException e) { // Ideally user.core should be throwing an unchecked exception, in which case no need to wrap at this // level once more without adding any valuable contextual information. Because we don't have exception // enrichment properly implemented, we are appending the error message from the UserStoreException to the // new message throw IdentityRuntimeException.error("Error occurred while retrieving tenantId for tenantDomain: " + tenantDomain + e.getMessage(), e); } if(tenantId == MultitenantConstants.INVALID_TENANT_ID){ throw IdentityRuntimeException.error("Invalid tenant domain " + tenantDomain); } else { return tenantId; } }
private void doAddUser(int i, UserStoreManager admin, String[] identityRoleNames, String userName, Permission permission) throws IdentityException, UserStoreException { try { if (!admin.isExistingRole(identityRoleNames[i], false)) { permission = new Permission("/permission/admin/login", UserMgtConstants.EXECUTE_ACTION); admin.addRole(identityRoleNames[i], new String[]{userName}, new Permission[]{permission}, false); } else { // if role already exists, just add user to role admin.updateUserListOfRole(identityRoleNames[i], new String[]{}, new String[]{userName}); } } catch (org.wso2.carbon.user.api.UserStoreException e) { // If something goes wrong here - then remove the already added user. admin.deleteUser(userName); throw IdentityException.error("Error occurred while adding user : " + userName + ". " + e.getMessage(), e); } }
private void doAddUser(int i, UserStoreManager admin, String[] identityRoleNames, String userName, Permission permission) throws IdentityException, UserStoreException { try { if (!admin.isExistingRole(identityRoleNames[i], false)) { permission = new Permission("/permission/admin/login", UserMgtConstants.EXECUTE_ACTION); admin.addRole(identityRoleNames[i], new String[]{userName}, new Permission[]{permission}, false); } else { // if role already exists, just add user to role admin.updateUserListOfRole(identityRoleNames[i], new String[]{}, new String[]{userName}); } } catch (org.wso2.carbon.user.api.UserStoreException e) { // If something goes wrong here - then remove the already added user. admin.deleteUser(userName); throw IdentityException.error("Error occurred while adding user : " + userName + ". " + e.getMessage(), e); } }