public static String getMultiAttributeSeparator() { String multiAttributeSeparator = null; try { multiAttributeSeparator = CarbonContext.getThreadLocalCarbonContext().getUserRealm(). getRealmConfiguration().getUserStoreProperty(IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR); } catch (UserStoreException e) { log.warn("Error while retrieving MultiAttributeSeparator from UserRealm."); if (log.isDebugEnabled()) { log.debug("Error while retrieving MultiAttributeSeparator from UserRealm." + e); } } if (StringUtils.isBlank(multiAttributeSeparator)) { multiAttributeSeparator = IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR_DEFAULT; if (log.isDebugEnabled()) { log.debug("Multi Attribute Separator is defaulting to " + multiAttributeSeparator); } } return multiAttributeSeparator; }
public static String getMultiAttributeSeparator() { String multiAttributeSeparator = null; try { multiAttributeSeparator = CarbonContext.getThreadLocalCarbonContext().getUserRealm(). getRealmConfiguration().getUserStoreProperty(IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR); } catch (UserStoreException e) { log.warn("Error while retrieving MultiAttributeSeparator from UserRealm."); if (log.isDebugEnabled()) { log.debug("Error while retrieving MultiAttributeSeparator from UserRealm." + e); } } if (StringUtils.isBlank(multiAttributeSeparator)) { multiAttributeSeparator = IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR_DEFAULT; if (log.isDebugEnabled()) { log.debug("Multi Attribute Separator is defaulting to " + multiAttributeSeparator); } } return multiAttributeSeparator; }
private void initDatasource() { try { dataSource = DatabaseUtil.getRealmDataSource(CarbonContext.getThreadLocalCarbonContext().getUserRealm(). getRealmConfiguration()); } catch (UserStoreException e) { log.error("Error while retrieving user management data source", e); } } }
private void initDatasource() { try { dataSource = DatabaseUtil.getRealmDataSource(CarbonContext.getThreadLocalCarbonContext().getUserRealm(). getRealmConfiguration()); } catch (UserStoreException e) { log.error("Error while retrieving user management data source", e); } } }
private void initDatasource() { try { dataSource = DatabaseUtil.getRealmDataSource(CarbonContext.getThreadLocalCarbonContext().getUserRealm(). getRealmConfiguration()); } catch (UserStoreException e) { log.error("Error while retrieving user management data source", e); } } }
/** * Get the fully qualified action holder (userStoreDomain/user@tenantdomain). * * @param actionHolder Username of the action holder * @param actionHolderTenantDomain The tenant domain of the action holder * @return The action holder */ public static String getActionHolder(String actionHolder, String actionHolderTenantDomain) { String fullyQualifiedActionHolderName = null; try { String actionHolderUserStoreDomain = UserCoreUtil.getDomainName( CarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration()); if (StringUtils.isNotBlank(actionHolder) && StringUtils.isNotBlank(actionHolderTenantDomain) && StringUtils.isNotBlank(actionHolderUserStoreDomain)) { fullyQualifiedActionHolderName = actionHolderUserStoreDomain + "/" + actionHolder + "@" + actionHolderTenantDomain; } } catch (UserStoreException e) { log.error("Failed to fetch action holder user store domain for user " + actionHolder); } return fullyQualifiedActionHolderName; }
private String getAdminRole() throws UserStoreException { return CarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration().getAdminRoleName(); }
@Override @Deprecated public String getAttributeName(String claimURI) throws UserStoreException { UserRealm realm = IdentityClaimManagementServiceDataHolder.getInstance().getRealmService() .getTenantUserRealm(tenantId); String primaryDomainName = realm.getRealmConfiguration().getUserStoreProperty (UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME); return getAttributeName(primaryDomainName, claimURI); }
@Override @Deprecated public String getAttributeName(String claimURI) throws UserStoreException { UserRealm realm = IdentityClaimManagementServiceDataHolder.getInstance().getRealmService() .getTenantUserRealm(tenantId); String primaryDomainName = realm.getRealmConfiguration().getUserStoreProperty (UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME); return getAttributeName(primaryDomainName, claimURI); }
@Override @Deprecated public String getAttributeName(String claimURI) throws UserStoreException { UserRealm realm = IdentityClaimManagementServiceDataHolder.getInstance().getRealmService() .getTenantUserRealm(tenantId); String primaryDomainName = realm.getRealmConfiguration().getUserStoreProperty (UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME); return getAttributeName(primaryDomainName, claimURI); }
public void terminatingConfigurationContext(ConfigurationContext context) { try { org.wso2.carbon.user.api.UserRealm tenantRealm = CarbonContext .getThreadLocalCarbonContext().getUserRealm(); RealmConfiguration realmConfig = tenantRealm.getRealmConfiguration(); AbstractUserStoreManager userStoreManager = (AbstractUserStoreManager) tenantRealm .getUserStoreManager(); userStoreManager.clearAllSecondaryUserStores(); realmConfig.setSecondaryRealmConfig(null); userStoreManager.setSecondaryUserStoreManager(null); log.info("Unloaded all secondary user stores for tenant " + CarbonContext.getThreadLocalCarbonContext().getTenantId()); } catch (Exception ex) { log.error(ex.getMessage()); } }
public void terminatingConfigurationContext(ConfigurationContext context) { try { org.wso2.carbon.user.api.UserRealm tenantRealm = CarbonContext .getThreadLocalCarbonContext().getUserRealm(); RealmConfiguration realmConfig = tenantRealm.getRealmConfiguration(); AbstractUserStoreManager userStoreManager = (AbstractUserStoreManager) tenantRealm .getUserStoreManager(); userStoreManager.clearAllSecondaryUserStores(); realmConfig.setSecondaryRealmConfig(null); userStoreManager.setSecondaryUserStoreManager(null); log.info("Unloaded all secondary user stores for tenant " + CarbonContext.getThreadLocalCarbonContext().getTenantId()); } catch (Exception ex) { log.error(ex.getMessage()); } }
public void terminatingConfigurationContext(ConfigurationContext context) { try { org.wso2.carbon.user.api.UserRealm tenantRealm = CarbonContext .getThreadLocalCarbonContext().getUserRealm(); RealmConfiguration realmConfig = tenantRealm.getRealmConfiguration(); AbstractUserStoreManager userStoreManager = (AbstractUserStoreManager) tenantRealm .getUserStoreManager(); userStoreManager.clearAllSecondaryUserStores(); realmConfig.setSecondaryRealmConfig(null); userStoreManager.setSecondaryUserStoreManager(null); log.info("Unloaded all secondary user stores for tenant " + CarbonContext.getThreadLocalCarbonContext().getTenantId()); } catch (Exception ex) { log.error(ex.getMessage()); } }
/** * Get the domain names of user stores which has count functionality enabled * * @return */ public static Set<String> getCountEnabledUserStores() throws UserStoreCounterException { RealmConfiguration realmConfiguration; Set<String> userStoreList = new HashSet<>(); try { realmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration(); while (realmConfiguration != null) { if (!Boolean.valueOf(realmConfiguration.getUserStoreProperty( UserCoreConstants.RealmConfig.USER_STORE_DISABLED))) { if (StringUtils.isNotEmpty(realmConfiguration.getUserStoreProperty(countRetrieverClass))) { userStoreList.add(realmConfiguration .getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME)); } } realmConfiguration = realmConfiguration.getSecondaryRealmConfig(); } } catch (UserStoreException e) { throw new UserStoreCounterException("Error while getting the count enabled user stores", e); } return userStoreList; }
/** * Get the available list of user store domains * * @return * @throws UserStoreCounterException */ public static Map<String, RealmConfiguration> getUserStoreList() throws UserStoreCounterException { String domain; RealmConfiguration realmConfiguration; Map<String, RealmConfiguration> userStoreList = new HashMap<>(); try { realmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration(); domain = IdentityUtil.getPrimaryDomainName(); userStoreList.put(domain, realmConfiguration); while (realmConfiguration != null) { realmConfiguration = realmConfiguration.getSecondaryRealmConfig(); if (realmConfiguration != null) { domain = realmConfiguration .getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME); userStoreList.put(domain, realmConfiguration); } else { break; } } } catch (UserStoreException e) { throw new UserStoreCounterException("Error while listing user stores for count functionality", e); } return userStoreList; }
/** * Create an instance of the given count retriever for internal domain * * @return * @throws UserStoreCounterException */ public static UserStoreCountRetriever getInternalCounterInstance() throws UserStoreCounterException { UserStoreCountRetriever countRetreiver; try { countRetreiver = UserStoreCountDataHolder.getInstance().getCountRetrieverFactories() .get(InternalCountRetriever.class.getName()).buildCountRetriever(CarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration()); if (countRetreiver == null) { throw new UserStoreCounterException("Could not create a count retriever for Internal domain"); } } catch (UserStoreException e) { throw new UserStoreCounterException("Could not create a count retriever for Internal domain"); } return countRetreiver; }
public static boolean isUserStoreEnabled(String domain) throws UserStoreCounterException { RealmConfiguration realmConfiguration; boolean isEnabled = false; try { realmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration(); do { String userStoreDomain = realmConfiguration. getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME); if (domain.equals(userStoreDomain)) { isEnabled = !Boolean.valueOf(realmConfiguration.getUserStoreProperty(UserCoreConstants.RealmConfig. USER_STORE_DISABLED)); break; } realmConfiguration = realmConfiguration.getSecondaryRealmConfig(); } while (realmConfiguration != null); } catch (UserStoreException e) { throw new UserStoreCounterException("Error occurred while getting Secondary Realm Configuration", e); } return isEnabled; } }
public static Set<String> getSuspensionNotificationEnabledUserStores(String tenantDomain) throws AccountSuspensionNotificationException { RealmConfiguration realmConfiguration; Set<String> userStoreSet = new HashSet<>(); String domain; try { realmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration(); domain = IdentityUtil.getPrimaryDomainName(); if (isEffectiveUserStore(realmConfiguration, true)) { userStoreSet.add(domain); } do { realmConfiguration = realmConfiguration.getSecondaryRealmConfig(); if (realmConfiguration != null) { if (isEffectiveUserStore(realmConfiguration, false)) { userStoreSet.add(realmConfiguration .getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME)); } } } while (realmConfiguration != null); } catch (UserStoreException e) { throw new AccountSuspensionNotificationException("Error while getting the notification enabled user stores", e); } return userStoreSet; }
/** * Add permissions to the appmgt/applicationdata collection for given role. * * @param roleName * @throws org.wso2.carbon.appmgt.api.AppManagementException */ public static void addNewRole(String roleName, Permission[] permissions, org.wso2.carbon.user.api.UserRealm userRealm) throws AppManagementException { // TODO: Merge different resource loading methods and create a single method. try { String tenantAdminName = userRealm.getRealmConfiguration().getAdminUserName(); String[] userList = new String[]{tenantAdminName}; String[] existingRoles = userRealm.getUserStoreManager().getRoleNames(); boolean roleExists = false; for(String role : existingRoles){ if(role.equalsIgnoreCase(roleName)){ roleExists = true; break; } } if(!roleExists) { userRealm.getUserStoreManager().addRole(roleName, userList, permissions); } } catch (UserStoreException e) { throw new AppManagementException("Error while adding new role : " + roleName, e); } }
public static void waitAndInitialize() { try { String mgtTransport = CarbonUtils.getManagementTransport(); AxisConfiguration axisConfiguration = ServiceReferenceHolder .getContextService().getServerConfigContext().getAxisConfiguration(); int mgtTransportPort = CarbonUtils.getTransportProxyPort(axisConfiguration, mgtTransport); if (mgtTransportPort <= 0) { mgtTransportPort = CarbonUtils.getTransportPort(axisConfiguration, mgtTransport); } // Using localhost as the hostname since this is always an internal admin service call. // Hostnames that can be retrieved using other approaches does not work in this context. url = mgtTransport + "://" + TenantInitializationConstants.LOCAL_HOST_NAME + ":" + mgtTransportPort + "/services/"; adminName = ServiceDataHolder.getInstance().getRealmService() .getTenantUserRealm(MultitenantConstants.SUPER_TENANT_ID).getRealmConfiguration() .getAdminUserName(); adminPwd = ServiceDataHolder.getInstance().getRealmService() .getTenantUserRealm(MultitenantConstants.SUPER_TENANT_ID).getRealmConfiguration() .getAdminPassword().toCharArray(); executor = new ScheduledThreadPoolExecutor(1); executor.scheduleAtFixedRate(new ScheduledThreadPoolExecutorImpl(), TenantInitializationConstants.DEFAULT_WAIT_DURATION, TenantInitializationConstants.DEFAULT_WAIT_DURATION, TimeUnit.SECONDS); } catch (UserStoreException e) { log.error("An error occurred while retrieving admin credentials for initializing on-premise " + "gateway configuration.", e); } }