org.wso2.carbon.registry.core.service.RegistryService Java Examples
The following examples show how to use
org.wso2.carbon.registry.core.service.RegistryService.
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: JWTClientUtil.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
/** * Get the jwt details from the registry for tenants. * * @param tenantId for accesing tenant space. * @return the config for tenant * @throws RegistryException */ public static void addJWTConfigResourceToRegistry(int tenantId, String content) throws RegistryException { try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true); RegistryService registryService = JWTClientExtensionDataHolder.getInstance().getRegistryService(); if (registryService != null) { Registry registry = registryService.getConfigSystemRegistry(tenantId); JWTClientUtil.loadTenantRegistry(tenantId); if (!registry.resourceExists(TENANT_JWT_CONFIG_LOCATION)) { Resource resource = registry.newResource(); resource.setContent(content.getBytes()); registry.put(TENANT_JWT_CONFIG_LOCATION, resource); } } } finally { PrivilegedCarbonContext.endTenantFlow(); } }
Example #2
Source File: AbstractAPIManagerTestCase.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Before public void init() { System.setProperty(CARBON_HOME, ""); privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class); PowerMockito.mockStatic(PrivilegedCarbonContext.class); PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext); PowerMockito.mockStatic(GovernanceUtils.class); paginationContext = Mockito.mock(PaginationContext.class); PowerMockito.mockStatic(PaginationContext.class); PowerMockito.when(PaginationContext.getInstance()).thenReturn(paginationContext); apiMgtDAO = Mockito.mock(ApiMgtDAO.class); registry = Mockito.mock(Registry.class); genericArtifactManager = Mockito.mock(GenericArtifactManager.class); registryService = Mockito.mock(RegistryService.class); tenantManager = Mockito.mock(TenantManager.class); graphQLSchemaDefinition = Mockito.mock(GraphQLSchemaDefinition.class); keyManager = Mockito.mock(KeyManager.class); PowerMockito.mockStatic(KeyManagerHolder.class); PowerMockito.when(KeyManagerHolder.getKeyManagerInstance("carbon.super")).thenReturn(keyManager); }
Example #3
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testGetOAuthConfigurationFromTenantRegistry () throws Exception{ final int tenantId = -1234; final String property = "AuthorizationHeader"; ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry userRegistry = Mockito.mock(UserRegistry.class); Resource resource = Mockito.mock(Resource.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getConfigSystemRegistry(tenantId)).thenReturn(userRegistry); Mockito.when(userRegistry.resourceExists(APIConstants.API_TENANT_CONF_LOCATION)).thenReturn(true); Mockito.when(userRegistry.get(APIConstants.API_TENANT_CONF_LOCATION)).thenReturn(resource); File siteConfFile = new File(Thread.currentThread().getContextClassLoader(). getResource("tenant-conf.json").getFile()); String tenantConfValue = FileUtils.readFileToString(siteConfFile); Mockito.when(resource.getContent()).thenReturn(tenantConfValue.getBytes()); JSONParser parser = new JSONParser(); JSONObject json = (JSONObject) parser.parse(tenantConfValue); String authorizationHeader = (String)json.get(property); String authHeader = getOAuthConfigurationFromTenantRegistry(tenantId,property); Assert.assertEquals(authorizationHeader, authHeader); }
Example #4
Source File: ClaimManagementServiceComponent.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@Reference( name = "registry.service", service = RegistryService.class, cardinality = ReferenceCardinality.MANDATORY, policy = ReferencePolicy.DYNAMIC, unbind = "unsetRegistryService") protected void setRegistryService(RegistryService registryService) { try { ClaimManagementServiceDataHolder.getInstance().setRegistryService(registryService); } catch (Throwable e) { log.error("Failed to get a reference to the Registry Service.", e); } if (log.isDebugEnabled()) { log.debug("RegistryService set in Claim Management bundle"); } }
Example #5
Source File: ApplicationThrottleControllerTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Before public void init() throws RegistryException, UserStoreException { System.setProperty(CARBON_HOME, ""); tenantDomain = "carbon.super"; applicationId = "1"; tenantID = tenantID; messageContext = TestUtils.getMessageContextWithAuthContext("api", "v1"); registryServiceHolder = Mockito.mock(RegistryServiceHolder.class); registryService = Mockito.mock(RegistryService.class); registry = Mockito.mock(UserRegistry.class); realmService = Mockito.mock(RealmService.class); tenantManager = Mockito.mock(TenantManager.class); carbonContext = Mockito.mock(PrivilegedCarbonContext.class); throttleDataHolder = Mockito.mock(ThrottleDataHolder.class); throttlingPolicyResource = Mockito.mock(Resource.class); throttleContext = Mockito.mock(ThrottleContext.class); PowerMockito.mockStatic(PrivilegedCarbonContext.class); PowerMockito.mockStatic(RegistryServiceHolder.class); PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(carbonContext); PowerMockito.when(RegistryServiceHolder.getInstance()).thenReturn(registryServiceHolder); PowerMockito.when(registryServiceHolder.getRegistryService()).thenReturn(registryService); PowerMockito.when(carbonContext.getOSGiService(RealmService.class, null)).thenReturn(realmService); PowerMockito.when(realmService.getTenantManager()).thenReturn(tenantManager); }
Example #6
Source File: TestUtils.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public static ServiceReferenceHolder mockRegistryAndUserRealm(int tenantId) throws UserStoreException, RegistryException { ServiceReferenceHolder sh = getServiceReferenceHolder(); RealmService realmService = Mockito.mock(RealmService.class); TenantManager tm = Mockito.mock(TenantManager.class); PowerMockito.when(sh.getRealmService()).thenReturn(realmService); PowerMockito.when(realmService.getTenantManager()).thenReturn(tm); RegistryService registryService = Mockito.mock(RegistryService.class); PowerMockito.when(sh.getRegistryService()).thenReturn(registryService); UserRegistry userReg = Mockito.mock(UserRegistry.class); PowerMockito.when(registryService.getGovernanceUserRegistry()).thenReturn(userReg); UserRegistry systemReg = Mockito.mock(UserRegistry.class); PowerMockito.when(registryService.getConfigSystemRegistry()).thenReturn(systemReg); UserRealm userRealm = Mockito.mock(UserRealm.class); UserRealm bootstrapRealm = Mockito.mock(UserRealm.class); PowerMockito.when(systemReg.getUserRealm()).thenReturn(userRealm); PowerMockito.doNothing().when(ServiceReferenceHolder.class); ServiceReferenceHolder.setUserRealm(userRealm); org.wso2.carbon.user.api.UserRealm userR = Mockito.mock(org.wso2.carbon.user.api.UserRealm.class); PowerMockito.when(realmService.getTenantUserRealm(-1234)).thenReturn(userR); AuthorizationManager authManager = Mockito.mock(AuthorizationManager.class); PowerMockito.when(userR.getAuthorizationManager()).thenReturn(authManager); PowerMockito.when(realmService.getBootstrapRealm()).thenReturn(bootstrapRealm); ServiceReferenceHolder.setUserRealm(bootstrapRealm); PowerMockito.when(tm.getTenantId(Matchers.anyString())).thenReturn(tenantId); return sh; }
Example #7
Source File: APIManagerComponentAddTierPolicyTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Before public void setup() throws IOException { System.setProperty("carbon.home", ""); PowerMockito.mockStatic(ServiceReferenceHolder.class); PowerMockito.mockStatic(CarbonContext.class); serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); componentContext = Mockito.mock(ComponentContext.class); registryService = Mockito.mock(RegistryService.class); userRegistry = Mockito.mock(UserRegistry.class); resource = Mockito.mock(Resource.class); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); PowerMockito.when(CarbonContext.getThreadLocalCarbonContext()).thenThrow(IndexOutOfBoundsException.class); }
Example #8
Source File: APIMRegistryServiceImplTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void getConfigRegistryResourceContentTestCase() throws UserStoreException, RegistryException, APIManagementException{ APIMRegistryServiceImpl apimRegistryService = new APIMRegistryServiceImplWrapper(); System.setProperty(CARBON_HOME, ""); PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class); PowerMockito.mockStatic(PrivilegedCarbonContext.class); PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext); Mockito.when(privilegedCarbonContext.getTenantDomain()).thenReturn(TENANT_DOMAIN); Mockito.when(privilegedCarbonContext.getTenantId()).thenReturn(TENANT_ID); RealmService realmService = Mockito.mock(RealmService.class); TenantManager tenantManager = Mockito.mock(TenantManager.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); Resource resource = Mockito.mock(Resource.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(tenantManager.getTenantId(TENANT_DOMAIN)).thenReturn(TENANT_ID); Mockito.when(registryService.getConfigSystemRegistry(TENANT_ID)).thenReturn(registry); PowerMockito.mockStatic(APIUtil.class); APIUtil.loadTenantConf(TENANT_ID); Mockito.when(registry.resourceExists("testLocation")).thenReturn(true); Mockito.when(registry.get("testLocation")).thenReturn(resource); Assert.assertEquals("testContent", apimRegistryService. getConfigRegistryResourceContent("test.foo", "testLocation")); }
Example #9
Source File: EntitlementServiceComponent.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
/** * sets registry service * * @param registryService <code>RegistryService</code> */ @Reference( name = "registry.service", service = RegistryService.class, cardinality = ReferenceCardinality.MANDATORY, policy = ReferencePolicy.DYNAMIC, unbind = "unsetRegistryService" ) protected void setRegistryService(RegistryService registryService) { if (log.isDebugEnabled()) { log.debug("RegistryService set in Entitlement bundle"); } EntitlementServiceComponent.registryService = registryService; }
Example #10
Source File: MockIaasServiceComponent.java From attic-stratos with Apache License 2.0 | 5 votes |
protected void setRegistryService(RegistryService registryService) { if (log.isDebugEnabled()) { log.debug("Setting the Registry Service"); } try { UserRegistry registry = registryService.getGovernanceSystemRegistry(); ServiceReferenceHolder.getInstance().setRegistry(registry); } catch (RegistryException e) { String msg = "Failed when retrieving Governance System Registry."; log.error(msg, e); } }
Example #11
Source File: EntitlementServiceComponent.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
/** * un-sets registry service * * @param registryService <code>RegistryService</code> */ protected void unsetRegistryService(RegistryService registryService) { if (log.isDebugEnabled()) { log.debug("RegistryService unset in Entitlement bundle"); } EntitlementServiceComponent.registryService = null; }
Example #12
Source File: OIDCAuthenticatorUIDSComponent.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Reference( name = "registry.service", service = org.wso2.carbon.registry.core.service.RegistryService.class, cardinality = ReferenceCardinality.MANDATORY, policy = ReferencePolicy.DYNAMIC, unbind = "unsetRegistryService") protected void setRegistryService(RegistryService registryService) { OIDCAuthFEDataHolder.getInstance().setRegistryService(registryService); }
Example #13
Source File: APIManagerComponentAddRxtConfigsTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Before public void setup() throws IOException { PowerMockito.mockStatic(ServiceReferenceHolder.class); PowerMockito.mockStatic(FileUtil.class); serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); componentContext = Mockito.mock(ComponentContext.class); registryService = Mockito.mock(RegistryService.class); userRegistry = Mockito.mock(UserRegistry.class); resource = Mockito.mock(Resource.class); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); }
Example #14
Source File: STSServiceComponent.java From carbon-identity with Apache License 2.0 | 5 votes |
protected void setRegistryService(RegistryService registryService) { if (log.isDebugEnabled()) { log.debug("RegistryService set in Carbon STS bundle"); } try { STSServiceDataHolder.getInstance().setRegistryService(registryService); } catch (Throwable e) { log.error("Failed to get a reference to the Registry", e); } }
Example #15
Source File: OutboundProvisioningManager.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * @param userName * @param tenantDomain * @return * @throws CarbonException * @throws UserStoreException */ private List<String> getUserRoles(String userName, String tenantDomain) throws CarbonException, UserStoreException { RegistryService registryService = IdentityProvisionServiceComponent.getRegistryService(); RealmService realmService = IdentityProvisionServiceComponent.getRealmService(); UserRealm realm = AnonymousSessionUtil.getRealmByTenantDomain(registryService, realmService, tenantDomain); UserStoreManager userstore = null; userstore = realm.getUserStoreManager(); String[] newRoles = userstore.getRoleListOfUser(userName); return Arrays.asList(newRoles); }
Example #16
Source File: TestUtils.java From carbon-device-mgt with Apache License 2.0 | 5 votes |
public static RegistryService getRegistryService(Class clazz) throws RegistryException { RealmService realmService = new InMemoryRealmService(); RegistryDataHolder.getInstance().setRealmService(realmService); DeviceManagementDataHolder.getInstance().setRealmService(realmService); InputStream is = clazz.getClassLoader().getResourceAsStream("carbon-home/repository/conf/registry.xml"); RegistryContext context = RegistryContext.getBaseInstance(is, realmService); context.setSetup(true); return context.getEmbeddedRegistryService(); }
Example #17
Source File: SecurityMgtServiceComponent.java From carbon-identity with Apache License 2.0 | 5 votes |
protected void setRegistryService(RegistryService registryService) { if (log.isDebugEnabled()) { log.debug("Setting the RegistryService"); } this.registryService = registryService; SecurityServiceHolder.setRegistryService(registryService); }
Example #18
Source File: MigrationServiceComponent.java From product-ei with Apache License 2.0 | 5 votes |
/** * Method to set registry service. * * @param registryService service to get tenant data. */ protected void setRegistryService(RegistryService registryService) { if (log.isDebugEnabled()) { log.debug("Setting RegistryService to WSO2 EI Config component"); } MigrationServiceDataHolder.setRegistryService(registryService); }
Example #19
Source File: ApplicationManagementServiceComponent.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
@Reference( name = "registry.service", service = RegistryService.class, cardinality = ReferenceCardinality.MANDATORY, policy = ReferencePolicy.DYNAMIC, unbind = "unsetRegistryService" ) protected void setRegistryService(RegistryService registryService) { if (log.isDebugEnabled()) { log.debug("RegistryService set in Identity ApplicationManagementComponent bundle"); } ApplicationManagementServiceComponentHolder.getInstance().setRegistryService(registryService); }
Example #20
Source File: OutboundProvisioningManager.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * @param userName * @param tenantDomain * @return * @throws CarbonException * @throws UserStoreException */ private Map<String, String> getUserClaims(String userName, String tenantDomain) throws CarbonException, UserStoreException { Map<String, String> inboundAttributes = new HashMap<>(); RegistryService registryService = IdentityProvisionServiceComponent.getRegistryService(); RealmService realmService = IdentityProvisionServiceComponent.getRealmService(); UserRealm realm = AnonymousSessionUtil.getRealmByTenantDomain(registryService, realmService, tenantDomain); UserStoreManager userstore = null; userstore = realm.getUserStoreManager(); Claim[] claimArray = null; try { claimArray = userstore.getUserClaimValues(userName, null); } catch (UserStoreException e) { if (e.getMessage().contains("UserNotFound")) { if (log.isDebugEnabled()) { log.debug("User " + userName + " not found in user store"); } } else { throw e; } } if (claimArray != null) { for (Claim claim : claimArray) { inboundAttributes.put(claim.getClaimUri(), claim.getValue()); } } return inboundAttributes; }
Example #21
Source File: EIMigrationServiceComponent.java From product-ei with Apache License 2.0 | 5 votes |
@Reference( name = "registry.service", service = org.wso2.carbon.registry.core.service.RegistryService.class, cardinality = ReferenceCardinality.MANDATORY, policy = ReferencePolicy.DYNAMIC, unbind = "unsetRegistryService") protected void setRegistryService(RegistryService registryService) { EIMigrationServiceDataHolder.setRegistryService(registryService); }
Example #22
Source File: BaseAPIPublisherTest.java From carbon-device-mgt with Apache License 2.0 | 5 votes |
private void initServices() throws NoSuchFieldException, IllegalAccessException, JWTClientException, UserStoreException, RegistryException { IntegrationClientService integrationClientService = Mockito.mock(IntegrationClientServiceImpl.class, Mockito.CALLS_REAL_METHODS); APIPublisherDataHolder.getInstance().setIntegrationClientService(integrationClientService); PublisherClient publisherClient = Mockito.mock(PublisherClient.class, Mockito.CALLS_REAL_METHODS); doReturn(publisherClient).when(integrationClientService).getPublisherClient(); APIIndividualApi api = new MockAPIIndividualApi(); Field field = PublisherClient.class.getDeclaredField("api"); field.setAccessible(true); field.set(publisherClient, api); AccessTokenInfo accessTokenInfo = new AccessTokenInfo(); final String REQUIRED_SCOPE = "apim:api_create apim:api_view apim:api_publish apim:subscribe apim:tier_view apim:tier_manage " + "apim:subscription_view apim:subscription_block"; accessTokenInfo.setScopes(REQUIRED_SCOPE); JWTClientManagerService jwtClientManagerService = Mockito.mock(JWTClientManagerServiceImpl.class, Mockito.CALLS_REAL_METHODS); JWTClient jwtClient = Mockito.mock(JWTClient.class, Mockito.CALLS_REAL_METHODS); doReturn(accessTokenInfo).when(jwtClient).getAccessToken(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); doReturn(jwtClient).when(jwtClientManagerService).getJWTClient(); APIIntegrationClientDataHolder.getInstance().setJwtClientManagerService(jwtClientManagerService); RegistryService registryService = this.getRegistryService(); OSGiDataHolder.getInstance().setRegistryService(registryService); JWTClientExtensionDataHolder.getInstance().setRegistryService(registryService); }
Example #23
Source File: CaptchaMgtServiceComponent.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
@Reference( name = "registry.service", service = org.wso2.carbon.registry.core.service.RegistryService.class, cardinality = ReferenceCardinality.MANDATORY, policy = ReferencePolicy.DYNAMIC, unbind = "unsetRegistryService" ) protected void setRegistryService(RegistryService registryService) { this.registryService = registryService; }
Example #24
Source File: DeploymentSynchronizerComponent.java From carbon-commons with Apache License 2.0 | 5 votes |
protected void unsetRegistryService(RegistryService service) { if (log.isDebugEnabled()) { log.debug("Deployment synchronizer component unbound from the registry service"); } ServiceReferenceHolder.setRegistryService(null); }
Example #25
Source File: IdentityMgtServiceComponent.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
@Reference( name = "registry.service", service = RegistryService.class, cardinality = ReferenceCardinality.MANDATORY, policy = ReferencePolicy.DYNAMIC, unbind = "unsetRegistryService" ) protected void setRegistryService(RegistryService registryService) { log.debug("Setting the Registry Service"); IdentityMgtServiceComponent.registryService = registryService; }
Example #26
Source File: RegistryConfigWriter.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
@Override public void write(int tenantId, Properties props, String resourcePath) throws IdentityMgtConfigException { if(log.isDebugEnabled()) { log.debug("Writing data to registry path : " + resourcePath); } RegistryService registry = IdentityMgtServiceComponent.getRegistryService(); try { UserRegistry userReg = registry.getConfigSystemRegistry(tenantId); Resource resource = userReg.newResource(); Set<String> names = props.stringPropertyNames(); // Only key value pairs exists and no multiple values exists a key. for (String keyName : names) { List<String> value = new ArrayList<String>(); String valueStr = props.getProperty(keyName); if(log.isDebugEnabled()) { log.debug("Write key : " + keyName + " value : " + value); } // This is done due to casting to List in JDBCRegistryDao value.add(valueStr); resource.setProperty(keyName, value); } userReg.put(resourcePath, resource); } catch (RegistryException e) { throw new IdentityMgtConfigException( "Error occurred while writing data to registry path : " + resourcePath, e); } }
Example #27
Source File: APIKeyMgtServiceComponent.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Reference( name = "registry.service", service = org.wso2.carbon.registry.core.service.RegistryService.class, cardinality = ReferenceCardinality.MANDATORY, policy = ReferencePolicy.DYNAMIC, unbind = "unsetRegistryService") protected void setRegistryService(RegistryService registryService) { APIKeyMgtDataHolder.setRegistryService(registryService); if (log.isDebugEnabled()) { log.debug("Registry Service is set in the API KeyMgt bundle."); } }
Example #28
Source File: ReportingComponent.java From carbon-commons with Apache License 2.0 | 5 votes |
public static RegistryService getRegistryService() throws RegistryException { if (registryServiceInstance == null) { throw new RegistryException("Registry Service instance null"); } return registryServiceInstance; }
Example #29
Source File: APIPublisherDataHolder.java From carbon-device-mgt with Apache License 2.0 | 4 votes |
public void setRegistryService(RegistryService registryService) { this.registryService = registryService; }
Example #30
Source File: UMRemoteServicesDSComponent.java From carbon-identity with Apache License 2.0 | 4 votes |
protected void unsetRegistryService(RegistryService registryService) { UMRemoteServicesDataHolder.getInstance().setRegistryService(null); }