本文整理汇总了Java中org.opensaml.saml2.core.Conditions类的典型用法代码示例。如果您正苦于以下问题:Java Conditions类的具体用法?Java Conditions怎么用?Java Conditions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Conditions类属于org.opensaml.saml2.core包,在下文中一共展示了Conditions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processChildElement
import org.opensaml.saml2.core.Conditions; //导入依赖的package包/类
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentObject, XMLObject childObject) throws UnmarshallingException {
Assertion assertion = (Assertion) parentObject;
if (childObject instanceof Issuer) {
assertion.setIssuer((Issuer) childObject);
} else if (childObject instanceof Signature) {
assertion.setSignature((Signature) childObject);
} else if (childObject instanceof Subject) {
assertion.setSubject((Subject) childObject);
} else if (childObject instanceof Conditions) {
assertion.setConditions((Conditions) childObject);
} else if (childObject instanceof Advice) {
assertion.setAdvice((Advice) childObject);
} else if (childObject instanceof Statement) {
assertion.getStatements().add((Statement) childObject);
} else {
super.processChildElement(parentObject, childObject);
}
}
示例2: processChildElement
import org.opensaml.saml2.core.Conditions; //导入依赖的package包/类
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
throws UnmarshallingException {
AuthnRequest req = (AuthnRequest) parentSAMLObject;
if (childSAMLObject instanceof Subject) {
req.setSubject((Subject) childSAMLObject);
} else if (childSAMLObject instanceof NameIDPolicy) {
req.setNameIDPolicy((NameIDPolicy) childSAMLObject);
} else if (childSAMLObject instanceof Conditions) {
req.setConditions((Conditions) childSAMLObject);
} else if (childSAMLObject instanceof RequestedAuthnContext) {
req.setRequestedAuthnContext((RequestedAuthnContext) childSAMLObject);
} else if (childSAMLObject instanceof Scoping) {
req.setScoping((Scoping) childSAMLObject);
} else {
super.processChildElement(parentSAMLObject, childSAMLObject);
}
}
示例3: testChildElementsMarshall
import org.opensaml.saml2.core.Conditions; //导入依赖的package包/类
/** {@inheritDoc} */
public void testChildElementsMarshall() {
QName qname = new QName(SAMLConstants.SAML20_NS, Conditions.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX);
Conditions conditions = (Conditions) buildXMLObject(qname);
QName oneTimeUserQName = new QName(SAMLConstants.SAML20_NS, OneTimeUse.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX);
conditions.getConditions().add((Condition) buildXMLObject(oneTimeUserQName));
QName audienceRestrictionQName = new QName(SAMLConstants.SAML20_NS, AudienceRestriction.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX);
for (int i = 0; i < audienceRestrictionCount; i++) {
conditions.getAudienceRestrictions().add((AudienceRestriction) buildXMLObject(audienceRestrictionQName));
}
conditions.getConditions().add((Condition) buildXMLObject(oneTimeUserQName));
QName proxyRestrictionQName = new QName(SAMLConstants.SAML20_NS, ProxyRestriction.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX);
conditions.getConditions().add((Condition) buildXMLObject(proxyRestrictionQName));
assertEquals(expectedChildElementsDOM, conditions);
}
示例4: testChildElementsMarshall
import org.opensaml.saml2.core.Conditions; //导入依赖的package包/类
/** {@inheritDoc} */
public void testChildElementsMarshall() {
QName qname = new QName(SAMLConstants.SAML20P_NS, AuthnRequest.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20P_PREFIX);
AuthnRequest req = (AuthnRequest) buildXMLObject(qname);
super.populateChildElements(req);
QName subjectQName = new QName(SAMLConstants.SAML20_NS, Subject.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX);
req.setSubject((Subject) buildXMLObject(subjectQName));
QName nameIDPolicyQName = new QName(SAMLConstants.SAML20P_NS, NameIDPolicy.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20P_PREFIX);
req.setNameIDPolicy((NameIDPolicy) buildXMLObject(nameIDPolicyQName));
QName conditionsQName = new QName(SAMLConstants.SAML20_NS, Conditions.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX);
req.setConditions((Conditions) buildXMLObject(conditionsQName));
QName requestedAuthnContextQName = new QName(SAMLConstants.SAML20P_NS, RequestedAuthnContext.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20P_PREFIX);
req.setRequestedAuthnContext((RequestedAuthnContext) buildXMLObject(requestedAuthnContextQName));
QName scopingQName = new QName(SAMLConstants.SAML20P_NS, Scoping.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20P_PREFIX);
req.setScoping((Scoping) buildXMLObject(scopingQName));
assertEquals(expectedChildElementsDOM, req);
}
示例5: validateOneTimeUseCondition
import org.opensaml.saml2.core.Conditions; //导入依赖的package包/类
/**
* Checks that there is at most one OneTimeUse condition.
*
* @param conditions
* @throws ValidationException
*/
protected void validateOneTimeUseCondition(Conditions conditions) throws ValidationException {
int oneTimeUseCount = 0;
for (int i = 0; i < conditions.getConditions().size(); i++) {
if (conditions.getConditions().get(i) instanceof OneTimeUse) {
oneTimeUseCount++;
}
}
if (oneTimeUseCount > 1) {
throw new ValidationException("At most one instance of OneTimeUse allowed");
}
}
示例6: validateProxyRestrictionCondition
import org.opensaml.saml2.core.Conditions; //导入依赖的package包/类
protected void validateProxyRestrictionCondition(Conditions conditions) throws ValidationException {
int proxyRestrictionCount = 0;
for (int i = 0; i < conditions.getConditions().size(); i++) {
if (conditions.getConditions().get(i) instanceof ProxyRestriction) {
proxyRestrictionCount++;
}
}
if (proxyRestrictionCount > 1) {
throw new ValidationException("At most one instance of ProxyRestriction allowed");
}
}
示例7: marshallAttributes
import org.opensaml.saml2.core.Conditions; //导入依赖的package包/类
/** {@inheritDoc} */
protected void marshallAttributes(XMLObject samlObject, Element domElement) throws MarshallingException {
Conditions conditions = (Conditions) samlObject;
if (conditions.getNotBefore() != null) {
String notBeforeStr = Configuration.getSAMLDateFormatter().print(conditions.getNotBefore());
domElement.setAttributeNS(null, Conditions.NOT_BEFORE_ATTRIB_NAME, notBeforeStr);
}
if (conditions.getNotOnOrAfter() != null) {
String notOnOrAfterStr = Configuration.getSAMLDateFormatter().print(conditions.getNotOnOrAfter());
domElement.setAttributeNS(null, Conditions.NOT_ON_OR_AFTER_ATTRIB_NAME, notOnOrAfterStr);
}
}
示例8: processChildElement
import org.opensaml.saml2.core.Conditions; //导入依赖的package包/类
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentObject, XMLObject childObject) throws UnmarshallingException {
Conditions conditions = (Conditions) parentObject;
if (childObject instanceof Condition) {
conditions.getConditions().add((Condition) childObject);
} else {
super.processChildElement(parentObject, childObject);
}
}
示例9: processAttribute
import org.opensaml.saml2.core.Conditions; //导入依赖的package包/类
/** {@inheritDoc} */
protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
Conditions conditions = (Conditions) samlObject;
if (attribute.getLocalName().equals(Conditions.NOT_BEFORE_ATTRIB_NAME)
&& !DatatypeHelper.isEmpty(attribute.getValue())) {
conditions.setNotBefore(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
} else if (attribute.getLocalName().equals(Conditions.NOT_ON_OR_AFTER_ATTRIB_NAME)
&& !DatatypeHelper.isEmpty(attribute.getValue())) {
conditions.setNotOnOrAfter(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
} else {
super.processAttribute(samlObject, attribute);
}
}
示例10: enforceConditions
import org.opensaml.saml2.core.Conditions; //导入依赖的package包/类
private void enforceConditions(Conditions conditions) throws SamlException {
DateTime now = this.now != null ? this.now : DateTime.now();
if (now.isBefore(conditions.getNotBefore())) {
throw new SamlException(
"The assertion cannot be used before " + conditions.getNotBefore().toString());
}
if (now.isAfter(conditions.getNotOnOrAfter())) {
throw new SamlException(
"The assertion cannot be used after " + conditions.getNotOnOrAfter().toString());
}
}
示例11: validateAudienceRestriction
import org.opensaml.saml2.core.Conditions; //导入依赖的package包/类
/**
* 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");
}
}
}
示例12: createAudienceCondition
import org.opensaml.saml2.core.Conditions; //导入依赖的package包/类
/**
* Create SAML Conditions with an audience element.
*
* @param audienceURI
* The value of the audience element
* @return The SAML Conditions with the given audience element
*/
public static Conditions createAudienceCondition(String audienceURI) {
Audience audience = buildXMLObject(Audience.class);
audience.setAudienceURI(audienceURI);
AudienceRestriction audienceRestriction = buildXMLObject(AudienceRestriction.class);
audienceRestriction.getAudiences().add(audience);
Conditions conditions = buildXMLObject(Conditions.class);
conditions.getAudienceRestrictions().add(audienceRestriction);
return conditions;
}
示例13: testCreateAudienceCondition
import org.opensaml.saml2.core.Conditions; //导入依赖的package包/类
@Test
public void testCreateAudienceCondition() {
Conditions ac = SAMLUtil.createAudienceCondition("uri");
assertNotNull(ac);
assertEquals(1, ac.getConditions().size());
assertNull(ac.getNotBefore());
assertNull(ac.getNotOnOrAfter());
assertNull(ac.getProxyRestriction());
assertNull(ac.getOneTimeUse());
AudienceRestriction ar = ac.getAudienceRestrictions().get(0);
assertEquals(1, ar.getAudiences().size());
Audience audience = ar.getAudiences().get(0);
assertEquals("uri", audience.getAudienceURI());
}
示例14: validateAudienceRestriction
import org.opensaml.saml2.core.Conditions; //导入依赖的package包/类
/**
* 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");
}
}
}
示例15: validateAudienceRestrictionInAssertion
import org.opensaml.saml2.core.Conditions; //导入依赖的package包/类
/**
* 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;
}