use of com.sun.identity.saml2.jaxb.metadata.IDPSSODescriptorElement in project OpenAM by OpenRock.
the class SAML2Test method importEntity.
@Test(groups = { "samlv2", "samlv2op" }, dependsOnMethods = { "createMetaTemplate" })
public void importEntity() throws CLIException, SAML2MetaException {
entering("importEntity", null);
String[] args = { "import-entity", CLIConstants.PREFIX_ARGUMENT_LONG + FedCLIConstants.ARGUMENT_METADATA, "meta", CLIConstants.PREFIX_ARGUMENT_LONG + FedCLIConstants.ARGUMENT_EXTENDED_DATA, "extended", CLIConstants.PREFIX_ARGUMENT_LONG + FedCLIConstants.ARGUMENT_COT, NAME_COT, CLIConstants.PREFIX_ARGUMENT_LONG + FedCLIConstants.SPECIFICATION_VERSION, FedCLIConstants.SAML2_SPECIFICATION };
CLIRequest req = new CLIRequest(null, args, getAdminSSOToken());
cmdManager.addToRequestQueue(req);
cmdManager.serviceRequestQueue();
SAML2MetaManager mgr = new SAML2MetaManager();
EntityDescriptorElement entity = mgr.getEntityDescriptor("/", NAME_IDP);
assert (entity != null);
SPSSODescriptorElement spElt = mgr.getSPSSODescriptor("/", NAME_IDP);
assert (spElt != null);
IDPSSODescriptorElement idpElt = mgr.getIDPSSODescriptor("/", NAME_IDP);
assert (idpElt != null);
XACMLPDPDescriptorElement pdpElt = mgr.getPolicyDecisionPointDescriptor("/", NAME_IDP);
assert (pdpElt != null);
XACMLAuthzDecisionQueryDescriptorElement pepElt = mgr.getPolicyEnforcementPointDescriptor("/", NAME_IDP);
assert (pepElt != null);
IDPSSOConfigElement idpConfig = mgr.getIDPSSOConfig("/", NAME_IDP);
assert (idpConfig != null);
SPSSOConfigElement spConfig = mgr.getSPSSOConfig("/", NAME_IDP);
assert (spConfig != null);
XACMLPDPConfigElement pdpConfig = mgr.getPolicyDecisionPointConfig("/", NAME_IDP);
assert (pdpConfig != null);
XACMLAuthzDecisionQueryConfigElement pepConfig = mgr.getPolicyEnforcementPointConfig("/", NAME_IDP);
assert (pepConfig != null);
exiting("importEntity");
}
use of com.sun.identity.saml2.jaxb.metadata.IDPSSODescriptorElement in project OpenAM by OpenRock.
the class ValidateSAML2 method validateIDP.
private void validateIDP() throws WorkflowException {
try {
SAML2MetaManager mm = SAML2Utils.getSAML2MetaManager();
IDPSSODescriptorElement elt = mm.getIDPSSODescriptor(realm, idpEntityId);
if (elt == null) {
Object[] param = { idpEntityId };
throw new WorkflowException("cannot.locate.idp", param);
}
if (idpMetaAlias != null) {
IDPSSOConfigElement idpConfig = mm.getIDPSSOConfig(realm, idpEntityId);
if (idpConfig == null) {
Object[] param = { idpEntityId };
throw new WorkflowException("cannot.locate.idp", param);
} else {
if (!idpConfig.getMetaAlias().equals(idpMetaAlias)) {
Object[] param = { idpEntityId };
throw new WorkflowException("cannot.locate.idp", param);
}
}
}
List ssoServiceList = elt.getSingleSignOnService();
idpBaseURL = getIDPBaseURL(ssoServiceList);
if (idpBaseURL == null) {
Object[] param = { idpEntityId };
throw new WorkflowException("cannot.locate.idp.loginURL", param);
}
validateURL(idpBaseURL);
} catch (SAML2MetaException ex) {
debug.error("ValidateSAML2: Error while validating IdP", ex);
Object[] param = { idpEntityId };
throw new WorkflowException("cannot.locate.idp", param);
}
}
use of com.sun.identity.saml2.jaxb.metadata.IDPSSODescriptorElement in project OpenAM by OpenRock.
the class SAML2Utils method verifyQueryString.
/**
* Verify Signed Query string.
*
* @param queryString URL query string that will be verified.
* @param realm realm of host entity.
* @param hostEntityRole entity role of host entity.
* @param remoteEntity entityID of peer entity.
* @return returns true if sign is valid.
* @throws SAML2Exception if error in verifying the signature.
*/
public static boolean verifyQueryString(String queryString, String realm, String hostEntityRole, String remoteEntity) throws SAML2Exception {
String method = "verifyQueryString : ";
if (debug.messageEnabled()) {
debug.message(method + "queryString :" + queryString);
}
Set<X509Certificate> signingCerts;
if (hostEntityRole.equalsIgnoreCase(SAML2Constants.IDP_ROLE)) {
SPSSODescriptorElement spSSODesc = saml2MetaManager.getSPSSODescriptor(realm, remoteEntity);
signingCerts = KeyUtil.getVerificationCerts(spSSODesc, remoteEntity, SAML2Constants.SP_ROLE);
} else {
IDPSSODescriptorElement idpSSODesc = saml2MetaManager.getIDPSSODescriptor(realm, remoteEntity);
signingCerts = KeyUtil.getVerificationCerts(idpSSODesc, remoteEntity, SAML2Constants.IDP_ROLE);
}
if (debug.messageEnabled()) {
debug.message(method + "realm is : " + realm);
debug.message(method + "Host Entity role is : " + hostEntityRole);
debug.message(method + "remoteEntity is : " + remoteEntity);
}
if (signingCerts.isEmpty()) {
debug.error("Incorrect configuration for Signing Certificate.");
throw new SAML2Exception(SAML2Utils.bundle.getString("metaDataError"));
}
return QuerySignatureUtil.verify(queryString, signingCerts);
}
use of com.sun.identity.saml2.jaxb.metadata.IDPSSODescriptorElement in project OpenAM by OpenRock.
the class DiscoveryBootstrap method getResourceOffering.
/**
* Gets the discovery bootstrap resource offering for the user.
* @return Discovery Resource Offering String
* @exception SAML2Exception if there's any failure.
*/
private String getResourceOffering(String authnContextClassRef, Subject subject, String wscID, String realm) throws SAML2Exception {
if (SAML2Utils.debug.messageEnabled()) {
SAML2Utils.debug.message("DiscoveryBootstrap.getResourceOffering:Init");
}
DiscoEntryElement discoEntry = DiscoServiceManager.getBootstrappingDiscoEntry();
if (discoEntry == null) {
throw new SAML2Exception(SAML2Utils.bundle.getString("missingUnivID"));
}
String[] values = null;
try {
values = SessionManager.getProvider().getProperty(session, Constants.UNIVERSAL_IDENTIFIER);
} catch (SessionException se) {
throw new SAML2Exception(se);
}
if ((values == null) || (values.length == 0)) {
throw new SAML2Exception(SAML2Utils.bundle.getString("missingDiscoOffering"));
}
String univID = values[0];
try {
ResourceOfferingType offering = discoEntry.getResourceOffering();
ServiceInstanceType serviceInstance = offering.getServiceInstance();
String providerID = serviceInstance.getProviderID();
if (!DiscoServiceManager.useImpliedResource()) {
ResourceIDMapper idMapper = DiscoServiceManager.getResourceIDMapper(providerID);
if (idMapper == null) {
idMapper = DiscoServiceManager.getDefaultResourceIDMapper();
}
ObjectFactory fac = new ObjectFactory();
ResourceIDType resourceID = fac.createResourceIDType();
String resourceIDValue = idMapper.getResourceID(providerID, univID);
if (SAML2Utils.debug.messageEnabled()) {
SAML2Utils.debug.message("DiscoveryBootstrap.getResourceOffering: " + "ResourceID Value:" + resourceIDValue);
}
resourceID.setValue(resourceIDValue);
offering.setResourceID(resourceID);
} else {
ObjectFactory fac = new com.sun.identity.liberty.ws.disco.jaxb.ObjectFactory();
ResourceIDType resourceID = fac.createResourceIDType();
resourceID.setValue(DiscoConstants.IMPLIED_RESOURCE);
offering.setResourceID(resourceID);
}
List discoEntryList = new ArrayList();
discoEntryList.add(discoEntry);
SessionSubject sessionSubject = null;
if (DiscoServiceManager.encryptNIinSessionContext()) {
IDPSSODescriptorElement idpSSODesc = SAML2Utils.getSAML2MetaManager().getIDPSSODescriptor(realm, providerID);
EncInfo encInfo = KeyUtil.getEncInfo(idpSSODesc, wscID, SAML2Constants.IDP_ROLE);
NameIdentifier ni = EncryptedNameIdentifier.getEncryptedNameIdentifier(convertSPNameID(subject.getNameID()), providerID, encInfo.getWrappingKey(), encInfo.getDataEncAlgorithm(), encInfo.getDataEncStrength());
sessionSubject = new SessionSubject(ni, convertSC(subject.getSubjectConfirmation()), convertIDPNameID(subject.getNameID()));
} else {
sessionSubject = new SessionSubject(convertSPNameID(subject.getNameID()), convertSC(subject.getSubjectConfirmation()), convertIDPNameID(subject.getNameID()));
}
AuthnContext authnContext = new AuthnContext(authnContextClassRef, null);
authnContext.setMinorVersion(IFSConstants.FF_12_PROTOCOL_MINOR_VERSION);
SessionContext invocatorSession = new SessionContext(sessionSubject, authnContext, providerID);
Map map = DiscoUtils.checkPolicyAndHandleDirectives(univID, null, discoEntryList, null, invocatorSession, wscID, session);
List offerings = (List) map.get(DiscoUtils.OFFERINGS);
if (offerings.isEmpty()) {
if (SAML2Utils.debug.messageEnabled()) {
SAML2Utils.debug.message("DiscoveryBootstrap.getResourceOffering:" + "no ResourceOffering");
}
throw new SAML2Exception(SAML2Utils.bundle.getString("missingDiscoOffering"));
}
ResourceOffering resourceOffering = (ResourceOffering) offerings.get(0);
assertions = (List) map.get(DiscoUtils.CREDENTIALS);
if (SAML2Utils.debug.messageEnabled()) {
SAML2Utils.debug.message("DiscoveryBootstrap.getResourceOffering: " + "Resource Offering:" + resourceOffering);
}
return resourceOffering.toString();
} catch (Exception ex) {
SAML2Utils.debug.error("DiscoveryBootstrap.getResourceOffering:" + "Exception while creating resource offering.", ex);
throw new SAML2Exception(ex);
}
}
use of com.sun.identity.saml2.jaxb.metadata.IDPSSODescriptorElement in project OpenAM by OpenRock.
the class DoManageNameID method getIDPManageNameIDConfig.
/**
* Returns first ManageNameID configuration in an entity under
* the realm.
* @param realm The realm under which the entity resides.
* @param entityId ID of the entity to be retrieved.
* @param binding bind type need to has to be matched.
* @return <code>ManageNameIDServiceElement</code> for the entity or null
* @throws SAML2MetaException if unable to retrieve the first identity
* provider's SSO configuration.
* @throws SessionException invalid or expired single-sign-on session
*/
public static ManageNameIDServiceElement getIDPManageNameIDConfig(String realm, String entityId, String binding) throws SAML2MetaException, SessionException {
ManageNameIDServiceElement mni = null;
IDPSSODescriptorElement idpSSODesc = metaManager.getIDPSSODescriptor(realm, entityId);
if (idpSSODesc == null) {
debug.error(SAML2Utils.bundle.getString("noIDPEntry"));
return null;
}
List list = idpSSODesc.getManageNameIDService();
if ((list != null) && !list.isEmpty()) {
if (binding == null) {
return (ManageNameIDServiceElement) list.get(0);
}
Iterator it = list.iterator();
while (it.hasNext()) {
mni = (ManageNameIDServiceElement) it.next();
if (binding.equalsIgnoreCase(mni.getBinding())) {
break;
}
}
}
return mni;
}
Aggregations