use of com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement in project OpenAM by OpenRock.
the class CreateWSFedMetaDataTemplate method createExtendedMetaTemplate.
public static String createExtendedMetaTemplate(String entityId, Map mapParams) throws JAXBException {
JAXBContext jc = WSFederationMetaUtils.getMetaJAXBContext();
com.sun.identity.wsfederation.jaxb.entityconfig.ObjectFactory objFactory = new com.sun.identity.wsfederation.jaxb.entityconfig.ObjectFactory();
FederationConfigElement fedConfig = objFactory.createFederationConfigElement();
fedConfig.setFederationID(entityId);
fedConfig.setHosted(true);
String idpAlias = (String) mapParams.get(MetaTemplateParameters.P_IDP);
if (idpAlias != null) {
buildWSFedIDPConfigTemplate(objFactory, fedConfig, mapParams);
}
String spAlias = (String) mapParams.get(MetaTemplateParameters.P_SP);
if (spAlias != null) {
buildWSFedSPConfigTemplate(objFactory, fedConfig, mapParams);
}
Marshaller m = jc.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
StringWriter pw = new StringWriter();
m.marshal(fedConfig, pw);
return pw.toString();
}
use of com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement in project OpenAM by OpenRock.
the class WSFederationMetaSecurityUtils method updateProviderKeyInfo.
/**
* Updates signing or encryption key info for SP or IDP.
* This will update both signing/encryption alias on extended metadata and
* certificates in standard metadata.
* @param realm Realm the entity resides.
* @param entityID ID of the entity to be updated.
* @param certAlias Alias of the certificate to be set to the entity. If
* null, will remove existing key information from the SP or IDP.
* @param isIDP true if this is for IDP signing/encryption alias, false
* if this is for SP signing/encryption alias
* @throws WSFederationMetaException if failed to update the certificate
* alias for the entity.
*/
public static void updateProviderKeyInfo(String realm, String entityID, String certAlias, boolean isIDP) throws WSFederationMetaException {
WSFederationMetaManager metaManager = new WSFederationMetaManager();
FederationConfigElement config = metaManager.getEntityConfig(realm, entityID);
if (!config.isHosted()) {
String[] args = { entityID, realm };
throw new WSFederationMetaException("entityNotHosted", args);
}
FederationElement desp = metaManager.getEntityDescriptor(realm, entityID);
if (isIDP) {
IDPSSOConfigElement idpConfig = metaManager.getIDPSSOConfig(realm, entityID);
if ((idpConfig == null) || (desp == null)) {
String[] args = { entityID, realm };
throw new WSFederationMetaException("entityNotIDP", args);
}
// update standard metadata
if ((certAlias == null) || (certAlias.length() == 0)) {
// remove key info
removeKeyDescriptor(desp);
setExtendedAttributeValue(idpConfig, SAML2Constants.SIGNING_CERT_ALIAS, null);
} else {
TokenSigningKeyInfoElement kde = getKeyDescriptor(certAlias);
updateKeyDescriptor(desp, kde);
// update extended metadata
Set value = new HashSet();
value.add(certAlias);
setExtendedAttributeValue(idpConfig, SAML2Constants.SIGNING_CERT_ALIAS, value);
}
} else {
SPSSOConfigElement spConfig = metaManager.getSPSSOConfig(realm, entityID);
if ((spConfig == null) || (desp == null)) {
String[] args = { entityID, realm };
throw new WSFederationMetaException("entityNotSP", args);
}
// update standard metadata
if ((certAlias == null) || (certAlias.length() == 0)) {
// remove key info
removeKeyDescriptor(desp);
setExtendedAttributeValue(spConfig, SAML2Constants.SIGNING_CERT_ALIAS, null);
} else {
TokenSigningKeyInfoElement kde = getKeyDescriptor(certAlias);
updateKeyDescriptor(desp, kde);
// update extended metadata
Set value = new HashSet();
value.add(certAlias);
setExtendedAttributeValue(spConfig, SAML2Constants.SIGNING_CERT_ALIAS, value);
}
}
metaManager.setFederation(realm, desp);
metaManager.setEntityConfig(realm, config);
}
use of com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement in project OpenAM by OpenRock.
the class WSFederationMetaManager method getEntityByMetaAlias.
/**
* Returns entity ID associated with the metaAlias.
*
* @param metaAlias The metaAlias.
* @return entity ID associated with the metaAlias or null if not found.
* @throws WSFederationMetaException if unable to retrieve the entity ids.
*/
public String getEntityByMetaAlias(String metaAlias) throws WSFederationMetaException {
String realm = WSFederationMetaUtils.getRealmByMetaAlias(metaAlias);
try {
Set entityIds = configInst.getAllConfigurationNames(realm);
if (entityIds == null || entityIds.isEmpty()) {
return null;
}
for (Iterator iter = entityIds.iterator(); iter.hasNext(); ) {
String federationId = (String) iter.next();
FederationConfigElement config = getEntityConfig(realm, federationId);
if (config == null) {
continue;
}
List list = config.getIDPSSOConfigOrSPSSOConfig();
for (Iterator iter2 = list.iterator(); iter2.hasNext(); ) {
BaseConfigType bConfig = (BaseConfigType) iter2.next();
String cMetaAlias = bConfig.getMetaAlias();
if (cMetaAlias != null && cMetaAlias.equals(metaAlias)) {
return federationId;
}
}
}
} catch (ConfigurationException e) {
debug.error("WSFederationMetaManager.getEntityByMetaAlias:", e);
throw new WSFederationMetaException(e);
}
return null;
}
use of com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement in project OpenAM by OpenRock.
the class WSFederationMetaCache method getEntityConfig.
/**
* Returns extended entity configuration under the realm from cache.
* @param realm The realm under which the entity resides.
* @param entityId ID of the entity to be retrieved.
* @return <code>FederationConfigElement</code> object for the entity or
* null if not found.
*/
static FederationConfigElement getEntityConfig(String realm, String entityId) {
String cacheKey = buildCacheKey(realm, entityId);
FederationConfigElement config = (FederationConfigElement) configCache.get(cacheKey);
if (debug.messageEnabled()) {
debug.message("SAML2MetaCache.getEntityConfig: cacheKey = " + cacheKey + ", found = " + (config != null));
}
return config;
}
use of com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement in project OpenAM by OpenRock.
the class WSFederationMetaManager method getEntityConfig.
/**
* Returns extended entity configuration under the realm.
*
* @param realm The realm under which the entity resides.
* @param federationId ID of the entity to be retrieved.
* @return <code>FederationConfigElement</code> object for the entity or
* null if not found.
* @throws WSFederationMetaException if unable to retrieve the entity
* configuration.
*/
public FederationConfigElement getEntityConfig(String realm, String federationId) throws WSFederationMetaException {
if (federationId == null) {
return null;
}
if (realm == null) {
realm = "/";
}
String[] objs = { federationId, realm };
FederationConfigElement config = null;
if (callerSession == null) {
config = WSFederationMetaCache.getEntityConfig(realm, federationId);
if (config != null) {
LogUtil.access(Level.FINE, LogUtil.GOT_ENTITY_CONFIG, objs, null);
return config;
}
}
try {
Map attrs = configInst.getConfiguration(realm, federationId);
if (attrs == null) {
return null;
}
Set values = (Set) attrs.get(ATTR_ENTITY_CONFIG);
if (values == null || values.isEmpty()) {
return null;
}
String value = (String) values.iterator().next();
Object obj = WSFederationMetaUtils.convertStringToJAXB(value);
if (obj instanceof FederationConfigElement) {
config = (FederationConfigElement) obj;
WSFederationMetaCache.putEntityConfig(realm, federationId, config);
LogUtil.access(Level.FINE, LogUtil.GOT_ENTITY_CONFIG, objs, null);
return config;
}
debug.error("WSFederationMetaManager.getEntityConfig: " + "invalid config");
LogUtil.error(Level.INFO, LogUtil.GOT_INVALID_ENTITY_CONFIG, objs, null);
throw new WSFederationMetaException("invalid_config", objs);
} catch (ConfigurationException e) {
debug.error("WSFederationMetaManager.getEntityConfig:", e);
String[] data = { e.getMessage(), federationId, realm };
LogUtil.error(Level.INFO, LogUtil.CONFIG_ERROR_GET_ENTITY_CONFIG, data, null);
throw new WSFederationMetaException(e);
} catch (JAXBException jaxbe) {
debug.error("WSFederationMetaManager.getEntityConfig:", jaxbe);
LogUtil.error(Level.INFO, LogUtil.GOT_INVALID_ENTITY_CONFIG, objs, null);
throw new WSFederationMetaException("invalid_config", objs);
}
}
Aggregations