org.wso2.carbon.base.ServerConfiguration Java Examples
The following examples show how to use
org.wso2.carbon.base.ServerConfiguration.
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: SecurityMgtServiceComponent.java From carbon-identity with Apache License 2.0 | 6 votes |
protected void activate(ComponentContext ctxt) { try { ConfigurationContext mainConfigCtx = configContextService.getServerConfigContext(); AxisConfiguration mainAxisConfig = mainConfigCtx.getAxisConfiguration(); BundleContext bundleCtx = ctxt.getBundleContext(); String enablePoxSecurity = ServerConfiguration.getInstance() .getFirstProperty("EnablePoxSecurity"); if (enablePoxSecurity == null || "true".equals(enablePoxSecurity)) { mainAxisConfig.engageModule(POX_SECURITY_MODULE); } else { log.info("POX Security Disabled"); } bundleCtx.registerService(SecurityConfigAdmin.class.getName(), new SecurityConfigAdmin(mainAxisConfig, registryService.getConfigSystemRegistry(), null), null); bundleCtx.registerService(Axis2ConfigurationContextObserver.class.getName(), new SecurityAxis2ConfigurationContextObserver(), null); log.debug("Security Mgt bundle is activated"); } catch (Throwable e) { log.error("Failed to activate SecurityMgtServiceComponent", e); } }
Example #2
Source File: DataPublisherUtil.java From carbon-apimgt with Apache License 2.0 | 6 votes |
public static String getHostAddress() { if (hostAddress != null) { return hostAddress; } hostAddress = ServerConfiguration.getInstance().getFirstProperty(HOST_NAME); if(null == hostAddress){ if (getLocalAddress() != null) { hostAddress = getLocalAddress().getHostName(); } if (hostAddress == null) { hostAddress = UNKNOWN_HOST; } return hostAddress; }else { return hostAddress; } }
Example #3
Source File: WorkflowMgtServiceComponent.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@Activate protected void activate(ComponentContext context) { BundleContext bundleContext = context.getBundleContext(); WorkflowManagementService workflowService = new WorkflowManagementServiceImpl(); bundleContext.registerService(WorkflowManagementService.class, workflowService, null); WorkflowServiceDataHolder.getInstance().setWorkflowService(workflowService); WorkflowServiceDataHolder.getInstance().setBundleContext(bundleContext); ServiceRegistration serviceRegistration = context.getBundleContext().registerService(WorkflowListener.class.getName(), new WorkflowAuditLogger(), null); context.getBundleContext().registerService(WorkflowExecutorManagerListener.class.getName(), new WorkflowExecutorAuditLogger(), null); if (serviceRegistration != null) { if (log.isDebugEnabled()) { log.debug("WorkflowAuditLogger registered."); } } else { log.error("Workflow Audit Logger could not be registered."); } if (System.getProperty(WFConstant.KEYSTORE_SYSTEM_PROPERTY_ID) == null) { System.setProperty(WFConstant.KEYSTORE_SYSTEM_PROPERTY_ID, ServerConfiguration.getInstance().getFirstProperty(WFConstant.KEYSTORE_CARBON_CONFIG_PATH)); } if (System.getProperty(WFConstant.KEYSTORE_PASSWORD_SYSTEM_PROPERTY_ID) == null) { System.setProperty(WFConstant.KEYSTORE_PASSWORD_SYSTEM_PROPERTY_ID, ServerConfiguration.getInstance().getFirstProperty(WFConstant.KEYSTORE_PASSWORD_CARBON_CONFIG_PATH)); } }
Example #4
Source File: Utils.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
private static SSLSocketFactory getTrustedSSLSocketFactory() { try { String keyStorePassword = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Password"); String keyStoreLocation = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Location"); String trustStorePassword = ServerConfiguration.getInstance().getFirstProperty( "Security.TrustStore.Password"); String trustStoreLocation = ServerConfiguration.getInstance().getFirstProperty( "Security.TrustStore.Location"); KeyStore keyStore = loadKeyStore(keyStoreLocation,keyStorePassword,KEY_STORE_TYPE); KeyStore trustStore = loadTrustStore(trustStoreLocation,trustStorePassword); return initSSLConnection(keyStore,keyStorePassword,trustStore); } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException |CertificateException | IOException | UnrecoverableKeyException e) { log.error("Error while creating the SSL socket factory due to "+e.getMessage(),e); return null; } }
Example #5
Source File: DefaultServiceURLBuilderTest.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@Test(dataProvider = "getRelativeInternalURLData") public void testGetRelativeInternalURL(String protocol, String hostName, int port, String proxyContextPath, String tenantNameFromContext, boolean enableTenantURLSupport, String expected, String urlPath) { when(CarbonUtils.getManagementTransport()).thenReturn(protocol); when(ServerConfiguration.getInstance().getFirstProperty(IdentityCoreConstants.HOST_NAME)).thenReturn(hostName); when(CarbonUtils.getTransportProxyPort(mockAxisConfiguration, protocol)).thenReturn(port); when(ServerConfiguration.getInstance().getFirstProperty(IdentityCoreConstants .PROXY_CONTEXT_PATH)).thenReturn(proxyContextPath); when(IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(enableTenantURLSupport); when(IdentityTenantUtil.getTenantDomainFromContext()).thenReturn(tenantNameFromContext); when(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()).thenReturn("carbon.super"); String relativeInternalUrl = null; try { relativeInternalUrl = ServiceURLBuilder.create().addPath(urlPath).build().getRelativeInternalURL(); } catch (URLBuilderException e) { //Mock behaviour, hence ignored } assertEquals(relativeInternalUrl, expected); }
Example #6
Source File: DefaultServiceURLBuilderTest.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@Test(dataProvider = "getRelativePublicURLData") public void testGetRelativePublicURL(String protocol, String hostName, int port, String proxyContextPath, String tenantNameFromContext, boolean enableTenantURLSupport, String expected, String urlPath) { when(CarbonUtils.getManagementTransport()).thenReturn(protocol); when(ServerConfiguration.getInstance().getFirstProperty(IdentityCoreConstants.HOST_NAME)).thenReturn(hostName); when(CarbonUtils.getTransportProxyPort(mockAxisConfiguration, protocol)).thenReturn(port); when(ServerConfiguration.getInstance().getFirstProperty(IdentityCoreConstants .PROXY_CONTEXT_PATH)).thenReturn(proxyContextPath); when(IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(enableTenantURLSupport); when(IdentityTenantUtil.getTenantDomainFromContext()).thenReturn(tenantNameFromContext); when(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()).thenReturn("carbon.super"); String relativePublicUrl = null; try { relativePublicUrl = ServiceURLBuilder.create().addPath(urlPath).build().getRelativePublicURL(); } catch (URLBuilderException e) { //Mock behaviour, hence ignored } assertEquals(relativePublicUrl, expected); }
Example #7
Source File: APIStoreHostObjectTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testGetHTTPsURL() throws APIManagementException { Context cx = Mockito.mock(Context.class); Scriptable thisObj = Mockito.mock(Scriptable.class); Function funObj = Mockito.mock(Function.class); Object[] args = new Object[1]; PowerMockito.mockStatic(CarbonUtils.class); PowerMockito.mockStatic(HostObjectUtils.class); ServerConfiguration serverConfiguration = Mockito.mock(ServerConfiguration.class); PowerMockito.when(CarbonUtils.getServerConfiguration()).thenReturn(serverConfiguration); PowerMockito.when(HostObjectUtils.getBackendPort("https")).thenReturn("9443"); //when hostName is not set and when hostName is set in system property System.setProperty("carbon.local.ip", "127.0.0.1"); Assert.assertEquals("https://127.0.0.1:9443", APIStoreHostObject.jsFunction_getHTTPsURL(cx, thisObj, args, funObj)); //when hostName is not set and when hostName is set in carbon.xml Mockito.when(serverConfiguration.getFirstProperty("HostName")).thenReturn("localhost"); Assert.assertEquals("https://localhost:9443", APIStoreHostObject.jsFunction_getHTTPsURL(cx, thisObj, args, funObj)); //when hostName is set to a valid host args[0] = "https://localhost:9443/store/"; Assert.assertEquals("https://localhost:9443", APIStoreHostObject.jsFunction_getHTTPsURL(cx, thisObj, args, funObj)); }
Example #8
Source File: IdentityApplicationManagementServiceClient.java From attic-stratos with Apache License 2.0 | 6 votes |
public IdentityApplicationManagementServiceClient(String epr) throws AxisFault { XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration(); int autosclaerSocketTimeout = conf.getInt("autoscaler.identity.clientTimeout", 180000); try { ServerConfiguration serverConfig = CarbonUtils.getServerConfiguration(); String trustStorePath = serverConfig.getFirstProperty("Security.TrustStore.Location"); String trustStorePassword = serverConfig.getFirstProperty("Security.TrustStore.Password"); String type = serverConfig.getFirstProperty("Security.TrustStore.Type"); System.setProperty("javax.net.ssl.trustStore", trustStorePath); System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword); System.setProperty("javax.net.ssl.trustStoreType", type); stub = new IdentityApplicationManagementServiceStub(epr); stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, autosclaerSocketTimeout); stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, autosclaerSocketTimeout); String username = conf.getString("autoscaler.identity.adminUser", "admin"); Utility.setAuthHeaders(stub._getServiceClient(), username); } catch (AxisFault axisFault) { String msg = "Failed to initiate identity service client. " + axisFault.getMessage(); log.error(msg, axisFault); throw new AxisFault(msg, axisFault); } }
Example #9
Source File: DefaultServiceURLBuilderTest.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@BeforeMethod public void setUp() throws Exception { mockStatic(CarbonUtils.class); mockStatic(ServerConfiguration.class); mockStatic(NetworkUtils.class); mockStatic(IdentityCoreServiceComponent.class); mockStatic(IdentityTenantUtil.class); mockStatic(PrivilegedCarbonContext.class); PrivilegedCarbonContext privilegedCarbonContext = mock(PrivilegedCarbonContext.class); when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext); when(ServerConfiguration.getInstance()).thenReturn(mockServerConfiguration); when(IdentityCoreServiceComponent.getConfigurationContextService()).thenReturn(mockConfigurationContextService); when(mockConfigurationContextService.getServerConfigContext()).thenReturn(mockConfigurationContext); when(mockConfigurationContext.getAxisConfiguration()).thenReturn(mockAxisConfiguration); try { when(NetworkUtils.getLocalHostname()).thenReturn("localhost"); } catch (SocketException e) { // Mock behaviour, hence ignored } System.setProperty(IdentityConstants.CarbonPlaceholders.CARBON_PORT_HTTP_PROPERTY, "9763"); System.setProperty(IdentityConstants.CarbonPlaceholders.CARBON_PORT_HTTPS_PROPERTY, "9443"); }
Example #10
Source File: TokenGenTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { PowerMockito.mockStatic(CarbonUtils.class); PowerMockito.mockStatic(SubscriptionDataHolder.class); ServerConfiguration serverConfiguration = Mockito.mock(ServerConfiguration.class); Mockito.when(serverConfiguration.getFirstProperty(APIConstants.PORT_OFFSET_CONFIG)).thenReturn("2"); PowerMockito.when(CarbonUtils.getServerConfiguration()).thenReturn(serverConfiguration); String dbConfigPath = System.getProperty("APIManagerDBConfigurationPath"); APIManagerConfiguration config = new APIManagerConfiguration(); config.load(dbConfigPath); ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService( new APIManagerConfigurationServiceImpl(config)); SubscriptionDataStore subscriptionDataStore = Mockito.mock(SubscriptionDataStore.class); SubscriptionDataHolder subscriptionDataHolder = Mockito.mock(SubscriptionDataHolder.class); PowerMockito.when(SubscriptionDataHolder.getInstance()).thenReturn(subscriptionDataHolder); PowerMockito.when(SubscriptionDataHolder.getInstance() .getTenantSubscriptionStore(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) .thenReturn(subscriptionDataStore); Application application = new Application(); application.setId(1); application.setName("app2"); application.setUUID(UUID.randomUUID().toString()); application.addAttribute("abc","cde"); Mockito.when(subscriptionDataStore.getApplicationById(1)).thenReturn(application); }
Example #11
Source File: DefaultServiceURLBuilder.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * Returns a ServiceURL with the protocol, hostname, port, proxy context path, a web context * root and the tenant domain (appended if required). * * @return {@link ServiceURL}. * @throws URLBuilderException If error occurred while constructing the URL. */ @Override public ServiceURL build() throws URLBuilderException { String protocol = fetchProtocol(); String proxyHostName = fetchProxyHostName(); String internalHostName = fetchInternalHostName(); int port = fetchPort(); String tenantDomain = resolveTenantDomain(); String proxyContextPath = ServerConfiguration.getInstance().getFirstProperty(PROXY_CONTEXT_PATH); String resolvedFragment = buildFragment(fragment, fragmentParams); String urlPath = getResolvedUrlPath(tenantDomain); return new ServiceURLImpl(protocol, proxyHostName, internalHostName, port, tenantDomain, proxyContextPath, urlPath, parameters, resolvedFragment); }
Example #12
Source File: KeyStoreAdminTest.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@Test public void testGetPaginatedKeystoreInfo() throws Exception { mockStatic(ServerConfiguration.class); when(ServerConfiguration.getInstance()).thenReturn(serverConfiguration); mockStatic(KeyStoreManager.class); when(KeyStoreManager.getInstance(anyInt())).thenReturn(keyStoreManager); when(keyStoreManager.getKeyStore("wso2carbon.jks")).thenReturn(getKeyStoreFromFile("wso2carbon.jks", "wso2carbon")); when(serverConfiguration.getFirstProperty(SERVER_TRUSTSTORE_FILE)).thenReturn(createPath("wso2carbon.jks").toString()); when(serverConfiguration.getFirstProperty(SERVER_TRUSTSTORE_PASSWORD)).thenReturn("wso2carbon"); mockStatic(KeyStoreUtil.class); when(KeyStoreUtil.isPrimaryStore(any())).thenReturn(true); mockStatic(KeyStoreManager.class); when(KeyStoreManager.getInstance(tenantID)).thenReturn(keyStoreManager); when(keyStoreManager.getPrimaryKeyStore()).thenReturn(getKeyStoreFromFile("wso2carbon.jks", "wso2carbon")); keyStoreAdmin = new KeyStoreAdmin(tenantID, registry); PaginatedKeyStoreData result = keyStoreAdmin.getPaginatedKeystoreInfo("wso2carbon.jks", 10); int actualKeysNo = findCertDataSetSize(result.getPaginatedKeyData().getCertDataSet()); assertEquals(actualKeysNo, 3, "Incorrect key numbers"); }
Example #13
Source File: KeyStoreAdmin.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
public Key getPrivateKey(String alias, boolean isSuperTenant) throws SecurityConfigException { KeyStoreData[] keystores = getKeyStores(isSuperTenant); KeyStore keyStore = null; String privateKeyPassowrd = null; try { for (int i = 0; i < keystores.length; i++) { if (KeyStoreUtil.isPrimaryStore(keystores[i].getKeyStoreName())) { KeyStoreManager keyMan = KeyStoreManager.getInstance(tenantId); keyStore = keyMan.getPrimaryKeyStore(); ServerConfiguration serverConfig = ServerConfiguration.getInstance(); privateKeyPassowrd = serverConfig .getFirstProperty(RegistryResources.SecurityManagement.SERVER_PRIVATE_KEY_PASSWORD); return keyStore.getKey(alias, privateKeyPassowrd.toCharArray()); } } } catch (Exception e) { String msg = "Error has encounted while loading the key for the given alias " + alias; log.error(msg, e); throw new SecurityConfigException(msg); } return null; }
Example #14
Source File: CarbonBasedTestListener.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
private void createKeyStore(Class realClass, WithKeyStore withKeyStore) { try { RegistryService registryService = createRegistryService(realClass, withKeyStore.tenantId(), withKeyStore.tenantDomain()); ServerConfiguration serverConfigurationService = ServerConfiguration.getInstance(); serverConfigurationService.init(realClass.getResourceAsStream("/repository/conf/carbon.xml")); KeyStoreManager keyStoreManager = KeyStoreManager.getInstance(withKeyStore.tenantId(), serverConfigurationService, registryService); if (!Proxy.isProxyClass(keyStoreManager.getClass()) && !keyStoreManager.getClass().getName().contains("EnhancerByMockitoWithCGLIB") ) { KeyStore keyStore = ReadCertStoreSampleUtil.createKeyStore(getClass()); org.wso2.carbon.identity.testutil.Whitebox.setInternalState(keyStoreManager, "primaryKeyStore", keyStore); org.wso2.carbon.identity.testutil.Whitebox.setInternalState(keyStoreManager, "registryKeyStore", keyStore); } CarbonCoreDataHolder.getInstance().setRegistryService(registryService); CarbonCoreDataHolder.getInstance().setServerConfigurationService(serverConfigurationService); } catch (Exception e) { throw new TestCreationException( "Unhandled error while reading cert for test class: " + realClass.getName(), e); } }
Example #15
Source File: CustomJschConfigSessionFactory.java From attic-stratos with Apache License 2.0 | 6 votes |
@Override protected JSch createDefaultJSch(FS fs) throws JSchException { JSch def = super.createDefaultJSch(fs); String keyName = ServerConfiguration.getInstance(). getFirstProperty(GitDeploymentSynchronizerConstants.SSH_PRIVATE_KEY_NAME); String keyPath = ServerConfiguration.getInstance(). getFirstProperty(GitDeploymentSynchronizerConstants.SSH_PRIVATE_KEY_PATH); if (keyName == null || keyName.isEmpty()) keyName = GitDeploymentSynchronizerConstants.SSH_KEY; if (keyPath == null || keyPath.isEmpty()) keyPath = System.getProperty("user.home") + "/" + GitDeploymentSynchronizerConstants.SSH_KEY_DIRECTORY; if (keyPath.endsWith("/")) def.addIdentity(keyPath + keyName); else def.addIdentity(keyPath + "/" + keyName); return def; }
Example #16
Source File: SignKeyDataHolder.java From carbon-identity with Apache License 2.0 | 6 votes |
public SignKeyDataHolder() throws Exception { try { String keyAlias = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.KeyAlias"); KeyStoreManager keyMan = KeyStoreManager.getInstance(MultitenantConstants.SUPER_TENANT_ID); Certificate[] certificates = keyMan.getPrimaryKeyStore().getCertificateChain(keyAlias); issuerPK = keyMan.getDefaultPrivateKey(); issuerCerts = new X509Certificate[certificates.length]; int i = 0; for (Certificate certificate : certificates) { issuerCerts[i++] = (X509Certificate) certificate; } signatureAlgorithm = XMLSignature.ALGO_ID_SIGNATURE_RSA; String pubKeyAlgo = issuerCerts[0].getPublicKey().getAlgorithm(); if (pubKeyAlgo.equalsIgnoreCase("DSA")) { signatureAlgorithm = XMLSignature.ALGO_ID_SIGNATURE_DSA; } } catch (Exception e) { throw new Exception("Error while reading the key", e); } }
Example #17
Source File: KeyStoreAdmin.java From carbon-identity with Apache License 2.0 | 6 votes |
public Key getPrivateKey(String alias, boolean isSuperTenant) throws SecurityConfigException { KeyStoreData[] keystores = getKeyStores(isSuperTenant); KeyStore keyStore = null; String privateKeyPassowrd = null; try { for (int i = 0; i < keystores.length; i++) { if (KeyStoreUtil.isPrimaryStore(keystores[i].getKeyStoreName())) { KeyStoreManager keyMan = KeyStoreManager.getInstance(tenantId); keyStore = keyMan.getPrimaryKeyStore(); ServerConfiguration serverConfig = ServerConfiguration.getInstance(); privateKeyPassowrd = serverConfig .getFirstProperty(RegistryResources.SecurityManagement.SERVER_PRIVATE_KEY_PASSWORD); return keyStore.getKey(alias, privateKeyPassowrd.toCharArray()); } } } catch (Exception e) { String msg = "Error has encounted while loading the key for the given alias " + alias; log.error(msg, e); throw new SecurityConfigException(msg); } return null; }
Example #18
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testCreateDocArtifactContent() throws GovernanceException, APIManagementException { API api = getUniqueAPI(); PowerMockito.mockStatic(CarbonUtils.class); ServerConfiguration serverConfiguration = Mockito.mock(ServerConfiguration.class); Mockito.when(serverConfiguration.getFirstProperty("WebContextRoot")).thenReturn("/abc").thenReturn("/"); PowerMockito.when(CarbonUtils.getServerConfiguration()).thenReturn(serverConfiguration); GenericArtifact genericArtifact = Mockito.mock(GenericArtifact.class); Documentation documentation = new Documentation(DocumentationType.HOWTO, "this is a doc"); documentation.setSourceType(Documentation.DocumentSourceType.FILE); documentation.setCreatedDate(new Date(System.currentTimeMillis())); documentation.setSummary("abcde"); documentation.setVisibility(Documentation.DocumentVisibility.API_LEVEL); documentation.setSourceUrl("/abcd/def"); documentation.setOtherTypeName("aa"); APIUtil.createDocArtifactContent(genericArtifact, api.getId(), documentation); documentation.setSourceType(Documentation.DocumentSourceType.INLINE); APIUtil.createDocArtifactContent(genericArtifact, api.getId(), documentation); documentation.setSourceType(Documentation.DocumentSourceType.URL); APIUtil.createDocArtifactContent(genericArtifact, api.getId(), documentation); try { documentation.setSourceType(Documentation.DocumentSourceType.URL); Mockito.doThrow(GovernanceException.class).when(genericArtifact).setAttribute(APIConstants .DOC_SOURCE_URL, documentation.getSourceUrl()); APIUtil.createDocArtifactContent(genericArtifact, api.getId(), documentation); Assert.fail(); } catch (APIManagementException ex) { Assert.assertTrue(ex.getMessage().contains("Failed to create doc artifact content from :")); } }
Example #19
Source File: DeploymentSynchronizationManager.java From carbon-commons with Apache License 2.0 | 5 votes |
/** * Initialize the RepositoryManager instance. The RepositoryManager must be initialized by * calling this method, before synchronizers can use it to schedule tasks. * * @param serverConfig Active Carbon ServerConfiguration */ public void init(ServerConfiguration serverConfig) { if (log.isDebugEnabled()) { log.debug("Initializing deployment synchronization manager"); } int poolSize = DeploymentSynchronizerConstants.DEFAULT_POOL_SIZE; String value = serverConfig.getFirstProperty(DeploymentSynchronizerConstants.POOL_SIZE); if (value != null) { poolSize = Integer.parseInt(value); } repositoryTaskExecutor = Executors.newScheduledThreadPool(poolSize, new SimpleThreadFactory()); }
Example #20
Source File: LogViewerClient.java From carbon-commons with Apache License 2.0 | 5 votes |
public boolean isManager() { if (LoggingConstants.WSO2_STRATOS_MANAGER.equalsIgnoreCase(ServerConfiguration.getInstance() .getFirstProperty("ServerKey"))) { return true; } else { return false; } }
Example #21
Source File: JWTSignatureAlgTestCase.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { PowerMockito.mockStatic(CarbonUtils.class); ServerConfiguration serverConfiguration = Mockito.mock(ServerConfiguration.class); Mockito.when(serverConfiguration.getFirstProperty(APIConstants.PORT_OFFSET_CONFIG)).thenReturn("2"); PowerMockito.when(CarbonUtils.getServerConfiguration()).thenReturn(serverConfiguration); String dbConfigPath = System.getProperty("APIManagerDBConfigurationPath"); APIManagerConfiguration config = new APIManagerConfiguration(); config.load(dbConfigPath); ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService( new APIManagerConfigurationServiceImpl(config)); }
Example #22
Source File: CSRFValve.java From attic-stratos with Apache License 2.0 | 5 votes |
/** * Load configuration */ private void loadConfiguration() { ServerConfiguration serverConfiguration = ServerConfiguration.getInstance(); whiteList = serverConfiguration.getProperties(WHITE_LIST_PROPERTY); csrfPatternList = serverConfiguration.getProperties(RULE_PATTERN_PROPERTY); csrfRule = serverConfiguration.getFirstProperty(RULE_PROPERTY); if (whiteList.length > 0 && csrfPatternList.length > 0 && csrfRule != null && serverConfiguration.getFirstProperty(ENABLED_PROPERTY) != null && Boolean .parseBoolean(serverConfiguration.getFirstProperty(ENABLED_PROPERTY))) { csrfEnabled = true; } }
Example #23
Source File: APIMSiddhiExtensionsComponent.java From carbon-apimgt with Apache License 2.0 | 5 votes |
private static int getPortOffset() { ServerConfiguration carbonConfig = CarbonUtils.getServerConfiguration(); String portOffset = System.getProperty(PORT_OFFSET_SYSTEM_VAR, carbonConfig.getFirstProperty(PORT_OFFSET_CONFIG)); try { if ((portOffset != null)) { return Integer.parseInt(portOffset.trim()); } else { return 0; } } catch (NumberFormatException e) { log.error("Invalid Port Offset: " + portOffset + ". Default value 0 will be used.", e); return 0; } }
Example #24
Source File: XSSValve.java From attic-stratos with Apache License 2.0 | 5 votes |
/** * Load configuration */ private void loadConfiguration() { ServerConfiguration serverConfiguration = ServerConfiguration.getInstance(); if (serverConfiguration.getFirstProperty(ENABLED_PROPERTY) != null && Boolean.parseBoolean( serverConfiguration.getFirstProperty(ENABLED_PROPERTY))) { xssEnabled = true; } xssURIPatternList = serverConfiguration.getProperties(RULE_PATTERN_PROPERTY); xssRule = serverConfiguration.getFirstProperty(RULE_PROPERTY); patterPath = CarbonUtils.getCarbonSecurityConfigDirPath() + "/" + XSS_EXTENSION_FILE_NAME; buildScriptPatterns(); }
Example #25
Source File: APIKeyValidatorTestCase.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Before public void setup() { System.setProperty("carbon.home", "jhkjn"); PowerMockito.mockStatic(PrivilegedCarbonContext.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); PowerMockito.mockStatic(CarbonConstants.class); PowerMockito.mockStatic(ServerConfiguration.class); PowerMockito.mockStatic(APIUtil.class); PowerMockito.mockStatic(CarbonContext.class); PowerMockito.mockStatic(Util.class); PowerMockito.mockStatic(Caching.class); PowerMockito.when(Util.getTenantDomain()).thenReturn("carbon.super"); serverConfiguration = Mockito.mock(ServerConfiguration.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); PowerMockito.when(ServerConfiguration.getInstance()).thenReturn(serverConfiguration); PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class); Mockito.when(serviceReferenceHolder.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration); PowerMockito.mockStatic(APISecurityUtils.class); privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class); PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext); Cache cache = Mockito.mock(Cache.class); PowerMockito.when(APIUtil.getCache(APIConstants.API_MANAGER_CACHE_MANAGER, APIConstants .GATEWAY_TOKEN_CACHE_NAME, defaultCacheTimeout, defaultCacheTimeout)).thenReturn(cache); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.GATEWAY_TOKEN_CACHE_ENABLED)).thenReturn ("true"); Mockito.when(serverConfiguration.getFirstProperty(APIConstants.DEFAULT_CACHE_TIMEOUT)).thenReturn("900"); CacheManager cacheManager = Mockito.mock(CacheManager.class); PowerMockito.when(Caching.getCacheManager(APIConstants.API_MANAGER_CACHE_MANAGER)).thenReturn(cacheManager); Mockito.when(cacheManager.getCache(Mockito.anyString())).thenReturn(cache); }
Example #26
Source File: SCIMCommonUtils.java From carbon-identity with Apache License 2.0 | 5 votes |
public static void init() { //to initialize scim urls once. //construct SCIM_USER_LOCATION and SCIM_GROUP_LOCATION like: https://localhost:9443/wso2/scim/Groups if (scimUserLocation == null || scimGroupLocation == null) { String portOffSet = ServerConfiguration.getInstance().getFirstProperty("Ports.Offset"); //TODO: read the https port from config file. Here the default one is hardcoded, but offset is read from config int httpsPort = 9443 + Integer.parseInt(portOffSet); String scimURL = "https://" + ServerConfiguration.getInstance().getFirstProperty("HostName") + ":" + String.valueOf(httpsPort) + "/wso2/scim/"; scimUserLocation = scimURL + "Users"; scimGroupLocation = scimURL + "Groups"; } }
Example #27
Source File: WorkflowMgtServiceComponent.java From carbon-identity with Apache License 2.0 | 5 votes |
protected void activate(ComponentContext context) { BundleContext bundleContext = context.getBundleContext(); WorkflowManagementService workflowService = new WorkflowManagementServiceImpl(); bundleContext.registerService(WorkflowManagementService.class, workflowService, null); WorkflowServiceDataHolder.getInstance().setWorkflowService(workflowService); WorkflowServiceDataHolder.getInstance().setBundleContext(bundleContext); ServiceRegistration serviceRegistration = context.getBundleContext().registerService (WorkflowListener.class.getName(), new WorkflowAuditLogger(), null); context.getBundleContext().registerService (WorkflowExecutorManagerListener.class.getName(), new WorkflowExecutorAuditLogger(), null); if (serviceRegistration != null) { if (log.isDebugEnabled()) { log.debug("WorkflowAuditLogger registered."); } } else { log.error("Workflow Audit Logger could not be registered."); } if (System.getProperty(WFConstant.KEYSTORE_SYSTEM_PROPERTY_ID) == null) { System.setProperty(WFConstant.KEYSTORE_SYSTEM_PROPERTY_ID, ServerConfiguration.getInstance() .getFirstProperty(WFConstant.KEYSTORE_CARBON_CONFIG_PATH)); } if (System.getProperty(WFConstant.KEYSTORE_PASSWORD_SYSTEM_PROPERTY_ID) == null) { System.setProperty(WFConstant.KEYSTORE_PASSWORD_SYSTEM_PROPERTY_ID, ServerConfiguration.getInstance() .getFirstProperty(WFConstant.KEYSTORE_PASSWORD_CARBON_CONFIG_PATH)); } }
Example #28
Source File: OAuthAdminServiceClient.java From attic-stratos with Apache License 2.0 | 5 votes |
public OAuthAdminServiceClient(String epr) throws AxisFault { XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration(); int autosclaerSocketTimeout = conf.getInt("autoscaler.identity.clientTimeout", 180000); try { ServerConfiguration serverConfig = CarbonUtils.getServerConfiguration(); String trustStorePath = serverConfig.getFirstProperty("Security.TrustStore.Location"); String trustStorePassword = serverConfig.getFirstProperty("Security.TrustStore.Password"); String type = serverConfig.getFirstProperty("Security.TrustStore.Type"); System.setProperty("javax.net.ssl.trustStore", trustStorePath); System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword); System.setProperty("javax.net.ssl.trustStoreType", type); stub = new OAuthAdminServiceStub(epr); stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, autosclaerSocketTimeout); stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, autosclaerSocketTimeout); //String username = CarbonContext.getThreadLocalCarbonContext().getUsername(); //TODO StratosAuthenticationHandler does not set to carbon context, thus user name becomes null. // For the moment username is hardcoded since above is fixed. String username = conf.getString("autoscaler.identity.adminUser", "admin"); Utility.setAuthHeaders(stub._getServiceClient(), username); } catch (AxisFault axisFault) { String msg = "Failed to initiate identity service client. " + axisFault.getMessage(); log.error(msg, axisFault); throw new AxisFault(msg, axisFault); } }
Example #29
Source File: IdentityUtil.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Get the host name of the server. * @return Hostname */ public static String getHostName() { String hostName = ServerConfiguration.getInstance().getFirstProperty(IdentityCoreConstants.HOST_NAME); if (hostName == null) { try { hostName = NetworkUtils.getLocalHostname(); } catch (SocketException e) { throw IdentityRuntimeException.error("Error while trying to read hostname.", e); } } return hostName; }
Example #30
Source File: IdentityUtil.java From carbon-identity with Apache License 2.0 | 5 votes |
public static boolean isValidFileName(String fileName){ String fileNameRegEx = ServerConfiguration.getInstance().getFirstProperty(IdentityCoreConstants.FILE_NAME_REGEX); if(isBlank(fileNameRegEx)){ fileNameRegEx = DEFAULT_FILE_NAME_REGEX; } Pattern pattern = Pattern.compile(fileNameRegEx, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.COMMENTS); Matcher matcher = pattern.matcher(fileName); return matcher.matches(); }