本文整理汇总了Java中org.opensaml.saml2.core.AuthnContextClassRef.setAuthnContextClassRef方法的典型用法代码示例。如果您正苦于以下问题:Java AuthnContextClassRef.setAuthnContextClassRef方法的具体用法?Java AuthnContextClassRef.setAuthnContextClassRef怎么用?Java AuthnContextClassRef.setAuthnContextClassRef使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opensaml.saml2.core.AuthnContextClassRef
的用法示例。
在下文中一共展示了AuthnContextClassRef.setAuthnContextClassRef方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAuthnContextClassRef
import org.opensaml.saml2.core.AuthnContextClassRef; //导入方法依赖的package包/类
@Test
public void getAuthnContextClassRef() {
String expectedAuthnContextClassRefString = "expected string";
AuthnContextClassRef authnContextClassRef = new AuthnContextClassRefStubImpl();
authnContextClassRef.setAuthnContextClassRef(expectedAuthnContextClassRefString);
AuthnContext authnContext = new AuthnContextStubImpl();
authnContext.setAuthnContextClassRef(authnContextClassRef);
AuthnStatement authnStatement= new AuthnStatementStubImpl();
authnStatement.setAuthnContext(authnContext);
List<AuthnStatement> authnStatements = new ArrayList<AuthnStatement>();
authnStatements.add(authnStatement);
Assertion assertion = new AssertionStubImpl(authnStatements);
assertEquals(expectedAuthnContextClassRefString, new OIOAssertion(assertion).getAuthnContextClassRef());
}
示例2: createAuthnStatement
import org.opensaml.saml2.core.AuthnContextClassRef; //导入方法依赖的package包/类
private AuthnStatement createAuthnStatement(final DateTime issueDate) {
// create authcontextclassref object
AuthnContextClassRefBuilder classRefBuilder = new AuthnContextClassRefBuilder();
AuthnContextClassRef classRef = classRefBuilder.buildObject();
classRef.setAuthnContextClassRef("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport");
// create authcontext object
AuthnContextBuilder authContextBuilder = new AuthnContextBuilder();
AuthnContext authnContext = authContextBuilder.buildObject();
authnContext.setAuthnContextClassRef(classRef);
// create authenticationstatement object
AuthnStatementBuilder authStatementBuilder = new AuthnStatementBuilder();
AuthnStatement authnStatement = authStatementBuilder.buildObject();
authnStatement.setAuthnInstant(issueDate);
authnStatement.setAuthnContext(authnContext);
return authnStatement;
}
示例3: buildRequestedAuthnContext
import org.opensaml.saml2.core.AuthnContextClassRef; //导入方法依赖的package包/类
private RequestedAuthnContext buildRequestedAuthnContext() {
// Create AuthnContextClassRef
AuthnContextClassRefBuilder authnContextClassRefBuilder = new AuthnContextClassRefBuilder();
AuthnContextClassRef authnContextClassRef = authnContextClassRefBuilder.buildObject(SAML2_ASSERTION, "AuthnContextClassRef", "saml");
authnContextClassRef.setAuthnContextClassRef(SAML2_PASSWORD_PROTECTED_TRANSPORT);
// Create RequestedAuthnContext
RequestedAuthnContextBuilder requestedAuthnContextBuilder = new RequestedAuthnContextBuilder();
RequestedAuthnContext requestedAuthnContext = requestedAuthnContextBuilder.buildObject();
requestedAuthnContext.setComparison(AuthnContextComparisonTypeEnumeration.EXACT);
requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef);
return requestedAuthnContext;
}
示例4: createAuthnContext
import org.opensaml.saml2.core.AuthnContextClassRef; //导入方法依赖的package包/类
/**
* Create an authnContext with a given authnContextClassRef.
*
* @param authnContextClassRefValue
* The value of the authnContextClassRef
* @return The SAML authnContext with the given authnContextClassRef
*/
public static AuthnContext createAuthnContext(
String authnContextClassRefValue) {
AuthnContext authnContext = buildXMLObject(AuthnContext.class);
AuthnContextClassRef authnContextClassRef = buildXMLObject(AuthnContextClassRef.class);
authnContextClassRef.setAuthnContextClassRef(authnContextClassRefValue);
authnContext.setAuthnContextClassRef(authnContextClassRef);
return authnContext;
}
示例5: testURIFailure
import org.opensaml.saml2.core.AuthnContextClassRef; //导入方法依赖的package包/类
/**
* Tests absent Class Reference failure.
*
* @throws ValidationException
*/
public void testURIFailure() throws ValidationException {
AuthnContextClassRef authnContextClassRef = (AuthnContextClassRef) target;
authnContextClassRef.setAuthnContextClassRef(null);
assertValidationFail("ClassRef was null, should raise a Validation Exception");
authnContextClassRef.setAuthnContextClassRef("");
assertValidationFail("ClassRef was empty string, should raise a Validation Exception");
authnContextClassRef.setAuthnContextClassRef(" ");
assertValidationFail("ClassRef was white space, should raise a Validation Exception");
}
示例6: testSingleElementMarshall
import org.opensaml.saml2.core.AuthnContextClassRef; //导入方法依赖的package包/类
/** {@inheritDoc} */
public void testSingleElementMarshall() {
QName qname = new QName(SAMLConstants.SAML20_NS, AuthnContextClassRef.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX);
AuthnContextClassRef authnContextClassRef = (AuthnContextClassRef) buildXMLObject(qname);
authnContextClassRef.setAuthnContextClassRef(expectedClassRef);
assertEquals(expectedDOM, authnContextClassRef);
}
示例7: buildAuthnRequestObject
import org.opensaml.saml2.core.AuthnContextClassRef; //导入方法依赖的package包/类
public static AuthnRequest buildAuthnRequestObject(final String authnId, final String spId, final String idpUrl, final String consumerUrl) {
// Issuer object
IssuerBuilder issuerBuilder = new IssuerBuilder();
Issuer issuer = issuerBuilder.buildObject();
issuer.setValue(spId);
// AuthnContextClass
AuthnContextClassRefBuilder authnContextClassRefBuilder = new AuthnContextClassRefBuilder();
AuthnContextClassRef authnContextClassRef = authnContextClassRefBuilder.buildObject(
SAMLConstants.SAML20_NS,
"AuthnContextClassRef", "saml");
authnContextClassRef.setAuthnContextClassRef(AuthnContext.PPT_AUTHN_CTX);
// AuthnContext
RequestedAuthnContextBuilder requestedAuthnContextBuilder = new RequestedAuthnContextBuilder();
RequestedAuthnContext requestedAuthnContext = requestedAuthnContextBuilder.buildObject();
requestedAuthnContext.setComparison(AuthnContextComparisonTypeEnumeration.EXACT);
requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef);
// Creation of AuthRequestObject
AuthnRequestBuilder authRequestBuilder = new AuthnRequestBuilder();
AuthnRequest authnRequest = authRequestBuilder.buildObject();
authnRequest.setID(authnId);
authnRequest.setDestination(idpUrl);
authnRequest.setVersion(SAMLVersion.VERSION_20);
authnRequest.setForceAuthn(false);
authnRequest.setIsPassive(false);
authnRequest.setIssueInstant(new DateTime());
authnRequest.setProtocolBinding(SAMLConstants.SAML2_POST_BINDING_URI);
authnRequest.setAssertionConsumerServiceURL(consumerUrl);
authnRequest.setProviderName(spId);
authnRequest.setIssuer(issuer);
authnRequest.setRequestedAuthnContext(requestedAuthnContext);
return authnRequest;
}
示例8: buildAuthnStatement
import org.opensaml.saml2.core.AuthnContextClassRef; //导入方法依赖的package包/类
private AuthnStatement buildAuthnStatement() throws IllegalAccessException {
AuthnStatement authnStatement = buildXMLObjectDefaultName(AuthnStatement.class);
AuthnContext authnContext = buildXMLObjectDefaultName(AuthnContext.class);
AuthnContextClassRef authnContextClassRef = buildXMLObjectDefaultName(AuthnContextClassRef.class);
authnContextClassRef.setAuthnContextClassRef("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport");
authnContext.setAuthnContextClassRef(authnContextClassRef);
authnStatement.setAuthnContext(authnContext);
authnStatement.setAuthnInstant(new DateTime());
return authnStatement;
}
示例9: processElementContent
import org.opensaml.saml2.core.AuthnContextClassRef; //导入方法依赖的package包/类
/** {@inheritDoc} */
protected void processElementContent(XMLObject samlObject, String elementContent) {
AuthnContextClassRef authnContextClassRef = (AuthnContextClassRef) samlObject;
authnContextClassRef.setAuthnContextClassRef(elementContent);
}
示例10: buildAuthnRequest
import org.opensaml.saml2.core.AuthnContextClassRef; //导入方法依赖的package包/类
protected AuthnRequest buildAuthnRequest(HttpServletRequest request) throws SSOAgentException {
IssuerBuilder issuerBuilder = new IssuerBuilder();
Issuer issuer =
issuerBuilder.buildObject("urn:oasis:names:tc:SAML:2.0:assertion",
"Issuer", "samlp");
issuer.setValue(ssoAgentConfig.getSAML2().getSPEntityId());
/* NameIDPolicy */
NameIDPolicyBuilder nameIdPolicyBuilder = new NameIDPolicyBuilder();
NameIDPolicy nameIdPolicy = nameIdPolicyBuilder.buildObject();
nameIdPolicy.setFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent");
nameIdPolicy.setSPNameQualifier("Issuer");
nameIdPolicy.setAllowCreate(true);
/* AuthnContextClass */
AuthnContextClassRefBuilder authnContextClassRefBuilder = new AuthnContextClassRefBuilder();
AuthnContextClassRef authnContextClassRef =
authnContextClassRefBuilder.buildObject("urn:oasis:names:tc:SAML:2.0:assertion",
"AuthnContextClassRef",
"saml");
authnContextClassRef.setAuthnContextClassRef("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport");
/* AuthnContex */
RequestedAuthnContextBuilder requestedAuthnContextBuilder =
new RequestedAuthnContextBuilder();
RequestedAuthnContext requestedAuthnContext = requestedAuthnContextBuilder.buildObject();
requestedAuthnContext.setComparison(AuthnContextComparisonTypeEnumeration.EXACT);
requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef);
DateTime issueInstant = new DateTime();
/* Creation of AuthRequestObject */
AuthnRequestBuilder authRequestBuilder = new AuthnRequestBuilder();
AuthnRequest authRequest =
authRequestBuilder.buildObject("urn:oasis:names:tc:SAML:2.0:protocol",
"AuthnRequest", "samlp");
authRequest.setForceAuthn(ssoAgentConfig.getSAML2().isForceAuthn());
authRequest.setIsPassive(ssoAgentConfig.getSAML2().isPassiveAuthn());
authRequest.setIssueInstant(issueInstant);
authRequest.setProtocolBinding(ssoAgentConfig.getSAML2().getHttpBinding());
authRequest.setAssertionConsumerServiceURL(ssoAgentConfig.getSAML2().getACSURL());
authRequest.setIssuer(issuer);
authRequest.setNameIDPolicy(nameIdPolicy);
authRequest.setRequestedAuthnContext(requestedAuthnContext);
authRequest.setID(SSOAgentUtils.createID());
authRequest.setVersion(SAMLVersion.VERSION_20);
authRequest.setDestination(ssoAgentConfig.getSAML2().getIdPURL());
if (request.getAttribute(Extensions.LOCAL_NAME) != null) {
authRequest.setExtensions((Extensions) request.getAttribute(Extensions.LOCAL_NAME));
}
/* Requesting Attributes. This Index value is registered in the IDP */
if (ssoAgentConfig.getSAML2().getAttributeConsumingServiceIndex() != null &&
ssoAgentConfig.getSAML2().getAttributeConsumingServiceIndex().trim().length() > 0) {
authRequest.setAttributeConsumingServiceIndex(Integer.parseInt(
ssoAgentConfig.getSAML2().getAttributeConsumingServiceIndex()));
}
return authRequest;
}
示例11: buildSAMLAssertion
import org.opensaml.saml2.core.AuthnContextClassRef; //导入方法依赖的package包/类
/**
* Build SAML Assertion object
*
* @param pRequestContext
* @param pNotOnOrAfter
* @param pRecipient
* @param pAudienceURI
* @param pAssertionAttributes
* @param pSignAssertion
* @param pDigitalCertificateName
* @return SAML Assertion Object
*/
private Assertion buildSAMLAssertion(ActionRequestContext pRequestContext
, DateTime pNotOnOrAfter
, String pRecipient
, String pAudienceURI
, Map<String, String> pAssertionAttributes
, boolean pSignAssertion
, String pDigitalCertificateName
) {
DateTime lCurrentTime = new DateTime();
Assertion lAssertion = new AssertionBuilder().buildObject();
lAssertion.setID(ASSERTION_ID_PREFIX + RandomString.getString(40));
lAssertion.setVersion(SAMLVersion.VERSION_20);
lAssertion.setIssuer(buildIssuer(pRequestContext.getFoxRequest().getHttpRequest().getRequestURL().toString()));
lAssertion.setIssueInstant(lCurrentTime);
Subject lSubject = new SubjectBuilder().buildObject();
SubjectConfirmation lSubjectConfirmation = new SubjectConfirmationBuilder().buildObject();
lSubjectConfirmation.setMethod(SubjectConfirmation.METHOD_BEARER);
SubjectConfirmationData lSubjectConfirmationData = new SubjectConfirmationDataBuilder().buildObject();
if (!XFUtil.isNull(pRecipient)) {
lSubjectConfirmationData.setRecipient(pRecipient);
}
lSubjectConfirmationData.setNotOnOrAfter(pNotOnOrAfter);
lSubjectConfirmation.setSubjectConfirmationData(lSubjectConfirmationData);
lSubject.getSubjectConfirmations().add(lSubjectConfirmation);
NameIDBuilder lNameIDBuilder = new NameIDBuilder();
NameID lNameID = lNameIDBuilder.buildObject();
lNameID.setValue(RandomString.getString(64));
lNameID.setFormat(NameID.TRANSIENT);
lSubject.setNameID(lNameID);
lAssertion.setSubject(lSubject);
AuthnStatement lAuthnStatement = new AuthnStatementBuilder().buildObject();
lAuthnStatement.setAuthnInstant(new DateTime());
AuthnContext lAuthnContext = new AuthnContextBuilder().buildObject();
AuthnContextClassRef lAuthnContextClassRef = new AuthnContextClassRefBuilder().buildObject();
lAuthnContextClassRef.setAuthnContextClassRef(AuthnContext.PASSWORD_AUTHN_CTX);
lAuthnContext.setAuthnContextClassRef(lAuthnContextClassRef);
lAuthnStatement.setAuthnContext(lAuthnContext);
lAssertion.getAuthnStatements().add(lAuthnStatement);
if (pAssertionAttributes != null && pAssertionAttributes.size() > 0) {
lAssertion.getAttributeStatements().add(buildAttributeStatement(pAssertionAttributes));
}
AudienceRestriction lAudienceRestriction = new AudienceRestrictionBuilder().buildObject();
if (!XFUtil.isNull(pAudienceURI)) {
Audience lAudience = new AudienceBuilder().buildObject();
lAudience.setAudienceURI(pAudienceURI);
lAudienceRestriction.getAudiences().add(lAudience);
}
Conditions lConditions = new ConditionsBuilder().buildObject();
lConditions.setNotBefore(lCurrentTime);
lConditions.setNotOnOrAfter(pNotOnOrAfter);
lConditions.getAudienceRestrictions().add(lAudienceRestriction);
lAssertion.setConditions(lConditions);
if (pSignAssertion) {
signSAMLObject(lAssertion, pRequestContext, pDigitalCertificateName);
}
return lAssertion;
}
示例12: populateRequiredData
import org.opensaml.saml2.core.AuthnContextClassRef; //导入方法依赖的package包/类
protected void populateRequiredData() {
super.populateRequiredData();
AuthnContextClassRef authnContextClassRef = (AuthnContextClassRef) target;
authnContextClassRef.setAuthnContextClassRef("ref");
}
示例13: buildAuthnRequest
import org.opensaml.saml2.core.AuthnContextClassRef; //导入方法依赖的package包/类
/**
* Build a SAML2 authentication request.
*
* @param requestId
* the request Id
* @return the authentication request
*/
protected AuthnRequest buildAuthnRequest(final SamlBindingEnum binding) {
final Issuer issuer = this.buildIssuer();
// Create NameIDPolicy
final NameIDPolicyBuilder nameIdPolicyBuilder = new NameIDPolicyBuilder();
final NameIDPolicy nameIdPolicy = nameIdPolicyBuilder.buildObject();
nameIdPolicy.setFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:transient");
nameIdPolicy.setAllowCreate(false);
// Create AuthnContextClassRef
final AuthnContextClassRef authnContextClassRef = this.authnContextClassRefBuilder
.buildObject(AuthnContextClassRef.DEFAULT_ELEMENT_NAME);
authnContextClassRef
.setAuthnContextClassRef("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport");
// Create RequestedAuthnContext
final RequestedAuthnContext requestedAuthnContext = this.requestedAuthnContextBuilder
.buildObject(RequestedAuthnContext.DEFAULT_ELEMENT_NAME);
requestedAuthnContext.setComparison(AuthnContextComparisonTypeEnumeration.EXACT);
requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef);
final DateTime issueInstant = new DateTime();
final AuthnRequest authnRequest = this.authRequestBuilder.buildObject(AuthnRequest.DEFAULT_ELEMENT_NAME);
// Force IdP authentication.
authnRequest.setForceAuthn(this.idpConfig.isForceAuthentication());
authnRequest.setIsPassive(false);
authnRequest.setIssueInstant(issueInstant);
final SamlBindingEnum responseBinding = this.idpConfig.getResponseBinding();
authnRequest.setProtocolBinding(responseBinding.getUri());
final ISpConfig spConfig = this.getSaml20SpProcessor().getSpConfig();
authnRequest.setAssertionConsumerServiceURL(spConfig.getEndpointUrl(responseBinding));
authnRequest.setIssuer(issuer);
authnRequest.setNameIDPolicy(nameIdPolicy);
// authnRequest.setRequestedAuthnContext(requestedAuthnContext);
// authnRequest.setProviderName(this.spConfig.getEntityId());
authnRequest.setDestination(this.idpConfig.getIdpSsoEndpointUrl(binding));
authnRequest.setVersion(SAMLVersion.VERSION_20);
// Select the Attributes to be returned
if (this.idpConfig.getAttributeConsumingServiceIndex() != null) {
authnRequest.setAttributeConsumingServiceIndex(this.idpConfig.getAttributeConsumingServiceIndex());
}
// Subject subject = this.subjectBuilder.buildObject();
// authnRequest.setSubject(subject);
// Time validity window : + or - XX ms
final Conditions conditions = this.conditionsBuilder.buildObject();
conditions.setNotBefore(this.buildNotBeforeTime(issueInstant));
conditions.setNotOnOrAfter(this.buildNotOnOrAfterTime(issueInstant));
authnRequest.setConditions(conditions);
this.getSaml20SpProcessor().signSamlObject(authnRequest);
return authnRequest;
}
示例14: createAuthnStatement
import org.opensaml.saml2.core.AuthnContextClassRef; //导入方法依赖的package包/类
private static AuthnStatement createAuthnStatement() {
AuthnStatement authnStatement = null;
AuthnContext authnContext = null;
SubjectLocality subjectLocality = null;
if (samlResponseData.getAuthnContextClassRef() != null
&& samlResponseData.getAuthnContextClassRef().length() > 0) {
authnContext = create(AuthnContext.DEFAULT_ELEMENT_NAME);
AuthnContextClassRef authnContextClassRef = create(AuthnContextClassRef.DEFAULT_ELEMENT_NAME);
if (samlResponseData.getAuthnContextClassRef().equals(
SamlResponseData.REPLACE_WITH_AUTHN_REQUEST)) {
authnContextClassRef.setAuthnContextClassRef(authnRequest
.getRequestedAuthnContext().getAuthnContextClassRefs()
.get(0).getAuthnContextClassRef());
} else {
authnContextClassRef.setAuthnContextClassRef(samlResponseData
.getAuthnContextClassRef());
}
authnContext.setAuthnContextClassRef(authnContextClassRef);
}
if (samlResponseData.getSubjectLocalityAddress() != null
&& samlResponseData.getSubjectLocalityAddress().length() > 0) {
subjectLocality = create(SubjectLocality.DEFAULT_ELEMENT_NAME);
subjectLocality.setAddress(samlResponseData
.getSubjectLocalityAddress());
}
if (samlResponseData.getSubjectLocalityDNSName() != null
&& samlResponseData.getSubjectLocalityDNSName().length() > 0) {
if (subjectLocality == null)
subjectLocality = create(SubjectLocality.DEFAULT_ELEMENT_NAME);
subjectLocality.setDNSName(samlResponseData
.getSubjectLocalityDNSName());
}
if (authnContext != null || subjectLocality != null
|| samlResponseData.getAuthnInstant() != null) {
authnStatement = create(AuthnStatement.DEFAULT_ELEMENT_NAME);
if (samlResponseData.getAuthnInstant() != null) {
authnStatement.setAuthnInstant(startTime
.plusMinutes(samlResponseData.getAuthnInstant()));
}
authnStatement.setSessionIndex(GENERATOR.generateIdentifier());
authnStatement.setAuthnContext(authnContext);
authnStatement.setSubjectLocality(subjectLocality);
}
return authnStatement;
}