Java Code Examples for org.wso2.carbon.base.ServerConfiguration#getInstance()
The following examples show how to use
org.wso2.carbon.base.ServerConfiguration#getInstance() .
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: 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 2
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 3
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 4
Source File: KeyStoreAdmin.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
public KeyStoreAdmin(int tenantId, Registry registry) { ServerConfiguration config = ServerConfiguration.getInstance(); TRUST_STORE_LOCATION = config.getFirstProperty("Security.TrustStore.Location"); TRUST_STORE_PASSWORD = config.getFirstProperty("Security.TrustStore.Password"); this.registry = registry; this.tenantId = tenantId; }
Example 5
Source File: Utils.java From attic-stratos with Apache License 2.0 | 5 votes |
/** * Read context name from carbon.xml * "carbon" will be the default value * * @return webcontext name */ public static String getWebContextName() { String webContext = "carbon"; ServerConfiguration sc = ServerConfiguration.getInstance(); if (sc != null) { String value = sc.getFirstProperty("WebContext"); if (value != null) { webContext = value; } } return webContext; }
Example 6
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 7
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 8
Source File: IdentityBaseUtil.java From carbon-identity with Apache License 2.0 | 5 votes |
public static Policy getDefaultRampartConfig() { //Extract the primary keystore information from server configuration ServerConfiguration serverConfig = ServerConfiguration.getInstance(); String keyStore = serverConfig.getFirstProperty("Security.KeyStore.Location"); String keyStoreType = serverConfig.getFirstProperty("Security.KeyStore.Type"); String keyStorePassword = serverConfig.getFirstProperty("Security.KeyStore.Password"); String privateKeyAlias = serverConfig.getFirstProperty("Security.KeyStore.KeyAlias"); String privateKeyPassword = serverConfig.getFirstProperty("Security.KeyStore.KeyPassword"); //Populate Rampart Configuration RampartConfig rampartConfig = new RampartConfig(); rampartConfig.setUser(privateKeyAlias); //TODO use a registry based callback handler rampartConfig.setPwCbClass("org.wso2.carbon.identity.base.InMemoryPasswordCallbackHandler"); //Set the private key alias and private key password in the password callback handler InMemoryPasswordCallbackHandler.addUser(privateKeyAlias, privateKeyPassword); CryptoConfig sigCrypto = new CryptoConfig(); Properties props = new Properties(); sigCrypto.setProvider("org.apache.ws.security.components.crypto.Merlin"); props.setProperty("org.apache.ws.security.crypto.merlin.keystore.type", keyStoreType); props.setProperty("org.apache.ws.security.crypto.merlin.file", keyStore); props.setProperty("org.apache.ws.security.crypto.merlin.keystore.password", keyStorePassword); // This property is set in order to fix IDENTITY-1931. // This issue is however not found in IS-4.5.0. // The reason for the error is unknown. Suspecting JCE provider. // Error occurrs when WSS4J tries to read the certificates in the JDK's cacerts store. props.setProperty("org.apache.ws.security.crypto.merlin.load.cacerts", "false"); sigCrypto.setProp(props); rampartConfig.setSigCryptoConfig(sigCrypto); Policy policy = new Policy(); policy.addAssertion(rampartConfig); return policy; }
Example 9
Source File: SecurityConfigParams.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Get the private key store * * If the key store is defined in the Security configuration take it from there otherwise * key store is taken from the Server Configuration * * @return private key store */ public String getPrivateStore() { if (privateStore == null) { ServerConfiguration serverConfig = ServerConfiguration.getInstance(); String pvtStore = serverConfig.getFirstProperty("Security.KeyStore.Location"); return pvtStore.substring(pvtStore.lastIndexOf("/") + 1); } return privateStore; }
Example 10
Source File: SAML1TokenBuilder.java From carbon-identity with Apache License 2.0 | 5 votes |
@Override public void createSAMLAssertion(DateTime notAfter, DateTime notBefore, String assertionId) throws IdentityProviderException { assertion = (Assertion) buildXMLObject(Assertion.DEFAULT_ELEMENT_NAME); Conditions conditions = (Conditions) buildXMLObject(Conditions.DEFAULT_ELEMENT_NAME); conditions.setNotBefore(notBefore); conditions.setNotOnOrAfter(notAfter); ServerConfiguration config = ServerConfiguration.getInstance(); String host = "http://" + config.getFirstProperty("HostName"); assertion.setIssuer(host); assertion.setIssueInstant(new DateTime()); if (appilesTo != null) { Audience audience = (Audience) buildXMLObject(Audience.DEFAULT_ELEMENT_NAME); audience.setUri(appilesTo); AudienceRestrictionCondition audienceRestrictions = (AudienceRestrictionCondition) buildXMLObject(AudienceRestrictionCondition.DEFAULT_ELEMENT_NAME); audienceRestrictions.getAudiences().add(audience); conditions.getAudienceRestrictionConditions().add(audienceRestrictions); } assertion.setConditions(conditions); assertion.getAttributeStatements().add(this.attributeStmt); assertion.setID(assertionId); }
Example 11
Source File: OpenIDUtil.java From carbon-identity with Apache License 2.0 | 5 votes |
private static String getHostName() { ServerConfiguration serverConfig = ServerConfiguration.getInstance(); if (serverConfig.getFirstProperty("HostName") != null) { return MultitenantUtils.getDomainNameFromOpenId(serverConfig.getFirstProperty("HostName")); } else { return "localhost"; } }
Example 12
Source File: DeviceTypeUtils.java From product-iots with Apache License 2.0 | 5 votes |
private static int getPortOffset() { ServerConfiguration carbonConfig = ServerConfiguration.getInstance(); String portOffset = System.getProperty("portOffset", carbonConfig.getFirstProperty( DeviceTypeConstants.CARBON_CONFIG_PORT_OFFSET)); try { if ((portOffset != null)) { return Integer.parseInt(portOffset.trim()); } else { return DeviceTypeConstants.CARBON_DEFAULT_PORT_OFFSET; } } catch (NumberFormatException e) { return DeviceTypeConstants.CARBON_DEFAULT_PORT_OFFSET; } }
Example 13
Source File: DeviceTypeUtils.java From product-iots with Apache License 2.0 | 5 votes |
private static int getPortOffset() { ServerConfiguration carbonConfig = ServerConfiguration.getInstance(); String portOffset = System.getProperty("portOffset", carbonConfig.getFirstProperty( DeviceTypeConstants.CARBON_CONFIG_PORT_OFFSET)); try { if ((portOffset != null)) { return Integer.parseInt(portOffset.trim()); } else { return DeviceTypeConstants.CARBON_DEFAULT_PORT_OFFSET; } } catch (NumberFormatException e) { return DeviceTypeConstants.CARBON_DEFAULT_PORT_OFFSET; } }
Example 14
Source File: STSConfigAdmin.java From carbon-identity with Apache License 2.0 | 4 votes |
public static void configureService(AxisConfiguration config, Registry registry) throws IdentityProviderException { AxisConfiguration axisConfig = IdentitySTSMgtServiceComponent.getConfigurationContext().getAxisConfiguration(); try { ServerConfiguration serverConfig = ServerConfiguration.getInstance(); String ksName = serverConfig.getFirstProperty(STSMgtConstants.ServerConfigProperty.SECURITY_KEYSTORE_LOCATION); ksName = ksName.substring(ksName.lastIndexOf("/") + 1); SecurityConfigAdmin admin = new SecurityConfigAdmin(config, registry, new IPPasswordCallbackHandler()); if (log.isDebugEnabled()) { log.debug("Applying identity security policy for Identity STS services"); } if (IdentityProviderUtil.isIntial()) { if (axisConfig.getService(IdentityConstants.SERVICE_NAME_STS_UT) != null) { admin.applySecurity(IdentityConstants.SERVICE_NAME_STS_UT, STSMgtConstants.Policy.POLICY_SCENARIO19, null, null, null, null); } if (axisConfig.getService(IdentityConstants.OpenId.SERVICE_NAME_STS_OPENID) != null) { admin.applySecurity(IdentityConstants.OpenId.SERVICE_NAME_STS_OPENID, STSMgtConstants.Policy.POLICY_SCENARIO19, null, null, null, null); } if (axisConfig.getService(IdentityConstants.SERVICE_NAME_STS_IC) != null) { admin.applySecurity(IdentityConstants.SERVICE_NAME_STS_IC, STSMgtConstants.Policy.POLICY_SCENARIO18, null, new String[] { ksName }, ksName, null); } if (axisConfig.getService(IdentityConstants.OpenId.SERVICE_NAME_STS_IC_OPENID) != null) { admin.applySecurity(IdentityConstants.OpenId.SERVICE_NAME_STS_IC_OPENID, STSMgtConstants.Policy.POLICY_SCENARIO18, null, new String[] { ksName }, ksName, null); } if (axisConfig.getService(IdentityConstants.SERVICE_NAME_STS_UT_SYMM) != null) { admin.applySecurity(IdentityConstants.SERVICE_NAME_STS_UT_SYMM, STSMgtConstants.Policy.POLICY_SCENARIO18, null, new String[] { ksName }, ksName, null); } if (axisConfig.getService(IdentityConstants.SERVICE_NAME_STS_IC_SYMM) != null) { admin.applySecurity(IdentityConstants.SERVICE_NAME_STS_IC_SYMM, STSMgtConstants.Policy.POLICY_SCENARIO18, null, new String[] { ksName }, ksName, null); } } if (axisConfig.getService(IdentityConstants.SERVICE_NAME_STS_UT) != null) { overrideCallbackHandler(axisConfig, IdentityConstants.SERVICE_NAME_STS_UT); } if (axisConfig.getService(IdentityConstants.SERVICE_NAME_STS_UT_SYMM) != null) { overrideCallbackHandler(axisConfig, IdentityConstants.SERVICE_NAME_STS_UT_SYMM); } if (axisConfig.getService(IdentityConstants.OpenId.SERVICE_NAME_STS_OPENID) != null) { overrideCallbackHandler(axisConfig, IdentityConstants.OpenId.SERVICE_NAME_STS_OPENID); } if (axisConfig.getService(IdentityConstants.SERVICE_NAME_STS_IC) != null) { overrideCallbackHandler(axisConfig, IdentityConstants.SERVICE_NAME_STS_IC); } } catch (Exception e) { log.error("errorInChangingSecurityConfiguration", e); throw new IdentityProviderException("errorInChangingSecurityConfiguration", e); } }
Example 15
Source File: SAML2TokenBuilder.java From carbon-identity with Apache License 2.0 | 4 votes |
@Override public void createSAMLAssertion(DateTime notAfter, DateTime notBefore, String assertionId) throws IdentityProviderException { assertion = (Assertion) buildXMLObject(Assertion.DEFAULT_ELEMENT_NAME); Conditions conditions = (Conditions) buildXMLObject(Conditions.DEFAULT_ELEMENT_NAME); conditions.setNotBefore(notBefore); conditions.setNotOnOrAfter(notAfter); ServerConfiguration config = ServerConfiguration.getInstance(); String host = "http://" + config.getFirstProperty("HostName"); Issuer issuer = (Issuer) buildXMLObject(Issuer.DEFAULT_ELEMENT_NAME); issuer.setValue(host); assertion.setIssuer(issuer); assertion.setIssueInstant(new DateTime()); if (appilesTo != null) { Audience audience = (Audience) buildXMLObject(Audience.DEFAULT_ELEMENT_NAME); audience.setAudienceURI(appilesTo); AudienceRestriction audienceRestrictions = (AudienceRestriction) buildXMLObject(AudienceRestriction.DEFAULT_ELEMENT_NAME); audienceRestrictions.getAudiences().add(audience); conditions.getAudienceRestrictions().add(audienceRestrictions); } assertion.setConditions(conditions); assertion.getAttributeStatements().add(this.attributeStmt); assertion.setID(assertionId); Subject subject = (Subject) buildXMLObject(Subject.DEFAULT_ELEMENT_NAME); SubjectConfirmation subjectConf = (SubjectConfirmation) buildXMLObject(SubjectConfirmation.DEFAULT_ELEMENT_NAME); SubjectConfirmationData confData = (SubjectConfirmationData) buildXMLObject(SubjectConfirmationData.DEFAULT_ELEMENT_NAME); confData.setAddress(CONF_KEY); subjectConf.setSubjectConfirmationData(confData); subject.getSubjectConfirmations().add(subjectConf); assertion.setSubject(subject); }
Example 16
Source File: CarbonRepositoryUtils.java From carbon-commons with Apache License 2.0 | 4 votes |
/** * Load the deployment synchronizer configuration from the global ServerConfiguration * of Carbon. * * @return a DeploymentSynchronizerConfiguration instance * @throws org.wso2.carbon.deployment.synchronizer.DeploymentSynchronizerException on error */ public static DeploymentSynchronizerConfiguration getDeploymentSyncConfigurationFromConf() throws DeploymentSynchronizerException{ DeploymentSynchronizerConfiguration config = new DeploymentSynchronizerConfiguration(); ServerConfiguration serverConfig = ServerConfiguration.getInstance(); String value = serverConfig.getFirstProperty(DeploymentSynchronizerConstants.ENABLED); //If Deployment Synchronizer Configuration is not found in carbon.xml if (value == null) { return null; } config.setEnabled(JavaUtils.isTrueExplicitly(value)); if (config.isEnabled()) { value = serverConfig.getFirstProperty(DeploymentSynchronizerConstants.AUTO_CHECKOUT_MODE); config.setAutoCheckout(value != null && JavaUtils.isTrueExplicitly(value)); value = serverConfig.getFirstProperty(DeploymentSynchronizerConstants.AUTO_COMMIT_MODE); config.setAutoCommit(value != null && JavaUtils.isTrueExplicitly(value)); value = serverConfig.getFirstProperty(DeploymentSynchronizerConstants.USE_EVENTING); config.setUseEventing(value != null && JavaUtils.isTrueExplicitly(value)); value = serverConfig.getFirstProperty(DeploymentSynchronizerConstants.AUTO_SYNC_PERIOD); if (value != null) { config.setPeriod(Long.parseLong(value)); } else { config.setPeriod(DeploymentSynchronizerConstants.DEFAULT_AUTO_SYNC_PERIOD); } value = serverConfig.getFirstProperty(DeploymentSynchronizerConstants.REPOSITORY_TYPE); if (value != null) { config.setRepositoryType(value); } else { config.setRepositoryType(DeploymentSynchronizerConstants.DEFAULT_REPOSITORY_TYPE); } ArtifactRepository repository = RepositoryReferenceHolder.getInstance().getRepositoryByType(config.getRepositoryType()); if (repository == null) { throw new DeploymentSynchronizerException("No Repository found for type " + config.getRepositoryType()); } List<RepositoryConfigParameter> parameters = repository.getParameters(); //If repository specific configuration parameters are found. if (parameters != null) { //Find the 'value' of each parameter from the server config by parameter 'name' and attach to parameter for (RepositoryConfigParameter parameter : parameters) { parameter.setValue(serverConfig.getFirstProperty(parameter.getName())); } //Attach parameter list to config object. config.setRepositoryConfigParameters( parameters.toArray(new RepositoryConfigParameter[parameters.size()])); } return config; } else { return config; } }
Example 17
Source File: KeyStoreManagementServiceImpl.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
private String getTrustStoreName() { ServerConfiguration serverConfiguration = ServerConfiguration.getInstance(); String filePath = serverConfiguration.getFirstProperty(SERVER_TRUSTSTORE_FILE); return Paths.get(filePath).getFileName().toString(); }
Example 18
Source File: SecurityConfigParams.java From carbon-identity with Apache License 2.0 | 3 votes |
/** * Get the private key alias * * If the key alias is defined in the Security configuration take it from there otherwise * key alias is taken from the Server Configuration * * @return private key key alias */ public String getKeyAlias() { if (keyAlias == null) { ServerConfiguration serverConfig = ServerConfiguration.getInstance(); return serverConfig.getFirstProperty("Security.KeyStore.KeyAlias"); } return keyAlias; }