org.wso2.carbon.registry.api.RegistryException Java Examples
The following examples show how to use
org.wso2.carbon.registry.api.RegistryException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeoLocationProviderServiceImpl.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
@Override public String getProximityAlerts(DeviceIdentifier identifier, String owner) throws GeoLocationBasedServiceException { try { Registry registry = getGovernanceRegistry(); Resource resource = registry.get(GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_PROXIMITY + "/" + owner + "/" + identifier.getId()); if (resource != null) { Properties props = resource.getProperties(); List proxDisObj = (List) props.get(GeoServices.PROXIMITY_DISTANCE); List proxTimeObj = (List) props.get(GeoServices.PROXIMITY_TIME); return String.format("{proximityDistance:\"%s\", proximityTime:\"%s\"}", proxDisObj != null ? proxDisObj.get(0).toString() : "", proxTimeObj != null ? proxTimeObj.get(0).toString() : ""); } else { return "{'content': false}"; } } catch (RegistryException e) { return "{'content': false}"; } }
Example #2
Source File: UserRealmProxy.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
private void buildUIPermissionNodeAllSelected(Collection parent, UIPermissionNode parentNode, Registry registry, Registry tenantRegistry) throws RegistryException, UserStoreException { String[] children = parent.getChildren(); UIPermissionNode[] childNodes = new UIPermissionNode[children.length]; for (int i = 0; i < children.length; i++) { String child = children[i]; Resource resource = null; if (registry.resourceExists(child)) { resource = registry.get(child); } else if (tenantRegistry != null) { resource = tenantRegistry.get(child); } else { throw new RegistryException("Permission resource not found in the registry."); } childNodes[i] = getUIPermissionNode(resource, true); if (resource instanceof Collection) { buildUIPermissionNodeAllSelected((Collection) resource, childNodes[i], registry, tenantRegistry); } } parentNode.setNodeList(childNodes); }
Example #3
Source File: UserRealmProxy.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
private void buildUIPermissionNode(Collection parent, UIPermissionNode parentNode, Registry registry, Registry tenantRegistry, AuthorizationManager authMan, String roleName, String userName) throws RegistryException, UserStoreException { boolean isSelected = false; if (roleName != null) { isSelected = authMan.isRoleAuthorized(roleName, parentNode.getResourcePath(), UserMgtConstants.EXECUTE_ACTION); } else if (userName != null) { isSelected = authMan.isUserAuthorized(userName, parentNode.getResourcePath(), UserMgtConstants.EXECUTE_ACTION); } if (isSelected) { buildUIPermissionNodeAllSelected(parent, parentNode, registry, tenantRegistry); parentNode.setSelected(true); } else { buildUIPermissionNodeNotAllSelected(parent, parentNode, registry, tenantRegistry, authMan, roleName, userName); } }
Example #4
Source File: ApplicationManagementServiceImpl.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
private void updateApplicationPermissions(ServiceProvider updatedApp, String updatedAppName, String storedAppName) throws RegistryException, IdentityApplicationManagementException { String applicationNode = ApplicationMgtUtil.getApplicationPermissionPath() + RegistryConstants .PATH_SEPARATOR + storedAppName; org.wso2.carbon.registry.api.Registry tenantGovReg = CarbonContext.getThreadLocalCarbonContext() .getRegistry(RegistryType.USER_GOVERNANCE); boolean exist = tenantGovReg.resourceExists(applicationNode); if (exist && !StringUtils.equals(storedAppName, updatedAppName)) { ApplicationMgtUtil.renameAppPermissionPathNode(storedAppName, updatedAppName); } if (updatedApp.getPermissionAndRoleConfig() != null && ArrayUtils.isNotEmpty(updatedApp.getPermissionAndRoleConfig().getPermissions())) { ApplicationMgtUtil.updatePermissions(updatedAppName, updatedApp.getPermissionAndRoleConfig().getPermissions()); } }
Example #5
Source File: ApplicationMgtUtil.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * Delete the resource * * @param applicationName * @throws IdentityApplicationManagementException */ public static void deletePermissions(String applicationName) throws IdentityApplicationManagementException { String applicationNode = getApplicationPermissionPath() + PATH_CONSTANT + applicationName; Registry tenantGovReg = CarbonContext.getThreadLocalCarbonContext().getRegistry( RegistryType.USER_GOVERNANCE); try { boolean exist = tenantGovReg.resourceExists(applicationNode); if (exist) { tenantGovReg.delete(applicationNode); } } catch (RegistryException e) { throw new IdentityApplicationManagementException("Error while storing permissions", e); } }
Example #6
Source File: ApplicationMgtUtil.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
private static void addPermission(String applicationNode, ApplicationPermission[] permissions, Registry tenantGovReg) throws RegistryException { for (ApplicationPermission permission : permissions) { String permissionValue = permission.getValue(); if ("/".equals( permissionValue.substring(0, 1))) { //if permissions are starts with slash remove that permissionValue = permissionValue.substring(1); } String[] splitedPermission = permissionValue.split("/"); String permissinPath = applicationNode + PATH_CONSTANT; for (int i = 0; i < splitedPermission.length; i++) { permissinPath = permissinPath + splitedPermission[i] + PATH_CONSTANT; Collection permissionNode = tenantGovReg.newCollection(); permissionNode.setProperty("name", splitedPermission[i]); tenantGovReg.put(permissinPath, permissionNode); } } }
Example #7
Source File: AutoscalerServiceImpl.java From attic-stratos with Apache License 2.0 | 6 votes |
@Override public boolean removeServiceGroup(String groupName) throws CartridgeGroupNotFoundException { try { if (log.isInfoEnabled()) { log.info(String.format("Starting to remove cartridge group: [group-name] %s", groupName)); } if (RegistryManager.getInstance().serviceGroupExist(groupName)) { RegistryManager.getInstance().removeServiceGroup(groupName); if (log.isInfoEnabled()) { log.info(String.format("Cartridge group removed: [group-name] %s", groupName)); } } else { String msg = String.format("Cartridge group not found: [group-name] %s", groupName); if (log.isWarnEnabled()) { log.warn(msg); } throw new CartridgeGroupNotFoundException(msg); } } catch (org.wso2.carbon.registry.core.exceptions.RegistryException e) { String message = "Could not remove cartridge group: " + groupName; log.error(message, e); throw new RuntimeException(message, e); } return true; }
Example #8
Source File: ApplicationMgtUtil.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * Rename the registry path node name for a deleted Service provider role. * * @param oldName * @param newName * @throws IdentityApplicationManagementException */ public static void renameAppPermissionPathNode(String oldName, String newName) throws IdentityApplicationManagementException { List<ApplicationPermission> loadPermissions = loadPermissions(oldName); String newApplicationNode = ApplicationMgtUtil.getApplicationPermissionPath() + PATH_CONSTANT + oldName; Registry tenantGovReg = CarbonContext.getThreadLocalCarbonContext().getRegistry( RegistryType.USER_GOVERNANCE); //creating new application node try { for (ApplicationPermission applicationPermission : loadPermissions) { tenantGovReg.delete(newApplicationNode + PATH_CONSTANT + applicationPermission.getValue()); } tenantGovReg.delete(newApplicationNode); Collection permissionNode = tenantGovReg.newCollection(); permissionNode.setProperty("name", newName); newApplicationNode = ApplicationMgtUtil.getApplicationPermissionPath() + PATH_CONSTANT + newName; String applicationNode = newApplicationNode; tenantGovReg.put(newApplicationNode, permissionNode); addPermission(applicationNode, loadPermissions.toArray(new ApplicationPermission[loadPermissions.size()]), tenantGovReg); } catch (RegistryException e) { throw new IdentityApplicationManagementException("Error while renaming permission node " + oldName + "to " + newName, e); } }
Example #9
Source File: EmailUserNameMigrationClient.java From product-es with Apache License 2.0 | 6 votes |
/** * This method checks whether there is a overview_provider in the overview table. * @param governanceArtifactConfiguration * @return * @throws RegistryException * @throws XMLStreamException */ private boolean hasOverviewProviderElement(GovernanceArtifactConfiguration governanceArtifactConfiguration) throws RegistryException, XMLStreamException { OMElement rxtContentOM = governanceArtifactConfiguration.getContentDefinition(); Iterator tableNodes = rxtContentOM.getChildrenWithLocalName(Constants.TABLE); while (tableNodes.hasNext()) { OMElement tableOMElement = (OMElement) tableNodes.next(); if (Constants.OVERVIEW.equalsIgnoreCase(tableOMElement.getAttributeValue(new QName(Constants.NAME)))) { Iterator fieldNodes = tableOMElement.getChildrenWithLocalName(Constants.FIELD); while (fieldNodes.hasNext()) { OMElement fieldElement = (OMElement) fieldNodes.next(); OMElement nameElement = fieldElement.getFirstChildWithName(new QName(Constants.NAME)); if (nameElement != null) { if (Constants.PROVIDER.equalsIgnoreCase(nameElement.getText())) { return true; } } } } } return false; }
Example #10
Source File: GeoLocationProviderServiceImpl.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
@Override public String getSpeedAlerts(DeviceIdentifier identifier, String owner) throws GeoLocationBasedServiceException { try { Registry registry = getGovernanceRegistry(); Resource resource = registry.get(GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_SPEED + "/" + owner + "/" + identifier.getId()); if (resource == null) { return "{'content': false}"; } InputStream inputStream = resource.getContentStream(); StringWriter writer = new StringWriter(); IOUtils.copy(inputStream, writer, "UTF-8"); return "{'speedLimit':" + writer.toString() + "}"; } catch (RegistryException | IOException e) { return "{'content': false}"; } }
Example #11
Source File: GeoLocationProviderServiceImpl.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
@Override public String getSpeedAlerts() throws GeoLocationBasedServiceException { try { Registry registry = getGovernanceRegistry(); Resource resource = registry.get(GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_SPEED); if (resource == null) { return "{'content': false}"; } InputStream inputStream = resource.getContentStream(); StringWriter writer = new StringWriter(); IOUtils.copy(inputStream, writer, "UTF-8"); return "{'speedLimit':" + writer.toString() + "}"; } catch (RegistryException | IOException e) { return "{'content': false}"; } }
Example #12
Source File: GeoLocationProviderServiceImpl.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
@Override public String getProximityAlerts() throws GeoLocationBasedServiceException { try { Registry registry = getGovernanceRegistry(); Resource resource = registry.get(GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_PROXIMITY); if (resource != null) { Properties props = resource.getProperties(); List proxDisObj = (List) props.get(GeoServices.PROXIMITY_DISTANCE); List proxTimeObj = (List) props.get(GeoServices.PROXIMITY_TIME); return String.format("{proximityDistance:\"%s\", proximityTime:\"%s\"}", proxDisObj != null ? proxDisObj.get(0).toString() : "", proxTimeObj != null ? proxTimeObj.get(0).toString() : ""); } else { return "{'content': false}"; } } catch (RegistryException e) { return "{'content': false}"; } }
Example #13
Source File: GeoLocationProviderServiceImpl.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
private void updateRegistry(String path, DeviceIdentifier identifier, Object content, Map<String, String> options) throws GeoLocationBasedServiceException { try { Registry registry = getGovernanceRegistry(); Resource newResource = registry.newResource(); newResource.setContent(content); newResource.setMediaType("application/json"); for (Map.Entry<String, String> option : options.entrySet()) { newResource.addProperty(option.getKey(), option.getValue()); } registry.put(path, newResource); } catch (RegistryException e) { throw new GeoLocationBasedServiceException( "Error occurred while setting the Within Alert for " + identifier.getType() + " with id: " + identifier.getId(), e); } }
Example #14
Source File: GeoLocationProviderServiceImpl.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
private void updateRegistry(String path, Object content, Map<String, String> options) throws GeoLocationBasedServiceException { try { Registry registry = getGovernanceRegistry(); Resource newResource = registry.newResource(); newResource.setContent(content); newResource.setMediaType("application/json"); for (Map.Entry<String, String> option : options.entrySet()) { newResource.addProperty(option.getKey(), option.getValue()); } registry.put(path, newResource); } catch (RegistryException e) { throw new GeoLocationBasedServiceException( "Error occurred while setting the Within Alert", e); } }
Example #15
Source File: PermissionUtils.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
public static boolean putPermission(Permission permission) throws PermissionManagementException { boolean status; try { StringTokenizer tokenizer = new StringTokenizer(permission.getPath(), "/"); String lastToken = "", currentToken, tempPath; while (tokenizer.hasMoreTokens()) { currentToken = tokenizer.nextToken(); tempPath = lastToken + "/" + currentToken; if (!checkResourceExists(tempPath)) { createRegistryCollection(tempPath, currentToken); } lastToken = tempPath; } status = true; } catch (RegistryException e) { throw new PermissionManagementException("Error occurred while persisting permission : " + permission.getName(), e); } return status; }
Example #16
Source File: UserRealmProxy.java From carbon-identity with Apache License 2.0 | 6 votes |
private void buildUIPermissionNodeAllSelected(Collection parent, UIPermissionNode parentNode, Registry registry, Registry tenantRegistry) throws RegistryException, UserStoreException { String[] children = parent.getChildren(); UIPermissionNode[] childNodes = new UIPermissionNode[children.length]; for (int i = 0; i < children.length; i++) { String child = children[i]; Resource resource = null; if (registry.resourceExists(child)) { resource = registry.get(child); } else if (tenantRegistry != null) { resource = tenantRegistry.get(child); } else { throw new RegistryException("Permission resource not found in the registry."); } childNodes[i] = getUIPermissionNode(resource, true); if (resource instanceof Collection) { buildUIPermissionNodeAllSelected((Collection) resource, childNodes[i], registry, tenantRegistry); } } parentNode.setNodeList(childNodes); }
Example #17
Source File: UserRealmProxy.java From carbon-identity with Apache License 2.0 | 6 votes |
private void buildUIPermissionNode(Collection parent, UIPermissionNode parentNode, Registry registry, Registry tenantRegistry, AuthorizationManager authMan, String roleName, String userName) throws RegistryException, UserStoreException { boolean isSelected = false; if (roleName != null) { isSelected = authMan.isRoleAuthorized(roleName, parentNode.getResourcePath(), UserMgtConstants.EXECUTE_ACTION); } else if (userName != null) { isSelected = authMan.isUserAuthorized(userName, parentNode.getResourcePath(), UserMgtConstants.EXECUTE_ACTION); } if (isSelected) { buildUIPermissionNodeAllSelected(parent, parentNode, registry, tenantRegistry); parentNode.setSelected(true); } else { buildUIPermissionNodeNotAllSelected(parent, parentNode, registry, tenantRegistry, authMan, roleName, userName); } }
Example #18
Source File: ApplicationManagementServiceImpl.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Remove trusted service * * @param groupName Group name * @param serviceName Service name * @param trustedService Trusted service name * @throws org.wso2.carbon.registry.api.RegistryException */ private void removeTrustedService(String groupName, String serviceName, String trustedService) throws RegistryException { String resourcePath = RegistryResources.SERVICE_GROUPS + groupName + RegistryResources.SERVICES + serviceName + "/trustedServices"; Registry registry = getConfigSystemRegistry(); if (registry != null) { if (registry.resourceExists(resourcePath)) { Resource resource = registry.get(resourcePath); if (resource.getProperty(trustedService) != null) { resource.removeProperty(trustedService); } registry.put(resourcePath, resource); } } }
Example #19
Source File: ApplicationMgtUtil.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Delete the resource * * @param applicationName * @throws IdentityApplicationManagementException */ public static void deletePermissions(String applicationName) throws IdentityApplicationManagementException { String applicationNode = getApplicationPermissionPath() + PATH_CONSTANT + applicationName; Registry tenantGovReg = CarbonContext.getThreadLocalCarbonContext().getRegistry( RegistryType.USER_GOVERNANCE); try { boolean exist = tenantGovReg.resourceExists(applicationNode); if (exist) { tenantGovReg.delete(applicationNode); } } catch (RegistryException e) { throw new IdentityApplicationManagementException("Error while storing permissions", e); } }
Example #20
Source File: ConfigurationManagerUtil.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
public static boolean putRegistryResource(String path, Resource resource) throws ConfigurationManagementException { boolean status; try { ConfigurationManagerUtil.getConfigurationRegistry().beginTransaction(); ConfigurationManagerUtil.getConfigurationRegistry().put(path, resource); ConfigurationManagerUtil.getConfigurationRegistry().commitTransaction(); status = true; } catch (RegistryException e) { throw new ConfigurationManagementException( "Error occurred while persisting registry resource : " + e.getMessage(), e); } return status; }
Example #21
Source File: RegistryBasedResourceLoader.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
@Override public InputStream getResourceStream(String name) throws ResourceNotFoundException { try { Registry registry = CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_CONFIGURATION); if (registry == null) { throw new IllegalStateException("No valid registry instance is attached to the current carbon context"); } if (!registry.resourceExists(EMAIL_CONFIG_BASE_LOCATION + "/" + name)) { throw new ResourceNotFoundException("Resource '" + name + "' does not exist"); } org.wso2.carbon.registry.api.Resource resource = registry.get(EMAIL_CONFIG_BASE_LOCATION + "/" + name); resource.setMediaType("text/plain"); return resource.getContentStream(); } catch (RegistryException e) { throw new ResourceNotFoundException("Error occurred while retrieving resource", e); } }
Example #22
Source File: ApplicationMgtUtil.java From carbon-identity with Apache License 2.0 | 6 votes |
private static void addPermission(ApplicationPermission[] permissions, Registry tenantGovReg) throws RegistryException { for (ApplicationPermission permission : permissions) { String permissionValue = permission.getValue(); if ("/".equals(permissionValue.substring(0, 1))) { //if permissions are starts with slash remove that permissionValue = permissionValue.substring(1); } String[] splitedPermission = permissionValue.split("/"); String permissinPath = applicationNode + PATH_CONSTANT; for (int i = 0; i < splitedPermission.length; i++) { permissinPath = permissinPath + splitedPermission[i] + PATH_CONSTANT; Collection permissionNode = tenantGovReg.newCollection(); permissionNode.setProperty("name", splitedPermission[i]); tenantGovReg.put(permissinPath, permissionNode); } } }
Example #23
Source File: ApplicationMgtUtil.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Rename the registry path node name for a deleted Service provider role. * * @param oldName * @param newName * @throws IdentityApplicationManagementException */ public static void renameAppPermissionPathNode(String oldName, String newName) throws IdentityApplicationManagementException { List<ApplicationPermission> loadPermissions = loadPermissions(oldName); String newApplicationNode = ApplicationMgtUtil.getApplicationPermissionPath() + PATH_CONSTANT + oldName; Registry tenantGovReg = CarbonContext.getThreadLocalCarbonContext().getRegistry( RegistryType.USER_GOVERNANCE); //creating new application node try { for (ApplicationPermission applicationPermission : loadPermissions) { tenantGovReg.delete(newApplicationNode + PATH_CONSTANT + applicationPermission.getValue()); } tenantGovReg.delete(newApplicationNode); Collection permissionNode = tenantGovReg.newCollection(); permissionNode.setProperty("name", newName); newApplicationNode = ApplicationMgtUtil.getApplicationPermissionPath() + PATH_CONSTANT + newName; ApplicationMgtUtil.applicationNode = newApplicationNode; tenantGovReg.put(newApplicationNode, permissionNode); addPermission(loadPermissions.toArray(new ApplicationPermission[loadPermissions.size()]), tenantGovReg); } catch (RegistryException e) { throw new IdentityApplicationManagementException("Error while renaming permission node " + oldName + "to " + newName, e); } }
Example #24
Source File: GraphQLSchemaDefinition.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * This method saves schema definition of GraphQL APIs in the registry * * @param api API to be saved * @param schemaDefinition Graphql API definition as String * @param registry user registry * @throws APIManagementException */ public void saveGraphQLSchemaDefinition(API api, String schemaDefinition, Registry registry) throws APIManagementException { String apiName = api.getId().getApiName(); String apiVersion = api.getId().getVersion(); String apiProviderName = api.getId().getProviderName(); String resourcePath = APIUtil.getGraphqlDefinitionFilePath(apiName, apiVersion, apiProviderName); try { String saveResourcePath = resourcePath + apiProviderName + APIConstants.GRAPHQL_SCHEMA_PROVIDER_SEPERATOR + apiName + apiVersion + APIConstants.GRAPHQL_SCHEMA_FILE_EXTENSION; Resource resource; if (!registry.resourceExists(saveResourcePath)) { resource = registry.newResource(); } else { resource = registry.get(saveResourcePath); } resource.setContent(schemaDefinition); resource.setMediaType(String.valueOf(ContentType.TEXT_PLAIN)); registry.put(saveResourcePath, resource); if (log.isDebugEnabled()) { log.debug("Successfully imported the schema: " + schemaDefinition ); } String[] visibleRoles = null; if (api.getVisibleRoles() != null) { visibleRoles = api.getVisibleRoles().split(","); } //Need to set anonymous if the visibility is public APIUtil.clearResourcePermissions(resourcePath, api.getId(), ((UserRegistry) registry).getTenantId()); APIUtil.setResourcePermissions(apiProviderName, api.getVisibility(), visibleRoles, resourcePath); } catch (RegistryException e) { String errorMessage = "Error while adding Graphql Definition for " + apiName + '-' + apiVersion; log.error(errorMessage, e); handleException(errorMessage, e); } }
Example #25
Source File: DiscoveryComponent.java From carbon-commons with Apache License 2.0 | 5 votes |
@Activate protected void activate(ComponentContext context) { BundleContext bundleCtx = context.getBundleContext(); if (cfgCtxSvc != null) { // Add the observers for new updates of services and activate/deactivate events // This will only register the observers in the main axis configuration AxisConfiguration mainAxisConfig = this.cfgCtxSvc.getServerConfigContext().getAxisConfiguration(); try { if (DiscoveryMgtUtils.isServiceDiscoveryEnabled(mainAxisConfig)) { // register the service observer if (log.isDebugEnabled()) { log.debug("Registering the Axis observer for WS-Discovery"); } Util.registerServiceObserver(mainAxisConfig); } } catch (RegistryException e) { log.error("Error while checking whether service discovery is enabled", e); } // we always register the handler (handler can find out whether ws-d is enabled or not) if (log.isDebugEnabled()) { log.debug("Enabling the server shutdown handler for WS-Discovery"); } DiscoveryShutdownHandler discoveryShutdownHandler = new DiscoveryShutdownHandler(); bundleCtx.registerService(ServerShutdownHandler.class.getName(), discoveryShutdownHandler, null); } else { log.warn("Error while initializing WS-Discovery core component in super tenant. " + "ConfigurationContext" + " service is unavailable."); } // This will take care of registering observers in tenant axis configurations observerServiceRegistration = bundleCtx.registerService(Axis2ConfigurationContextObserver.class.getName(), new DiscoveryAxis2ConfigurationContextObserver(), null); // Init and publish the discovery service for other components registerDiscoveryService(context); }
Example #26
Source File: DiscoveryAxis2ConfigurationContextObserver.java From carbon-commons with Apache License 2.0 | 5 votes |
public void createdConfigurationContext(ConfigurationContext configurationContext) { AxisConfiguration axisConfig = configurationContext.getAxisConfiguration(); try { if (DiscoveryMgtUtils.isServiceDiscoveryEnabled(axisConfig)) { if (log.isDebugEnabled()) { String domain = PrivilegedCarbonContext.getThreadLocalCarbonContext(). getTenantDomain(true); log.debug("Registering the Axis observer for WS-Discovery in tenant: " + domain); } Util.registerServiceObserver(axisConfig); } } catch (RegistryException e) { log.error("Checking whether service discovery is enabled for a tenant", e); } }
Example #27
Source File: DefaultPolicyVersionManager.java From carbon-identity with Apache License 2.0 | 5 votes |
@Override public PolicyDTO getPolicy(String policyId, String version) throws EntitlementException { // Zero means current version if (version == null || version.trim().length() == 0) { Registry registry = EntitlementServiceComponent. getGovernanceRegistry(CarbonContext.getThreadLocalCarbonContext().getTenantId()); try { Collection collection = (Collection) registry. get(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId); if (collection != null) { version = collection.getProperty("version"); } } catch (RegistryException e) { log.error(e); throw new EntitlementException("Invalid policy version"); } } PAPPolicyStore policyStore = new PAPPolicyStore(); PAPPolicyStoreReader reader = new PAPPolicyStoreReader(policyStore); Resource resource = policyStore.getPolicy(version, PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId + RegistryConstants.PATH_SEPARATOR); if (resource == null) { throw new EntitlementException("Invalid policy version"); } return reader.readPolicyDTO(resource); }
Example #28
Source File: EmailUserNameMigrationClient.java From product-es with Apache License 2.0 | 5 votes |
/** * This method replaces artifacts containing email username with ':' to '-at-'. * This will replace the storage path and resource content which contains overview_provider attribute with emailusername. * * @param artifacts artifacts of a particular rxt type. with overview-provider attribute in the storage path. * @param registry registry instance * @throws RegistryException * @throws javax.xml.stream.XMLStreamException */ private static void migrateArtifactsWithEmailUserName(GenericArtifact[] artifacts, Registry registry) throws RegistryException, XMLStreamException { for (GenericArtifact artifact : artifacts) { boolean isProviderMetadataUpdated = false; String relativePath = artifact.getPath(); if (registry.resourceExists(relativePath)) { Resource resource = registry.get(relativePath); String metadataString = RegistryUtils.decodeBytes((byte[]) resource.getContent()); OMElement metadataOM = AXIOMUtil.stringToOM(metadataString); OMElement overview = metadataOM.getFirstChildWithName(new QName(Constants.METADATA_NAMESPACE, Constants.OVERVIEW)); OMElement providerElement = overview.getFirstChildWithName(new QName(Constants.METADATA_NAMESPACE, Constants.PROVIDER)); if (providerElement != null && providerElement.getText().contains(Constants.OLD_EMAIL_AT_SIGN)) { String oldProviderName = providerElement.getText(); String newProviderName = oldProviderName.replace(Constants.OLD_EMAIL_AT_SIGN, Constants.NEW_EMAIL_AT_SIGN); providerElement.setText(newProviderName); resource.setContent(metadataOM.toStringWithConsume()); isProviderMetadataUpdated = true; } String newPath = null; if (relativePath.contains(Constants.OLD_EMAIL_AT_SIGN)) { newPath = relativePath.replace(Constants.OLD_EMAIL_AT_SIGN, Constants.NEW_EMAIL_AT_SIGN);//TODO:replaceALL registry.move(relativePath, newPath); registry.put(newPath, resource); } else if (relativePath.contains(Constants.NEW_EMAIL_AT_SIGN)) { newPath = relativePath; if(isProviderMetadataUpdated==true) { registry.put(newPath, resource); } } } } }
Example #29
Source File: EmailUserNameMigrationClient.java From product-es with Apache License 2.0 | 5 votes |
/** * This method extracts the artifact types which contains '@{overview_provider}' in the storage path, and call the * migration method. * @param tenant The tenant object * @throws UserStoreException * @throws RegistryException * @throws XMLStreamException */ private void migrate(Tenant tenant) throws UserStoreException, RegistryException, XMLStreamException{ int tenantId = tenant.getId(); try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenant.getDomain(), true); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId); String adminName = ServiceHolder.getRealmService().getTenantUserRealm(tenantId).getRealmConfiguration() .getAdminUserName(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(adminName); ServiceHolder.getTenantRegLoader().loadTenantRegistry(tenantId); Registry registry = ServiceHolder.getRegistryService().getGovernanceUserRegistry(adminName, tenantId); GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry); List<GovernanceArtifactConfiguration> configurations = GovernanceUtils. findGovernanceArtifactConfigurations(registry); for (GovernanceArtifactConfiguration governanceArtifactConfiguration : configurations) { String pathExpression = governanceArtifactConfiguration.getPathExpression(); if (pathExpression.contains(Constants.OVERVIEW_PROVIDER) || hasOverviewProviderElement(governanceArtifactConfiguration)) { String shortName = governanceArtifactConfiguration.getKey(); GenericArtifactManager artifactManager = new GenericArtifactManager(registry, shortName); GenericArtifact[] artifacts = artifactManager.getAllGenericArtifacts(); migrateArtifactsWithEmailUserName(artifacts, registry); } } } finally { PrivilegedCarbonContext.endTenantFlow(); } }
Example #30
Source File: UserRealmProxy.java From carbon-identity with Apache License 2.0 | 5 votes |
private void buildUIPermissionNodeNotAllSelected(Collection parent, UIPermissionNode parentNode, Registry registry, Registry tenantRegistry, AuthorizationManager authMan, String roleName, String userName) throws RegistryException, UserStoreException { String[] children = parent.getChildren(); UIPermissionNode[] childNodes = new UIPermissionNode[children.length]; for (int i = 0; i < children.length; i++) { String child = children[i]; Resource resource = null; if (tenantRegistry != null && child.startsWith("/permission/applications")) { resource = tenantRegistry.get(child); } else if (registry.resourceExists(child)) { resource = registry.get(child); } else { throw new RegistryException("Permission resource not found in the registry."); } boolean isSelected = false; if (roleName != null) { isSelected = authMan.isRoleAuthorized(roleName, child, UserMgtConstants.EXECUTE_ACTION); } else if (userName != null) { isSelected = authMan.isUserAuthorized(userName, child, UserMgtConstants.EXECUTE_ACTION); } childNodes[i] = getUIPermissionNode(resource, isSelected); if (resource instanceof Collection) { buildUIPermissionNodeNotAllSelected((Collection) resource, childNodes[i], registry, tenantRegistry, authMan, roleName, userName); } } parentNode.setNodeList(childNodes); }