org.opensaml.saml2.core.Audience Java Examples
The following examples show how to use
org.opensaml.saml2.core.Audience.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SAML2SSOManager.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Validate the AudienceRestriction of SAML2 Response * * @param assertion SAML2 Assertion * @return validity */ protected void validateAudienceRestriction(Assertion assertion) throws SSOAgentException { if (assertion != null) { Conditions conditions = assertion.getConditions(); if (conditions != null) { List<AudienceRestriction> audienceRestrictions = conditions.getAudienceRestrictions(); if (audienceRestrictions != null && !audienceRestrictions.isEmpty()) { boolean audienceFound = false; for (AudienceRestriction audienceRestriction : audienceRestrictions) { if (audienceRestriction.getAudiences() != null && !audienceRestriction.getAudiences().isEmpty() ) { for (Audience audience : audienceRestriction.getAudiences()) { if (ssoAgentConfig.getSAML2().getSPEntityId().equals(audience.getAudienceURI())) { audienceFound = true; break; } } } if (audienceFound) { break; } } if (!audienceFound) { throw new SSOAgentException("SAML2 Assertion Audience Restriction validation failed"); } } else { throw new SSOAgentException("SAML2 Response doesn't contain AudienceRestrictions"); } } else { throw new SSOAgentException("SAML2 Response doesn't contain Conditions"); } } }
Example #2
Source File: DefaultSAML2SSOManager.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Validate the AudienceRestriction of SAML2 Response * * @param assertion SAML2 Assertion * @return validity */ private void validateAudienceRestriction(Assertion assertion) throws SAMLSSOException { if (assertion != null) { Conditions conditions = assertion.getConditions(); if (conditions != null) { List<AudienceRestriction> audienceRestrictions = conditions.getAudienceRestrictions(); if (audienceRestrictions != null && !audienceRestrictions.isEmpty()) { for (AudienceRestriction audienceRestriction : audienceRestrictions) { if (CollectionUtils.isNotEmpty(audienceRestriction.getAudiences())) { boolean audienceFound = false; for (Audience audience : audienceRestriction.getAudiences()) { if (properties.get(IdentityApplicationConstants.Authenticator.SAML2SSO.SP_ENTITY_ID) .equals(audience.getAudienceURI())) { audienceFound = true; break; } } if (!audienceFound) { throw new SAMLSSOException("SAML Assertion Audience Restriction validation failed"); } } else { throw new SAMLSSOException("SAML Response's AudienceRestriction doesn't contain Audiences"); } } } else { throw new SAMLSSOException("SAML Response doesn't contain AudienceRestrictions"); } } else { throw new SAMLSSOException("SAML Response doesn't contain Conditions"); } } }
Example #3
Source File: ConditionsGenerator.java From MaxKey with Apache License 2.0 | 5 votes |
public AudienceRestriction builderAudienceRestriction(String audienceUrl){ AudienceRestriction audienceRestriction = new AudienceRestrictionBuilder().buildObject(); Audience audience = new AudienceBuilder().buildObject(); audience.setAudienceURI(audienceUrl); audienceRestriction.getAudiences().add(audience); logger.debug("Audience URL "+audienceUrl); return audienceRestriction; }
Example #4
Source File: SAML2SSOAuthenticator.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Validate the AudienceRestriction of SAML2 Assertion * * @param assertion SAML2 Assertion * @return validity */ public boolean validateAudienceRestrictionInAssertion(Assertion assertion) { if (assertion != null) { Conditions conditions = assertion.getConditions(); if (conditions != null) { List<AudienceRestriction> audienceRestrictions = conditions.getAudienceRestrictions(); if (audienceRestrictions != null && !audienceRestrictions.isEmpty()) { for (AudienceRestriction audienceRestriction : audienceRestrictions) { if (audienceRestriction.getAudiences() != null && audienceRestriction.getAudiences().size() > 0) { for (Audience audience : audienceRestriction.getAudiences()) { String spId = org.wso2.carbon.identity.authenticator.saml2.sso.common.Util.getServiceProviderId(); if (spId == null) { org.wso2.carbon.identity.authenticator.saml2.sso.common.Util.initSSOConfigParams(); spId = org.wso2.carbon.identity.authenticator.saml2.sso.common.Util.getServiceProviderId(); } if (spId != null) { if (spId.equals(audience.getAudienceURI())) { return true; } } else { log.warn("No SAML2 service provider ID defined."); } } } else { log.warn("SAML2 Response's AudienceRestriction doesn't contain Audiences"); } } } else { log.error("SAML2 Response doesn't contain AudienceRestrictions"); } } else { log.error("SAML2 Response doesn't contain Conditions"); } } return false; }
Example #5
Source File: ProxyRestrictionUnmarshaller.java From lams with GNU General Public License v2.0 | 5 votes |
/** {@inheritDoc} */ protected void processChildElement(XMLObject parentObject, XMLObject childObject) throws UnmarshallingException { ProxyRestriction proxyRestriction = (ProxyRestriction) parentObject; if (childObject instanceof Audience) { proxyRestriction.getAudiences().add((Audience) childObject); } else { super.processChildElement(parentObject, childObject); } }
Example #6
Source File: AudienceRestrictionUnmarshaller.java From lams with GNU General Public License v2.0 | 5 votes |
/** {@inheritDoc} */ protected void processChildElement(XMLObject parentObject, XMLObject childObject) throws UnmarshallingException { AudienceRestriction audienceRestriction = (AudienceRestriction) parentObject; if (childObject instanceof Audience) { audienceRestriction.getAudiences().add((Audience) childObject); } else { super.processChildElement(parentObject, childObject); } }
Example #7
Source File: AudienceUnmarshaller.java From lams with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ protected void processElementContent(XMLObject samlObject, String elementContent) { Audience audience = (Audience) samlObject; audience.setAudienceURI(elementContent); }
Example #8
Source File: AudienceMarshaller.java From lams with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ protected void marshallElementContent(XMLObject samlObject, Element domElement) throws MarshallingException { Audience audience = (Audience) samlObject; XMLHelper.appendTextContent(domElement, audience.getAudienceURI()); }
Example #9
Source File: ProxyRestrictionImpl.java From lams with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public List<Audience> getAudiences() { return audiences; }
Example #10
Source File: AudienceBuilder.java From lams with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public Audience buildObject() { return buildObject(SAMLConstants.SAML20_NS, Audience.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX); }
Example #11
Source File: AudienceBuilder.java From lams with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public Audience buildObject(String namespaceURI, String localName, String namespacePrefix) { return new AudienceImpl(namespaceURI, localName, namespacePrefix); }
Example #12
Source File: AudienceSchemaValidator.java From lams with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public void validate(Audience audience) throws ValidationException { validateAudienceURI(audience); }
Example #13
Source File: AudienceRestrictionImpl.java From lams with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public List<Audience> getAudiences() { return audience; }
Example #14
Source File: OAuth2SAMLWorkflowSample.java From jam-collaboration-sample with Apache License 2.0 | 4 votes |
private static Assertion buildSAML2Assertion(boolean includeClientKeyAttribute) { // Bootstrap the OpenSAML library try { DefaultBootstrap.bootstrap(); } catch (ConfigurationException e) { } DateTime issueInstant = new DateTime(); DateTime notOnOrAfter = issueInstant.plusMinutes(10); DateTime notBefore = issueInstant.minusMinutes(10); NameID nameID = (new NameIDBuilder().buildObject()); if (SUBJECT_NAME_ID_FORMAT.equals("email")) { nameID.setFormat(NameIDType.EMAIL); } else if (SUBJECT_NAME_ID_FORMAT.equals("unspecified")) { nameID.setFormat(NameIDType.UNSPECIFIED); } else { throw new IllegalArgumentException("SUBJECT_NAME_ID_FORMAT must be 'email' or 'unspecified'."); } if (subjectNameIdQualifier != null) { nameID.setNameQualifier(subjectNameIdQualifier); } nameID.setValue(SUBJECT_NAME_ID); SubjectConfirmationData subjectConfirmationData = (new SubjectConfirmationDataBuilder().buildObject()); subjectConfirmationData.setRecipient(BASE_URL + ACCESS_TOKEN_URL_PATH); subjectConfirmationData.setNotOnOrAfter(notOnOrAfter); SubjectConfirmation subjectConfirmation = (new SubjectConfirmationBuilder().buildObject()); subjectConfirmation.setMethod(SubjectConfirmation.METHOD_BEARER); subjectConfirmation.setSubjectConfirmationData(subjectConfirmationData); Subject subject = (new SubjectBuilder().buildObject()); subject.setNameID(nameID); subject.getSubjectConfirmations().add(subjectConfirmation); Issuer issuer = (new IssuerBuilder().buildObject()); issuer.setValue(IDP_ID); Audience audience = (new AudienceBuilder().buildObject()); audience.setAudienceURI(SP_ID_JAM); AudienceRestriction audienceRestriction = (new AudienceRestrictionBuilder().buildObject()); audienceRestriction.getAudiences().add(audience); Conditions conditions = (new ConditionsBuilder().buildObject()); conditions.setNotBefore(notBefore); conditions.setNotOnOrAfter(notOnOrAfter); conditions.getAudienceRestrictions().add(audienceRestriction); Assertion assertion = (new AssertionBuilder().buildObject()); assertion.setID(UUID.randomUUID().toString()); assertion.setVersion(SAMLVersion.VERSION_20); assertion.setIssueInstant(issueInstant); assertion.setIssuer(issuer); assertion.setSubject(subject); assertion.setConditions(conditions); if (includeClientKeyAttribute) { XSString attributeValue = (XSString)Configuration.getBuilderFactory().getBuilder(XSString.TYPE_NAME).buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); attributeValue.setValue(CLIENT_KEY); Attribute attribute = (new AttributeBuilder().buildObject()); attribute.setName("client_id"); attribute.getAttributeValues().add(attributeValue); AttributeStatement attributeStatement = (new AttributeStatementBuilder().buildObject()); attributeStatement.getAttributes().add(attribute); assertion.getAttributeStatements().add(attributeStatement); } return assertion; }
Example #15
Source File: OAuth2SAMLWorkflowSample.java From jam-collaboration-sample with Apache License 2.0 | 4 votes |
private static Assertion buildSAML2Assertion( String baseUrl, String subjectNameId, String subjectNameIdFormat, String subjectNameIdQualifier, String idpId, String clientKey, boolean includeClientKeyAttribute) { // Bootstrap the OpenSAML library try { DefaultBootstrap.bootstrap(); } catch (ConfigurationException e) { } DateTime issueInstant = new DateTime(); DateTime notOnOrAfter = issueInstant.plusMinutes(10); DateTime notBefore = issueInstant.minusMinutes(10); NameID nameID = (new NameIDBuilder().buildObject()); if (subjectNameIdFormat.equals("email")) { nameID.setFormat(NameIDType.EMAIL); } else if (subjectNameIdFormat.equals("unspecified")) { nameID.setFormat(NameIDType.UNSPECIFIED); } else { throw new IllegalArgumentException("subjectNameIdFormat must be 'email' or 'unspecified'."); } if (subjectNameIdQualifier != null) { nameID.setNameQualifier(subjectNameIdQualifier); } nameID.setValue(subjectNameId); SubjectConfirmationData subjectConfirmationData = (new SubjectConfirmationDataBuilder().buildObject()); subjectConfirmationData.setRecipient(baseUrl + ACCESS_TOKEN_URL_PATH); subjectConfirmationData.setNotOnOrAfter(notOnOrAfter); SubjectConfirmation subjectConfirmation = (new SubjectConfirmationBuilder().buildObject()); subjectConfirmation.setMethod(SubjectConfirmation.METHOD_BEARER); subjectConfirmation.setSubjectConfirmationData(subjectConfirmationData); Subject subject = (new SubjectBuilder().buildObject()); subject.setNameID(nameID); subject.getSubjectConfirmations().add(subjectConfirmation); Issuer issuer = (new IssuerBuilder().buildObject()); issuer.setValue(idpId); Audience audience = (new AudienceBuilder().buildObject()); audience.setAudienceURI(SP_ID_JAM); AudienceRestriction audienceRestriction = (new AudienceRestrictionBuilder().buildObject()); audienceRestriction.getAudiences().add(audience); Conditions conditions = (new ConditionsBuilder().buildObject()); conditions.setNotBefore(notBefore); conditions.setNotOnOrAfter(notOnOrAfter); conditions.getAudienceRestrictions().add(audienceRestriction); Assertion assertion = (new AssertionBuilder().buildObject()); assertion.setID(UUID.randomUUID().toString()); assertion.setVersion(SAMLVersion.VERSION_20); assertion.setIssueInstant(issueInstant); assertion.setIssuer(issuer); assertion.setSubject(subject); assertion.setConditions(conditions); if (includeClientKeyAttribute) { XSString attributeValue = (XSString)Configuration.getBuilderFactory().getBuilder(XSString.TYPE_NAME).buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); attributeValue.setValue(clientKey); Attribute attribute = (new AttributeBuilder().buildObject()); attribute.setName("client_id"); attribute.getAttributeValues().add(attributeValue); AttributeStatement attributeStatement = (new AttributeStatementBuilder().buildObject()); attributeStatement.getAttributes().add(attribute); assertion.getAttributeStatements().add(attributeStatement); } return assertion; }
Example #16
Source File: OAuth2SAMLUtil.java From jam-collaboration-sample with Apache License 2.0 | 4 votes |
public static String buildSignedSAML2Assertion( final String idpId, final String destinationUri, final String subjectNameId, final String subjectNameIdFormat, final String subjectNameIdQualifier, final PrivateKey idpPrivateKey, final X509Certificate idpCertificate, final String spJamId, final Map<String, List<Object>> attributes) throws Exception { // Bootstrap the OpenSAML library try { DefaultBootstrap.bootstrap(); } catch (ConfigurationException e) { } DateTime issueInstant = new DateTime(); DateTime notOnOrAfter = issueInstant.plusMinutes(10); DateTime notBefore = issueInstant.minusMinutes(10); NameID nameID = makeEmailFormatName(subjectNameId, subjectNameIdFormat, subjectNameIdQualifier); SubjectConfirmationData subjectConfirmationData = (new SubjectConfirmationDataBuilder().buildObject()); subjectConfirmationData.setRecipient(destinationUri); subjectConfirmationData.setNotOnOrAfter(notOnOrAfter); SubjectConfirmation subjectConfirmation = (new SubjectConfirmationBuilder().buildObject()); subjectConfirmation.setMethod(SubjectConfirmation.METHOD_BEARER); subjectConfirmation.setSubjectConfirmationData(subjectConfirmationData); Subject subject = (new SubjectBuilder().buildObject()); subject.setNameID(nameID); subject.getSubjectConfirmations().add(subjectConfirmation); Issuer issuer = (new IssuerBuilder().buildObject()); issuer.setValue(idpId); Audience audience = (new AudienceBuilder().buildObject()); audience.setAudienceURI(spJamId); AudienceRestriction audienceRestriction = (new AudienceRestrictionBuilder().buildObject()); audienceRestriction.getAudiences().add(audience); Conditions conditions = (new ConditionsBuilder().buildObject()); conditions.setNotBefore(notBefore); conditions.setNotOnOrAfter(notOnOrAfter); conditions.getAudienceRestrictions().add(audienceRestriction); Assertion assertion = (new AssertionBuilder().buildObject()); assertion.setID(UUID.randomUUID().toString()); assertion.setVersion(SAMLVersion.VERSION_20); assertion.setIssueInstant(issueInstant); assertion.setIssuer(issuer); assertion.setSubject(subject); assertion.setConditions(conditions); return signAssertion(assertion, idpPrivateKey); }
Example #17
Source File: SAML2TokenBuilder.java From carbon-identity with Apache License 2.0 | 4 votes |
@Override public void createSAMLAssertion(DateTime notAfter, DateTime notBefore, String assertionId) throws IdentityProviderException { assertion = (Assertion) buildXMLObject(Assertion.DEFAULT_ELEMENT_NAME); Conditions conditions = (Conditions) buildXMLObject(Conditions.DEFAULT_ELEMENT_NAME); conditions.setNotBefore(notBefore); conditions.setNotOnOrAfter(notAfter); ServerConfiguration config = ServerConfiguration.getInstance(); String host = "http://" + config.getFirstProperty("HostName"); Issuer issuer = (Issuer) buildXMLObject(Issuer.DEFAULT_ELEMENT_NAME); issuer.setValue(host); assertion.setIssuer(issuer); assertion.setIssueInstant(new DateTime()); if (appilesTo != null) { Audience audience = (Audience) buildXMLObject(Audience.DEFAULT_ELEMENT_NAME); audience.setAudienceURI(appilesTo); AudienceRestriction audienceRestrictions = (AudienceRestriction) buildXMLObject(AudienceRestriction.DEFAULT_ELEMENT_NAME); audienceRestrictions.getAudiences().add(audience); conditions.getAudienceRestrictions().add(audienceRestrictions); } assertion.setConditions(conditions); assertion.getAttributeStatements().add(this.attributeStmt); assertion.setID(assertionId); Subject subject = (Subject) buildXMLObject(Subject.DEFAULT_ELEMENT_NAME); SubjectConfirmation subjectConf = (SubjectConfirmation) buildXMLObject(SubjectConfirmation.DEFAULT_ELEMENT_NAME); SubjectConfirmationData confData = (SubjectConfirmationData) buildXMLObject(SubjectConfirmationData.DEFAULT_ELEMENT_NAME); confData.setAddress(CONF_KEY); subjectConf.setSubjectConfirmationData(confData); subject.getSubjectConfirmations().add(subjectConf); assertion.setSubject(subject); }
Example #18
Source File: AudienceRestrictionImpl.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Constructor. * * @param namespaceURI the namespace the element is in * @param elementLocalName the local name of the XML element this Object represents * @param namespacePrefix the prefix for the given namespace */ protected AudienceRestrictionImpl(String namespaceURI, String elementLocalName, String namespacePrefix) { super(namespaceURI, elementLocalName, namespacePrefix); audience = new XMLObjectChildrenList<Audience>(this); }
Example #19
Source File: ProxyRestrictionImpl.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Constructor. * * @param namespaceURI the namespace the element is in * @param elementLocalName the local name of the XML element this Object represents * @param namespacePrefix the prefix for the given namespace */ protected ProxyRestrictionImpl(String namespaceURI, String elementLocalName, String namespacePrefix) { super(namespaceURI, elementLocalName, namespacePrefix); audiences = new XMLObjectChildrenList<Audience>(this); }
Example #20
Source File: AudienceSchemaValidator.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Checks that the AudienceURI is present. * * @param audience * @throws ValidationException */ protected void validateAudienceURI(Audience audience) throws ValidationException { if (DatatypeHelper.isEmpty(audience.getAudienceURI())) { throw new ValidationException("AudienceURI required"); } }