org.wso2.carbon.registry.api.Resource resource = registry. get(PDPConstants.ENTITLEMENT_POLICY_PUBLISHER_VERIFICATION + verificationCode); List<String> list = resource.getPropertyValues("subscriberIds"); if (list != null) { subscriberIds = list.toArray(new String[list.size()]); list = resource.getPropertyValues("policyIds"); if (list != null) { policyIds = list.toArray(new String[list.size()]); String version = resource.getProperty("version"); if (version != null) { this.version = version; String action = resource.getProperty("action"); if (action != null) { this.action = action; String order = resource.getProperty("order"); if (order != null) { this.order = Integer.parseInt(order);
/** * Helper method * * @param verificationCode verificationCode as String * @param subscriberIds Array of subscriberIds */ private void persistVerificationCode(String verificationCode, String[] subscriberIds) { Registry registry = EntitlementServiceComponent. getGovernanceRegistry(CarbonContext.getThreadLocalCarbonContext().getTenantId()); try { org.wso2.carbon.registry.api.Resource resource = registry.newResource(); resource.setProperty("subscriberIds", Arrays.asList(subscriberIds)); resource.setProperty("policyIds", Arrays.asList(policyIds)); resource.setProperty("action", action); resource.setProperty("version", version); resource.setProperty("order", Integer.toString(order)); registry.put(PDPConstants.ENTITLEMENT_POLICY_PUBLISHER_VERIFICATION + verificationCode, resource); } catch (org.wso2.carbon.registry.api.RegistryException e) { log.error("Error while persisting verification code", e); } }
private UIPermissionNode getUIPermissionNode(Resource resource, boolean isSelected) throws RegistryException { String displayName = resource.getProperty(UserMgtConstants.DISPLAY_NAME); return new UIPermissionNode(resource.getPath(), displayName, isSelected); }
/** * Check if resource has expired and delete. * * @param registry Registry instance to use. * @param resourcePath Path of resource to be deleted. * @throws RegistryException */ private static void checkAndDeleteRegistryResource (Registry registry, String resourcePath) throws RegistryException { Resource resource = registry.get(resourcePath); long currentEpochTime = System.currentTimeMillis(); long resourceExpireTime = Long.parseLong(resource.getProperty(EXPIRE_TIME_PROPERTY)); if (currentEpochTime > resourceExpireTime) { registry.delete(resource.getId()); } }
Resource resource = registry.get(resourcePath); ClaimDTO claimDTO = new ClaimDTO(); claimDTO.setRealm(resource.getProperty(REALM_NAME).replace(SLASH_REPLACE_CHARACTER, "/")); String claims = resource.getProperty(CLAIMS); if (claims.startsWith("[")) { claims = claims.replaceFirst("\\[", ""); claimDTO.setClaimDialect(resource.getProperty(CLAIM_DIALECT));
if (registry.resourceExists(uiPermission.getResourceId())) { Resource existingResource = registry.get(uiPermission.getResourceId()); if (existingResource.getProperty(UserMgtConstants.DISPLAY_NAME) == null) { existingResource.setProperty(UserMgtConstants.DISPLAY_NAME, uiPermission.getDisplayName()); registry.put(uiPermission.getResourceId(), existingResource);
private Properties getOIDCScopeProperties(String spTenantDomain) { Resource oidcScopesResource = null; try { int tenantId = IdentityTenantUtil.getTenantId(spTenantDomain); startTenantFlow(spTenantDomain, tenantId); RegistryService registryService = OAuth2ServiceComponentHolder.getRegistryService(); if (registryService == null) { throw new RegistryException("Registry Service not set in OAuth2 Component. Component may not have " + "initialized correctly."); } oidcScopesResource = registryService.getConfigSystemRegistry(tenantId).get(SCOPE_RESOURCE_PATH); } catch (RegistryException e) { log.error("Error while obtaining registry collection from registry path:" + SCOPE_RESOURCE_PATH, e); } finally { PrivilegedCarbonContext.endTenantFlow(); } Properties propertiesToReturn = new Properties(); if (oidcScopesResource != null) { for (Object scopeProperty : oidcScopesResource.getProperties().keySet()) { String propertyKey = (String) scopeProperty; propertiesToReturn.setProperty(propertyKey, oidcScopesResource.getProperty(propertyKey)); } } else { log.error("OIDC scope resource cannot be found at " + SCOPE_RESOURCE_PATH + " for tenantDomain: " + spTenantDomain); } return propertiesToReturn; }
Resource resource = registry. get(EntitlementConstants.ENTITLEMENT_POLICY_BASIC_EDITOR_CONFIG_FILE_REGISTRY_PATH); if (resource != null && resource.getContent() != null) { configString = new String((byte[]) resource.getContent(), Charset.forName("UTF-8")); Resource resource = registry. get(EntitlementConstants.ENTITLEMENT_POLICY_STANDARD_EDITOR_CONFIG_FILE_REGISTRY_PATH); if (resource != null && resource.getContent() != null) { configString = new String((byte[]) resource.getContent(), Charset.forName("UTF-8")); config.put(EntitlementConstants.PolicyEditor.STANDARD, configString); Resource resource = registry. get(EntitlementConstants.ENTITLEMENT_POLICY_RBAC_EDITOR_CONFIG_FILE_REGISTRY_PATH); if (resource != null && resource.getContent() != null) { configString = new String((byte[]) resource.getContent(), Charset.forName("UTF-8")); config.put(EntitlementConstants.PolicyEditor.RBAC, configString); Resource resource = registry. get(EntitlementConstants.ENTITLEMENT_POLICY_SET_EDITOR_CONFIG_FILE_REGISTRY_PATH); if (resource != null && resource.getContent() != null) { configString = new String((byte[]) resource.getContent(), Charset.forName("UTF-8")); config.put(EntitlementConstants.PolicyEditor.SET, configString);
@Override public void persistConfig(String policyEditorType, String xmlConfig) throws PolicyEditorException { super.persistConfig(policyEditorType, xmlConfig); Registry registry = CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_GOVERNANCE); try { Resource resource = registry.newResource(); resource.setContent(xmlConfig); String path = null; if (EntitlementConstants.PolicyEditor.BASIC.equals(policyEditorType)) { path = EntitlementConstants.ENTITLEMENT_POLICY_BASIC_EDITOR_CONFIG_FILE_REGISTRY_PATH; } else if (EntitlementConstants.PolicyEditor.STANDARD.equals(policyEditorType)) { path = EntitlementConstants.ENTITLEMENT_POLICY_STANDARD_EDITOR_CONFIG_FILE_REGISTRY_PATH; } else if (EntitlementConstants.PolicyEditor.RBAC.equals(policyEditorType)) { path = EntitlementConstants.ENTITLEMENT_POLICY_RBAC_EDITOR_CONFIG_FILE_REGISTRY_PATH; } else if (EntitlementConstants.PolicyEditor.SET.equals(policyEditorType)) { path = EntitlementConstants.ENTITLEMENT_POLICY_SET_EDITOR_CONFIG_FILE_REGISTRY_PATH; } else { //default path = EntitlementConstants.ENTITLEMENT_POLICY_BASIC_EDITOR_CONFIG_FILE_REGISTRY_PATH; } registry.put(path, resource); } catch (RegistryException e) { throw new PolicyEditorException("Error while persisting policy editor config"); } }
resource.setContent(writer.toString()); resource.setMediaType(MobilePluginConstants.MEDIA_TYPE_XML); MobileDeviceManagementUtil.putRegistryResource(resourcePath, resource); status = true;
private void deleteRecursively (Registry registry, Resource resource) throws RegistryException { if (resource instanceof Collection) { for(String childResource : ((Collection) resource).getChildren()){ deleteRecursively(registry, registry.get(childResource)); } } registry.delete(resource.getPath()); }
/** * Add a trusted service to which tokens are issued with given claims. * * @param realmName - this uniquely represents the trusted service * @param claimDialect - claim dialects uris * @param claims - these comma separated default claims are issued when a request is done from the given realm * @throws Exception - if fails to add trusted service */ public void addTrustedService(String realmName, String claimDialect, String claims) throws Exception { realmName = replaceSlashWithConstantString(realmName); try { Registry registry = IdentityPassiveSTSServiceComponent.getConfigSystemRegistry(); String trustedServicePath = registryTrustedServicePath + realmName; // if registry collection does not exists, create if (!registry.resourceExists(trustedServicePath)) { Resource resource = registry.newResource(); resource.addProperty(REALM_NAME, realmName); resource.addProperty(CLAIMS, claims); resource.addProperty(CLAIM_DIALECT, claimDialect); registry.put(trustedServicePath, resource); } else { throw new Exception(realmName + " already added. Please remove first and add again."); } } catch (RegistryException e) { String error = "Error occurred when adding a trusted service due to error in accessing registry."; throw new Exception(error, e); } }
Resource resource = registry.get(resourcePath); ClaimDTO claimDTO = new ClaimDTO(); claimDTO.setRealm(resource.getProperty(REALM_NAME).replace(SLASH_REPLACE_CHARACTER, "/")); String claims = resource.getProperty(CLAIMS); if (claims.startsWith("[")) { claims = claims.replaceFirst("\\[", ""); claimDTO.setClaimDialect(resource.getProperty(CLAIM_DIALECT));
/** * Check if resource has expired and delete. * * @param registry Registry instance to use. * @param resourcePath Path of resource to be deleted. * @throws RegistryException */ private static void checkAndDeleteRegistryResource (Registry registry, String resourcePath) throws RegistryException { Resource resource = registry.get(resourcePath); long currentEpochTime = System.currentTimeMillis(); long resourceExpireTime = Long.parseLong(resource.getProperty(EXPIRE_TIME_PROPERTY)); if (currentEpochTime > resourceExpireTime) { registry.delete(resource.getId()); } }
if (resource != null && resource.getProperties() != null) { Enumeration supporetdScopes = resource.getProperties().propertyNames(); while (supporetdScopes.hasMoreElements()) { String supportedScope = (String) supporetdScopes.nextElement(); if (supportedScope.equals(requestedScope)) { requestedScopeClaims = resource.getProperty(requestedScope); if (requestedScopeClaims.contains(",")) { arrRequestedScopeClaims = requestedScopeClaims.split(",");
Resource resource = registry. get(EntitlementConstants.ENTITLEMENT_POLICY_BASIC_EDITOR_CONFIG_FILE_REGISTRY_PATH); if (resource != null && resource.getContent() != null) { configString = new String((byte[]) resource.getContent(), Charset.forName("UTF-8")); Resource resource = registry. get(EntitlementConstants.ENTITLEMENT_POLICY_STANDARD_EDITOR_CONFIG_FILE_REGISTRY_PATH); if (resource != null && resource.getContent() != null) { configString = new String((byte[]) resource.getContent(), Charset.forName("UTF-8")); config.put(EntitlementConstants.PolicyEditor.STANDARD, configString); Resource resource = registry. get(EntitlementConstants.ENTITLEMENT_POLICY_RBAC_EDITOR_CONFIG_FILE_REGISTRY_PATH); if (resource != null && resource.getContent() != null) { configString = new String((byte[]) resource.getContent(), Charset.forName("UTF-8")); config.put(EntitlementConstants.PolicyEditor.RBAC, configString); Resource resource = registry. get(EntitlementConstants.ENTITLEMENT_POLICY_SET_EDITOR_CONFIG_FILE_REGISTRY_PATH); if (resource != null && resource.getContent() != null) { configString = new String((byte[]) resource.getContent(), Charset.forName("UTF-8")); config.put(EntitlementConstants.PolicyEditor.SET, configString);
@Override public void persistConfig(String policyEditorType, String xmlConfig) throws PolicyEditorException { super.persistConfig(policyEditorType, xmlConfig); Registry registry = CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_GOVERNANCE); try { Resource resource = registry.newResource(); resource.setContent(xmlConfig); String path = null; if (EntitlementConstants.PolicyEditor.BASIC.equals(policyEditorType)) { path = EntitlementConstants.ENTITLEMENT_POLICY_BASIC_EDITOR_CONFIG_FILE_REGISTRY_PATH; } else if (EntitlementConstants.PolicyEditor.STANDARD.equals(policyEditorType)) { path = EntitlementConstants.ENTITLEMENT_POLICY_STANDARD_EDITOR_CONFIG_FILE_REGISTRY_PATH; } else if (EntitlementConstants.PolicyEditor.RBAC.equals(policyEditorType)) { path = EntitlementConstants.ENTITLEMENT_POLICY_RBAC_EDITOR_CONFIG_FILE_REGISTRY_PATH; } else if (EntitlementConstants.PolicyEditor.SET.equals(policyEditorType)) { path = EntitlementConstants.ENTITLEMENT_POLICY_SET_EDITOR_CONFIG_FILE_REGISTRY_PATH; } else { //default path = EntitlementConstants.ENTITLEMENT_POLICY_BASIC_EDITOR_CONFIG_FILE_REGISTRY_PATH; } registry.put(path, resource); } catch (RegistryException e) { throw new PolicyEditorException("Error while persisting policy editor config"); } }
resource.setContent(writer.toString()); resource.setMediaType(MobilePluginConstants.MEDIA_TYPE_XML); MobileDeviceManagementUtil.putRegistryResource(resourcePath, resource); status = true;
/** * Add a trusted service to which tokens are issued with given claims. * * @param realmName - this uniquely represents the trusted service * @param claimDialect - claim dialects uris * @param claims - these comma separated default claims are issued when a request is done from the given realm * @throws Exception - if fails to add trusted service */ public void addTrustedService(String realmName, String claimDialect, String claims) throws Exception { realmName = replaceSlashWithConstantString(realmName); try { Registry registry = IdentityPassiveSTSServiceComponent.getConfigSystemRegistry(); String trustedServicePath = registryTrustedServicePath + realmName; // if registry collection does not exists, create if (!registry.resourceExists(trustedServicePath)) { Resource resource = registry.newResource(); resource.addProperty(REALM_NAME, realmName); resource.addProperty(CLAIMS, claims); resource.addProperty(CLAIM_DIALECT, claimDialect); registry.put(trustedServicePath, resource); } else { throw new Exception(realmName + " already added. Please remove first and add again."); } } catch (RegistryException e) { String error = "Error occurred when adding a trusted service due to error in accessing registry."; throw new Exception(error, e); } }
org.wso2.carbon.registry.api.Resource resource = registry. get(PDPConstants.ENTITLEMENT_POLICY_PUBLISHER_VERIFICATION + verificationCode); List<String> list = resource.getPropertyValues("subscriberIds"); if (list != null) { subscriberIds = list.toArray(new String[list.size()]); list = resource.getPropertyValues("policyIds"); if (list != null) { policyIds = list.toArray(new String[list.size()]); String version = resource.getProperty("version"); if (version != null) { this.version = version; String action = resource.getProperty("action"); if (action != null) { this.action = action; String order = resource.getProperty("order"); if (order != null) { this.order = Integer.parseInt(order);