本文整理汇总了Java中org.opensaml.saml2.core.Assertion.setSubject方法的典型用法代码示例。如果您正苦于以下问题:Java Assertion.setSubject方法的具体用法?Java Assertion.setSubject怎么用?Java Assertion.setSubject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opensaml.saml2.core.Assertion
的用法示例。
在下文中一共展示了Assertion.setSubject方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processChildElement
import org.opensaml.saml2.core.Assertion; //导入方法依赖的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: buildAssertion
import org.opensaml.saml2.core.Assertion; //导入方法依赖的package包/类
public static Assertion buildAssertion(String recipient, String audience) {
Assertion assertion = SAMLUtil.buildXMLObject(Assertion.class);
assertion.setID(Utils.generateUUID());
assertion.setSubject(SAMLUtil.createSubject("joetest", recipient, new DateTime().plusHours(1)));
assertion.setIssueInstant(new DateTime());
assertion.setIssuer(SAMLUtil.createIssuer("idp1.test.oio.dk"));
assertion.setConditions(SAMLUtil.createAudienceCondition(audience));
assertion.getConditions().setNotOnOrAfter(new DateTime().plus(10000));
AuthnContext context = SAMLUtil.createAuthnContext("urn:oasis:names:tc:SAML:2.0:ac:classes:Password");
AuthnStatement authnStatement = SAMLUtil.buildXMLObject(AuthnStatement.class);
authnStatement.setAuthnContext(context);
authnStatement.setAuthnInstant(new DateTime());
authnStatement.setSessionIndex(Utils.generateUUID());
assertion.getAuthnStatements().add(authnStatement);
AttributeStatement as = SAMLUtil.buildXMLObject(AttributeStatement.class);
as.getAttributes().add(AttributeUtil.createAssuranceLevel(2));
assertion.getAttributeStatements().add(as);
return assertion;
}
示例3: selectUser
import org.opensaml.saml2.core.Assertion; //导入方法依赖的package包/类
private UserAssertion selectUser(String user, Configuration conf) {
Map<String, String[]> attributes = getAttributes(user, conf);
Assertion a = SAMLUtil.buildXMLObject(Assertion.class);
a.setSubject(SAMLUtil.createSubject(user, "urn:test", new DateTime().plusHours(1)));
AttributeStatement as = SAMLUtil.buildXMLObject(AttributeStatement.class);
a.getAttributeStatements().add(as);
for (Map.Entry<String, String[]> e : attributes.entrySet()) {
Attribute attr = AttributeUtil.createAttribute(e.getKey(), e.getKey(), "");
for (String val : e.getValue()) {
attr.getAttributeValues().add(AttributeUtil.createAttributeValue(val));
as.getAttributes().add(attr);
}
}
return new UserAssertionImpl(new OIOAssertion(a));
}
示例4: getSubjectNameIDValue
import org.opensaml.saml2.core.Assertion; //导入方法依赖的package包/类
@Test
public void getSubjectNameIDValue() {
String expectedValue = "testvalue";
NameID nameid = new NameIDStubImpl();
nameid.setValue(expectedValue);
Subject subject = new SubjectStubImpl();
subject.setNameID(nameid);
Assertion localAssertion = new AssertionStubImpl();
localAssertion.setSubject(subject);
assertEquals(expectedValue, new OIOAssertion(localAssertion).getSubjectNameIDValue());
assertEquals("joetest", assertion.getSubjectNameIDValue());
}
示例5: testSignoutDefault
import org.opensaml.saml2.core.Assertion; //导入方法依赖的package包/类
@Test
public void testSignoutDefault() throws Exception {
when(sh.isLoggedIn(anyString())).thenReturn(true);
Assertion a = SAMLUtil.buildXMLObject(Assertion.class);
a.setSubject(SAMLUtil.createSubject("test", "test", new DateTime()));
when(sh.getAssertion(anyString())).thenReturn(new OIOAssertion(a));
when(req.getParameter("wa")).thenReturn("wsignout1.0");
handler.handleGet(rc);
verify(res).setContentType("image/gif");
verify(sh).logOut(session);
verify(res, never()).sendError(anyInt());
}
示例6: testLogoutRedirect
import org.opensaml.saml2.core.Assertion; //导入方法依赖的package包/类
@Test
public void testLogoutRedirect() throws Exception {
when(sh.isLoggedIn(anyString())).thenReturn(true);
Assertion a = SAMLUtil.buildXMLObject(Assertion.class);
a.setSubject(SAMLUtil.createSubject("test", "test", new DateTime()));
when(sh.getAssertion(anyString())).thenReturn(new OIOAssertion(a));
when(req.getParameter("wa")).thenReturn("wsignout1.0");
when(req.getParameter("wreply")).thenReturn("/result");
handler.handleGet(rc);
verify(sh).logOut(session);
verify(res).sendRedirect("/result");
}
示例7: checkRecipient
import org.opensaml.saml2.core.Assertion; //导入方法依赖的package包/类
@Test
public void checkRecipient() {
String requiredMethodBearer = "urn:oasis:names:tc:SAML:2.0:cm:bearer";
assertFalse(assertion.checkRecipient(null));
assertFalse(new OIOAssertion(new AssertionStubImpl()).checkRecipient(""));
Assertion localAssertion = new AssertionStubImpl();
localAssertion.setSubject(new SubjectStubImpl());
assertFalse(assertion.checkRecipient(""));
SubjectConfirmation subjectConfirmation = new SubjectConfirmationStubImpl();
subjectConfirmation.setMethod(requiredMethodBearer);
SubjectConfirmationData subConfData = new SubjectConfirmationDataStubImpl();
String expectedRecipient = "recipient";
subConfData.setRecipient(expectedRecipient);
subjectConfirmation.setSubjectConfirmationData(subConfData);
Subject subject = new SubjectStubImpl(Collections.singletonList(subjectConfirmation));
localAssertion.setSubject(subject);
OIOAssertion la = new OIOAssertion(localAssertion);
assertTrue(la.checkRecipient(expectedRecipient));
subConfData.setRecipient("something else");
assertFalse(la.checkRecipient(expectedRecipient));
subjectConfirmation.setMethod("not requiredBearer");
assertFalse(la.checkRecipient(expectedRecipient));
assertTrue(assertion.checkRecipient(assertionConsumerURL));
}
示例8: buildSAMLAssertion
import org.opensaml.saml2.core.Assertion; //导入方法依赖的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;
}
示例9: buildSAMLAssertion
import org.opensaml.saml2.core.Assertion; //导入方法依赖的package包/类
private Assertion buildSAMLAssertion(final String emailAddress)
{
// Bootstrap the OpenSAML library
try {
DefaultBootstrap.bootstrap();
} catch (ConfigurationException e) {
}
DateTime issueInstant = new DateTime();
DateTime notOnOrAfter = issueInstant.plusMinutes(15);
DateTime notBefore = issueInstant.minusMinutes(5);
NameID nameID = (new NameIDBuilder().buildObject());
nameID.setFormat(NameIDType.EMAIL);
nameID.setValue(emailAddress);
SubjectConfirmationData subjectConfirmationData = (new SubjectConfirmationDataBuilder().buildObject());
subjectConfirmationData.setRecipient(applicationLink.getRpcUrl().toString() + ACCESS_TOKEN_URL);
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(providerID);
Audience audience = (new AudienceBuilder().buildObject());
audience.setAudienceURI(AUDIENCE_RESTRICTION);
AudienceRestriction audienceRestriction = (new AudienceRestrictionBuilder().buildObject());
audienceRestriction.getAudiences().add(audience);
Conditions conditions = (new ConditionsBuilder().buildObject());
conditions.setNotBefore(notBefore);
conditions.setNotOnOrAfter(notOnOrAfter);
conditions.getAudienceRestrictions().add(audienceRestriction);
XSString attributeValue = (XSString)Configuration.getBuilderFactory().getBuilder(XSString.TYPE_NAME).buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
attributeValue.setValue(clientID);
Attribute attribute = (new AttributeBuilder().buildObject());
attribute.setName("client_id");
attribute.getAttributeValues().add(attributeValue);
AttributeStatement attributeStatement = (new AttributeStatementBuilder().buildObject());
attributeStatement.getAttributes().add(attribute);
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);
assertion.getAttributeStatements().add(attributeStatement);
return assertion;
}
示例10: buildSAML2Assertion
import org.opensaml.saml2.core.Assertion; //导入方法依赖的package包/类
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;
}
示例11: buildSAML2Assertion
import org.opensaml.saml2.core.Assertion; //导入方法依赖的package包/类
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;
}
示例12: buildSignedSAML2Assertion
import org.opensaml.saml2.core.Assertion; //导入方法依赖的package包/类
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);
}
示例13: testVerifySignature
import org.opensaml.saml2.core.Assertion; //导入方法依赖的package包/类
@Test
public void testVerifySignature() throws Exception {
Assertion a = (Assertion) SAMLUtil.unmarshallElementFromString("<saml:Assertion Version=\"2.0\" xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\"></saml:Assertion>");
Credential cred = TestHelper.getCredential();
assertFalse(new OIOSamlObject(a).verifySignature(cred.getPublicKey()));
Signature signature = SAMLUtil.createSignature("test");
signature.setSigningCredential(cred);
signature.setSignatureAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA1);
signature.setCanonicalizationAlgorithm(SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS);
a.setSignature(signature);
Configuration.getMarshallerFactory().getMarshaller(a).marshall(a);
Signer.signObject(signature);
assertTrue(new OIOSamlObject(a).verifySignature(cred.getPublicKey()));
Credential cred2 = TestHelper.getCredential();
assertFalse(new OIOSamlObject(a).verifySignature(cred2.getPublicKey()));
a.setSubject(SAMLUtil.createSubject("test", "test", new DateTime()));
Configuration.getMarshallerFactory().getMarshaller(a).marshall(a);
assertFalse(new OIOSamlObject(a).verifySignature(cred.getPublicKey()));
}