use of com.sun.identity.federation.meta.IDFFMetaException in project OpenAM by OpenRock.
the class FSDefaultAttributeMapper method getAttributes.
/**
* Returns the attribute map for the given list of
* <code>AttributeStatement</code>s.
* @param statements list of <code>AttributeStatements</code>s.
* @param hostEntityId Hosted provider entity id.
* @param remoteEntityId Remote provider entity id.
* @param token Single sign-on session token.
* @return map of attribute values. The map will have the key as the
* attribute name and the map value is the attribute value
* that are passed via the single sign-on assertion.
*/
public Map getAttributes(List statements, String hostEntityId, String remoteEntityId, Object token) {
Map map = new HashMap();
if (statements == null || statements.size() == 0) {
return map;
}
Map configMap = null;
try {
IDFFMetaManager metaManager = FSUtils.getIDFFMetaManager();
if (metaManager != null) {
SPDescriptorConfigElement spConfig = metaManager.getSPDescriptorConfig("/", hostEntityId);
if (spConfig != null) {
Map attributes = IDFFMetaUtils.getAttributes(spConfig);
configMap = FSServiceUtils.parseAttributeConfig((List) attributes.get(IFSConstants.SP_ATTRIBUTE_MAP));
}
}
} catch (IDFFMetaException fme) {
FSUtils.debug.error("FSDefaultAttributeMapper.getAttributes:" + " Unable to read configuration map.", fme);
return map;
}
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSDefaultAttributeMapper.getAttributeMap: Configured map " + configMap);
}
for (Iterator iter = statements.iterator(); iter.hasNext(); ) {
AttributeStatement statement = (AttributeStatement) iter.next();
List attributes = statement.getAttribute();
if (attributes == null || attributes.size() == 0) {
continue;
}
Iterator iter1 = attributes.iterator();
while (iter1.hasNext()) {
Attribute attribute = (Attribute) iter1.next();
List values = null;
try {
values = attribute.getAttributeValue();
} catch (SAMLException ex) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSDefaultAttributeMapper.get" + "Attributes: Exception", ex);
}
continue;
}
if (values == null || values.size() == 0) {
continue;
}
String attributeName = attribute.getAttributeName();
if (configMap != null && !configMap.isEmpty()) {
String realAttrName = (String) configMap.get(attributeName);
if (realAttrName != null && realAttrName.length() > 0) {
attributeName = realAttrName;
}
}
//Retrieve the first only one.
String valueString = XMLUtils.getElementValue((Element) values.get(0));
if (valueString != null && valueString.length() > 0) {
map.put(attributeName, valueString);
}
}
}
return map;
}
use of com.sun.identity.federation.meta.IDFFMetaException in project OpenAM by OpenRock.
the class FSDefaultAttributePlugin method getAttributeStatements.
/**
* Returns list of <code>AttributeStatement</code>s by using attribute
* map defined in the configuration.
* @param realm The realm under which the entity resides.
* @param hostEntityId Hosted identity provider entity id.
* @param remoteEntityID Remote provider's entity id
* @param subject Subject subject of the authenticated principal.
* @param token user's session.
* @return list of SAML <code>AttributeStatement<code>s.
*/
public List getAttributeStatements(String realm, String hostEntityId, String remoteEntityID, FSSubject subject, Object token) {
FSUtils.debug.message("FSDefaultAttributePlugin.getAttributeStatements");
Map attributeMap = null;
try {
IDFFMetaManager metaManager = FSUtils.getIDFFMetaManager();
if (metaManager != null) {
IDPDescriptorConfigElement idpConfig = metaManager.getIDPDescriptorConfig(realm, hostEntityId);
if (idpConfig != null) {
Map attributes = IDFFMetaUtils.getAttributes(idpConfig);
attributeMap = FSServiceUtils.parseAttributeConfig((List) attributes.get(IFSConstants.IDP_ATTRIBUTE_MAP));
}
}
} catch (IDFFMetaException me) {
FSUtils.debug.error("FSDefaultAttributePlugin.getAttribute" + "Statements: meta exception.", me);
return null;
}
if (attributeMap == null || attributeMap.isEmpty()) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSDefaultAttributePlugin.getAttribute" + "Statements: Attribute map configuration is empty.");
}
return null;
} else {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSDefaultAttributePlugin.getAttribute" + "Statements: Attribute map configuration: " + attributeMap);
}
}
List statements = new ArrayList();
List attributes = new ArrayList();
try {
Iterator iter = attributeMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
String attributeName = (String) entry.getKey();
String attributeValue = getAttributeValue(token, (String) entry.getValue());
if (attributeValue != null) {
Attribute attr = new Attribute(attributeName, SAMLConstants.assertionSAMLNameSpaceURI, attributeValue);
attributes.add(attr);
}
}
AttributeStatement statement = new AttributeStatement(subject, attributes);
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSDefaultAttributePlugin.getAttribute" + "Statements: attribute statement: " + statement.toString());
}
statements.add(statement);
return statements;
} catch (SAMLException ex) {
FSUtils.debug.error("FSDefaultAttributePlugin.getAttribute" + "Statements: SAML Exception", ex);
}
return new ArrayList();
}
use of com.sun.identity.federation.meta.IDFFMetaException in project OpenAM by OpenRock.
the class FSIDPProxyImpl method getPreferredIDP.
/**
* Returns the preferred IDP.
* @param authnRequest original authnrequest
* @param hostEntityID ProxyIDP entity ID.
* @param request <code>HttpServletRequest</code> object
* @param response <code>HttpServletResponse</code> object
* @return providerID of the authenticating provider to be proxied.
* @exception FSRedirectException if redirect was done
*/
public String getPreferredIDP(FSAuthnRequest authnRequest, String hostEntityID, HttpServletRequest request, HttpServletResponse response) throws FSRedirectException {
FSUtils.debug.message("FSIDPProxyImpl.getPreferredIDP:Init");
try {
Map attributes = IDFFMetaUtils.getAttributes(FSUtils.getIDFFMetaManager().getSPDescriptorConfig("/", authnRequest.getProviderId()));
String useIntroductionForProxying = IDFFMetaUtils.getFirstAttributeValue(attributes, IFSConstants.USE_INTRODUCTION_FOR_IDP_PROXY);
if (useIntroductionForProxying == null || !useIntroductionForProxying.equals("true")) {
List proxyIDPs = (List) attributes.get(IFSConstants.IDP_PROXY_LIST);
if (proxyIDPs == null || proxyIDPs.isEmpty()) {
FSUtils.debug.error("FSIDPProxyImpl.getPrefferedIDP:" + "Preferred IDPs are null.");
return null;
}
return (String) proxyIDPs.iterator().next();
} else {
StringBuffer redirectURL = new StringBuffer(100);
String baseURL = FSServiceUtils.getBaseURL(request);
redirectURL.append(baseURL).append(IFSConstants.IDP_FINDER_URL).append("?").append("RequestID=").append(authnRequest.getRequestID()).append("&").append("ProviderID=").append(hostEntityID);
FSUtils.forwardRequest(request, response, redirectURL.toString());
throw new FSRedirectException(FSUtils.bundle.getString("Redirection_Happened"));
}
} catch (IDFFMetaException ex) {
FSUtils.debug.error("FSIDPProxyImpl.getPreferredIDP: " + "meta Exception in retrieving the preferred IDP", ex);
return null;
} catch (Exception e) {
FSUtils.debug.error("FSIDPProxyImpl.getPreferredIDP: " + "Exception in retrieving the preferred IDP", e);
return null;
}
}
use of com.sun.identity.federation.meta.IDFFMetaException in project OpenAM by OpenRock.
the class FSLoginHelper method getIDPs.
private Set getIDPs(String metaAlias) {
Set idpSet = new HashSet();
try {
String provider = "";
String providerStatus = "";
String role = IFSConstants.IDP.toLowerCase();
IDPDescriptorType providerDesc = null;
BaseConfigType providerConfig = null;
Set trustedProviders = metaManager.getAllTrustedProviders(metaAlias);
if (trustedProviders != null && !trustedProviders.isEmpty()) {
Iterator it = trustedProviders.iterator();
while (it.hasNext()) {
provider = (String) it.next();
providerDesc = metaManager.getIDPDescriptor(realm, provider);
providerConfig = metaManager.getIDPDescriptorConfig(realm, provider);
if (providerDesc == null || providerConfig == null) {
continue;
}
providerStatus = IDFFMetaUtils.getFirstAttributeValueFromConfig(providerConfig, IFSConstants.PROVIDER_STATUS);
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSLoginHelper::getIDPs For " + "providerId " + provider + " status is " + providerStatus);
}
if (providerStatus == null || providerStatus.length() == 0 || (providerStatus != null && providerStatus.equalsIgnoreCase(IFSConstants.ACTIVE))) {
idpSet.add(provider);
}
}
}
} catch (IDFFMetaException ame) {
FSUtils.debug.error("FSLoginHelper::getIDPs Error in getting idp List:", ame);
}
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSLoginHelper::getIDPs returing idpset as " + idpSet);
}
return idpSet;
}
use of com.sun.identity.federation.meta.IDFFMetaException in project OpenAM by OpenRock.
the class FSDefaultRealmAttributeMapper method getAttributes.
/**
* Returns the attribute map for the given list of
* <code>AttributeStatement</code>s.
* @param statements list of <code>AttributeStatements</code>s.
* @param realm The realm under which the entity resides.
* @param hostEntityId Hosted provider entity id.
* @param remoteEntityId Remote provider entity id.
* @param token Single sign-on session token.
* @return map of attribute values. The map will have the key as the
* attribute name and the map value is the attribute value
* that are passed via the single sign-on assertion.
*/
public Map getAttributes(List statements, String realm, String hostEntityId, String remoteEntityId, Object token) {
Map map = new HashMap();
if (statements == null || statements.size() == 0) {
return map;
}
Map configMap = null;
try {
IDFFMetaManager metaManager = FSUtils.getIDFFMetaManager();
if (metaManager != null) {
SPDescriptorConfigElement spConfig = metaManager.getSPDescriptorConfig(realm, hostEntityId);
if (spConfig != null) {
Map attributes = IDFFMetaUtils.getAttributes(spConfig);
configMap = FSServiceUtils.parseAttributeConfig((List) attributes.get(IFSConstants.SP_ATTRIBUTE_MAP));
}
}
} catch (IDFFMetaException fme) {
FSUtils.debug.error("FSDefaultAttributeMapper.getAttributes:" + " Unable to read configuration map.", fme);
return map;
}
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSDefaultAttributeMapper.getAttributeMap: Configured map " + configMap);
}
for (Iterator iter = statements.iterator(); iter.hasNext(); ) {
AttributeStatement statement = (AttributeStatement) iter.next();
List attributes = statement.getAttribute();
if (attributes == null || attributes.size() == 0) {
continue;
}
Iterator iter1 = attributes.iterator();
while (iter1.hasNext()) {
Attribute attribute = (Attribute) iter1.next();
List values = null;
try {
values = attribute.getAttributeValue();
} catch (SAMLException ex) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSDefaultAttributeMapper.get" + "Attributes: Exception", ex);
}
continue;
}
if (values == null || values.size() == 0) {
continue;
}
String attributeName = attribute.getAttributeName();
if (configMap != null && !configMap.isEmpty()) {
String realAttrName = (String) configMap.get(attributeName);
if (realAttrName != null && realAttrName.length() > 0) {
attributeName = realAttrName;
}
}
//Retrieve the first only one.
String valueString = XMLUtils.getElementValue((Element) values.get(0));
if (valueString != null && valueString.length() > 0) {
map.put(attributeName, valueString);
}
}
}
return map;
}
Aggregations