String cryptoProvider = ServerCrypto.class.getName();
Properties props = RampartConfigUtil.getServerCryptoProperties(
new String[]{keyStoreName}, keyStoreName, privateKeyAlias);
SAMLTokenIssuerConfig stsSamlConfig = new SAMLTokenIssuerConfig(issuerName,
cryptoProvider, props);
stsSamlConfig.setIssuerKeyAlias(keyAlias);
stsSamlConfig.setIssuerKeyPassword(keyPassword);
stsSamlConfig.setAddRequestedAttachedRef(true);
stsSamlConfig.setAddRequestedUnattachedRef(true);
stsSamlConfig.setKeyComputation(2);
stsSamlConfig.setProofKeyType(TokenIssuerUtil.BINARY_SECRET);
String resourcePath = null;
resourcePath = RegistryResources.SERVICE_GROUPS + ServerConstants.STS_NAME
+ RegistryResources.SERVICES + ServerConstants.STS_NAME + "/trustedServices";
if (configRegistry.resourceExists(resourcePath)) {
Resource trustedService = null;
Properties properties = null;
Iterator iterator = null;
trustedService = configRegistry.get(resourcePath);
properties = trustedService.getProperties();
if (properties != null && !properties.isEmpty()) {
iterator = properties.entrySet().iterator();
while (iterator.hasNext()) {
Entry entry = (Entry) iterator.next();
stsSamlConfig.addTrustedServiceEndpointAddress((String) entry.getKey(),
(String) ((List) entry.getValue()).get(0));
}
}
}
//Set the TTL value read from the carbon.xml
String ttl = serverConfig.getFirstProperty("STSTimeToLive");
if (ttl != null && ttl.length() > 0) {
try {
stsSamlConfig.setTtl(Long.parseLong(ttl));
if (log.isDebugEnabled()) {
log.debug("STSTimeToLive read from carbon.xml " + ttl);
}
} catch (NumberFormatException e) {
log.error("Error while reading STSTimeToLive from carbon.xml", e);
}
}
try {
// remove param is exists
Parameter param = service.getParameter(SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG
.getLocalPart());
if (param == null) {
// Add new parameter
service.addParameter(stsSamlConfig.getParameter());
service.addParameter(new Parameter(CarbonConstants.SKIP_PARAM_INIT, new Boolean("true")));
}
} catch (AxisFault e) {
log.error("Error while updating " + ServerConstants.STS_NAME
+ " in STSDeploymentInterceptor", e);