KeyStoreAdmin admin = null;
KeyStoreData[] keystores = null;
String privateKeyAlias = null;
String keyStoreName = null;
String issuerName = null;
ServerConfiguration serverConfig = null;
configRegistry = STSServiceDataHolder.getInstance().getRegistryService()
.getConfigSystemRegistry();
governRegistry = STSServiceDataHolder.getInstance().getRegistryService()
.getGovernanceSystemRegistry();
if (configRegistry == null || config.getService(ServerConstants.STS_NAME) == null) {
if (log.isDebugEnabled()) {
log.debug("configRegistry not set or STS service is unavailable");
}
return;
}
serverConfig = ServerConfiguration.getInstance();
keyAlias = serverConfig.getFirstProperty("Security.KeyStore.KeyAlias");
keyPassword = serverConfig.getFirstProperty("Security.KeyStore.KeyPassword");
issuerName = serverConfig.getFirstProperty("HostName");
if (issuerName == null) {
// HostName not set :-( use wso2wsas-sts
issuerName = ServerConstants.STS_NAME;
}
admin = new KeyStoreAdmin(governRegistry);
keystores = admin.getKeyStores();
for (int i = 0; i < keystores.length; i++) {
if (KeyStoreUtil.isPrimaryStore(keystores[i].getKeyStoreName())) {
keyStoreName = keystores[i].getKeyStoreName();
privateKeyAlias = KeyStoreUtil.getPrivateKeyAlias(KeyStoreManager.getInstance(
STSServiceDataHolder.getInstance().getRegistryService().getGovernanceSystemRegistry())
.getKeyStore(keyStoreName));
break;
}
}
if (privateKeyAlias != null) {
service = config.getService(ServerConstants.STS_NAME);
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()) {