本文整理汇总了Java中org.opensaml.saml2.core.NameID类的典型用法代码示例。如果您正苦于以下问题:Java NameID类的具体用法?Java NameID怎么用?Java NameID使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NameID类属于org.opensaml.saml2.core包,在下文中一共展示了NameID类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processChildElement
import org.opensaml.saml2.core.NameID; //导入依赖的package包/类
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
throws UnmarshallingException {
LogoutRequest req = (LogoutRequest) parentSAMLObject;
if (childSAMLObject instanceof BaseID) {
req.setBaseID((BaseID) childSAMLObject);
} else if (childSAMLObject instanceof NameID) {
req.setNameID((NameID) childSAMLObject);
} else if (childSAMLObject instanceof EncryptedID) {
req.setEncryptedID((EncryptedID) childSAMLObject);
} else if (childSAMLObject instanceof SessionIndex) {
req.getSessionIndexes().add((SessionIndex) childSAMLObject);
} else {
super.processChildElement(parentSAMLObject, childSAMLObject);
}
}
示例2: buildLogoutRequest
import org.opensaml.saml2.core.NameID; //导入依赖的package包/类
protected LogoutRequest buildLogoutRequest(String user, String sessionIdx) throws SSOAgentException {
LogoutRequest logoutReq = new LogoutRequestBuilder().buildObject();
logoutReq.setID(SSOAgentUtils.createID());
logoutReq.setDestination(ssoAgentConfig.getSAML2().getIdPURL());
DateTime issueInstant = new DateTime();
logoutReq.setIssueInstant(issueInstant);
logoutReq.setNotOnOrAfter(new DateTime(issueInstant.getMillis() + 5 * 60 * 1000));
IssuerBuilder issuerBuilder = new IssuerBuilder();
Issuer issuer = issuerBuilder.buildObject();
issuer.setValue(ssoAgentConfig.getSAML2().getSPEntityId());
logoutReq.setIssuer(issuer);
NameID nameId = new NameIDBuilder().buildObject();
nameId.setFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:entity");
nameId.setValue(user);
logoutReq.setNameID(nameId);
SessionIndex sessionIndex = new SessionIndexBuilder().buildObject();
sessionIndex.setSessionIndex(sessionIdx);
logoutReq.getSessionIndexes().add(sessionIndex);
logoutReq.setReason("Single Logout");
return logoutReq;
}
示例3: testChildElementsMarshall
import org.opensaml.saml2.core.NameID; //导入依赖的package包/类
/** {@inheritDoc} */
public void testChildElementsMarshall() {
QName qname = new QName(SAMLConstants.SAML20P_NS, LogoutRequest.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20P_PREFIX);
LogoutRequest req = (LogoutRequest) buildXMLObject(qname);
super.populateChildElements(req);
QName nameIDQName = new QName(SAMLConstants.SAML20_NS, NameID.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX);
req.setNameID((NameID) buildXMLObject(nameIDQName));
QName sessionIndexQName = new QName(SAMLConstants.SAML20P_NS, SessionIndex.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20P_PREFIX);
for (int i=0; i<expectedNumSessionIndexes; i++){
req.getSessionIndexes().add((SessionIndex) buildXMLObject(sessionIndexQName));
}
assertEquals(expectedChildElementsDOM, req);
}
示例4: getAcsEndpoint
import org.opensaml.saml2.core.NameID; //导入依赖的package包/类
/**
* Gets the source location used to for the artifacts created by this encoder.
*
* @param requestContext current request context
*
* @return source location used to for the artifacts created by this encoder
*/
protected Endpoint getAcsEndpoint(SAMLMessageContext<SAMLObject, SAMLObject, NameID> requestContext) {
BasicEndpointSelector selector = new BasicEndpointSelector();
selector.setEndpointType(ArtifactResolutionService.DEFAULT_ELEMENT_NAME);
selector.getSupportedIssuerBindings().add(SAMLConstants.SAML2_SOAP11_BINDING_URI);
selector.setMetadataProvider(requestContext.getMetadataProvider());
selector.setEntityMetadata(requestContext.getLocalEntityMetadata());
selector.setEntityRoleMetadata(requestContext.getLocalEntityRoleMetadata());
Endpoint acsEndpoint = selector.selectEndpoint();
if (acsEndpoint == null) {
log.error("No artifact resolution service endpoint defined for the entity "
+ requestContext.getOutboundMessageIssuer());
return null;
}
return acsEndpoint;
}
示例5: processChildElement
import org.opensaml.saml2.core.NameID; //导入依赖的package包/类
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
throws UnmarshallingException {
ManageNameIDRequest req = (ManageNameIDRequest) parentSAMLObject;
if (childSAMLObject instanceof NameID) {
req.setNameID((NameID) childSAMLObject);
} else if (childSAMLObject instanceof EncryptedID) {
req.setEncryptedID((EncryptedID) childSAMLObject);
} else if (childSAMLObject instanceof NewID) {
req.setNewID((NewID) childSAMLObject);
} else if (childSAMLObject instanceof NewEncryptedID) {
req.setNewEncryptedID((NewEncryptedID) childSAMLObject);
} else if (childSAMLObject instanceof Terminate) {
req.setTerminate((Terminate) childSAMLObject);
} else {
super.processChildElement(parentSAMLObject, childSAMLObject);
}
}
示例6: processChildElement
import org.opensaml.saml2.core.NameID; //导入依赖的package包/类
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
throws UnmarshallingException {
NameIDMappingRequest req = (NameIDMappingRequest) parentSAMLObject;
if (childSAMLObject instanceof BaseID) {
req.setBaseID((BaseID) childSAMLObject);
} else if (childSAMLObject instanceof NameID) {
req.setNameID((NameID) childSAMLObject);
} else if (childSAMLObject instanceof EncryptedID) {
req.setEncryptedID((EncryptedID) childSAMLObject);
} else if (childSAMLObject instanceof NameIDPolicy) {
req.setNameIDPolicy((NameIDPolicy) childSAMLObject);
} else {
super.processChildElement(parentSAMLObject, childSAMLObject);
}
}
示例7: processChildElement
import org.opensaml.saml2.core.NameID; //导入依赖的package包/类
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentObject, XMLObject childObject) throws UnmarshallingException {
Subject subject = (Subject) parentObject;
if (childObject instanceof BaseID) {
subject.setBaseID((BaseID) childObject);
} else if (childObject instanceof NameID) {
subject.setNameID((NameID) childObject);
} else if (childObject instanceof EncryptedID) {
subject.setEncryptedID((EncryptedID) childObject);
} else if (childObject instanceof SubjectConfirmation) {
subject.getSubjectConfirmations().add((SubjectConfirmation) childObject);
} else {
super.processChildElement(parentObject, childObject);
}
}
示例8: processChildElement
import org.opensaml.saml2.core.NameID; //导入依赖的package包/类
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentObject, XMLObject childObject) throws UnmarshallingException {
SubjectConfirmation subjectConfirmation = (SubjectConfirmation) parentObject;
if (childObject instanceof BaseID) {
subjectConfirmation.setBaseID((BaseID) childObject);
} else if (childObject instanceof NameID) {
subjectConfirmation.setNameID((NameID) childObject);
} else if (childObject instanceof EncryptedID) {
subjectConfirmation.setEncryptedID((EncryptedID) childObject);
} else if (childObject instanceof SubjectConfirmationData) {
subjectConfirmation.setSubjectConfirmationData((SubjectConfirmationData) childObject);
} else {
super.processChildElement(parentObject, childObject);
}
}
示例9: marshallAttributes
import org.opensaml.saml2.core.NameID; //导入依赖的package包/类
/** {@inheritDoc} */
protected void marshallAttributes(XMLObject samlObject, Element domElement) throws MarshallingException {
NameIDType nameID = (NameIDType) samlObject;
if (nameID.getNameQualifier() != null) {
domElement.setAttributeNS(null, NameID.NAME_QUALIFIER_ATTRIB_NAME, nameID.getNameQualifier());
}
if (nameID.getSPNameQualifier() != null) {
domElement.setAttributeNS(null, NameID.SP_NAME_QUALIFIER_ATTRIB_NAME, nameID.getSPNameQualifier());
}
if (nameID.getFormat() != null) {
domElement.setAttributeNS(null, NameID.FORMAT_ATTRIB_NAME, nameID.getFormat());
}
if (nameID.getSPProvidedID() != null) {
domElement.setAttributeNS(null, NameID.SPPROVIDED_ID_ATTRIB_NAME, nameID.getSPProvidedID());
}
}
示例10: createLogoutRequest
import org.opensaml.saml2.core.NameID; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public LogoutRequest createLogoutRequest(Response resp) {
LogoutRequest lr = ((SAMLObjectBuilder<LogoutRequest>)
_bf.getBuilder(LogoutRequest.DEFAULT_ELEMENT_NAME)).buildObject();
String uid = UUID.randomUUID().toString();
lr.setID(uid);
lr.setIssueInstant(new DateTime());
lr.setVersion(SAMLVersion.VERSION_20);
lr.setIssuer(getIssuer());
// Get NameID and SessionIndex from first assertion from
// Authentication Response object
Assertion asr = resp.getAssertions().get(0);
NameID nid = ((SAMLObjectBuilder<NameID>)
_bf.getBuilder(NameID.DEFAULT_ELEMENT_NAME)).buildObject();
nid.setValue(asr.getSubject().getNameID().getValue());
lr.setNameID(nid);
// Set session index(es)
List<AuthnStatement> ausl = asr.getAuthnStatements();
if (ausl != null) {
for (AuthnStatement aus :ausl) {
SessionIndex sindex = ((SAMLObjectBuilder<SessionIndex>)
_bf.getBuilder(SessionIndex.DEFAULT_ELEMENT_NAME)).buildObject();
sindex.setSessionIndex(aus.getSessionIndex());
lr.getSessionIndexes().add(sindex);
}
}
return lr;
}
示例11: testAttributes
import org.opensaml.saml2.core.NameID; //导入依赖的package包/类
@Test
public void testAttributes() {
SAMLCredential samlCredential = mock(SAMLCredential.class);
NameID nameId = mock(NameID.class);
when(samlCredential.getNameID()).thenReturn(nameId);
Attribute attribute = mock(Attribute.class);
when(attribute.getName()).thenReturn("attr");
when(samlCredential.getAttributes()).thenReturn(Collections.singletonList(attribute));
when(samlCredential.getAttribute("attr")).thenReturn(attribute);
when(samlCredential.getAttributeAsString("attr")).thenReturn("value");
when(samlCredential.getAttributeAsStringArray("attr")).thenReturn(new String[]{"value"});
when(nameId.toString()).thenReturn(NameID.UNSPECIFIED);
SAMLUserDetails details = (SAMLUserDetails) new SimpleSAMLUserDetailsService().loadUserBySAML(samlCredential);
assertThat(details.getPassword()).isEmpty();
assertThat(details.isAccountNonExpired()).isTrue();
assertThat(details.isAccountNonLocked()).isTrue();
assertThat(details.isCredentialsNonExpired()).isTrue();
assertThat(details.isEnabled()).isTrue();
assertThat(details.getAuthorities()).extracting(GrantedAuthority::getAuthority).containsExactly("ROLE_USER");
assertThat(details.getAttribute("attr")).isEqualTo("value");
assertThat(details.getAttributeArray("attr")).containsExactly("value");
assertThat(details.getAttributes()).containsOnlyKeys("attr").containsValue("value");
assertThat(details.getAttributesArrays()).containsOnlyKeys("attr");
assertThat(details.getAttributesArrays().get("attr")).containsExactly("value");
}
开发者ID:ulisesbocchio,项目名称:spring-boot-security-saml,代码行数:26,代码来源:SimpleSAMLUserDetailsServiceTest.java
示例12: testAttributes
import org.opensaml.saml2.core.NameID; //导入依赖的package包/类
@Test
public void testAttributes() {
SAMLCredential samlCredential = mock(SAMLCredential.class);
NameID nameId = mock(NameID.class);
when(samlCredential.getNameID()).thenReturn(nameId);
Attribute attribute = mock(Attribute.class);
when(attribute.getName()).thenReturn("attr");
when(samlCredential.getAttributes()).thenReturn(Collections.singletonList(attribute));
when(samlCredential.getAttribute("attr")).thenReturn(attribute);
when(samlCredential.getAttributeAsString("attr")).thenReturn("value");
when(samlCredential.getAttributeAsStringArray("attr")).thenReturn(new String[]{"value"});
when(nameId.toString()).thenReturn(NameID.UNSPECIFIED);
SAMLUserDetails details = new SAMLUserDetails(samlCredential);
assertThat(details.getPassword()).isEmpty();
assertThat(details.isAccountNonExpired()).isTrue();
assertThat(details.isAccountNonLocked()).isTrue();
assertThat(details.isCredentialsNonExpired()).isTrue();
assertThat(details.isEnabled()).isTrue();
assertThat(details.getAuthorities()).extracting(GrantedAuthority::getAuthority).containsExactly("ROLE_USER");
assertThat(details.getAttribute("attr")).isEqualTo("value");
assertThat(details.getAttributeArray("attr")).containsExactly("value");
assertThat(details.getAttributes()).containsOnlyKeys("attr").containsValue("value");
assertThat(details.getAttributesArrays()).containsOnlyKeys("attr");
assertThat(details.getAttributesArrays().get("attr")).containsExactly("value");
}
示例13: buildLogoutRequest
import org.opensaml.saml2.core.NameID; //导入依赖的package包/类
/**
* Generate a new LogoutRequest.
*
* @param session The session containing the active assertion.
* @param logoutServiceLocation Destination for the logout request.
* @param issuerEntityId Entity ID of the issuing entity.
*/
@SuppressWarnings("deprecation")
public static OIOLogoutRequest buildLogoutRequest(HttpSession session, String logoutServiceLocation, String issuerEntityId, SessionHandler handler) {
LogoutRequest logoutRequest = new LogoutRequestBuilder().buildObject();
logoutRequest.setID(Utils.generateUUID());
logoutRequest.setIssueInstant(new DateTime(DateTimeZone.UTC));
logoutRequest.addNamespace(OIOSAMLConstants.SAML20_NAMESPACE);
logoutRequest.setDestination(logoutServiceLocation);
logoutRequest.setReason("urn:oasis:names:tc:SAML:2.0:logout:user");
logoutRequest.setIssuer(SAMLUtil.createIssuer(issuerEntityId));
OIOAssertion assertion = handler.getAssertion(session.getId());
if (assertion != null) {
NameID nameID = SAMLUtil.createNameID(assertion.getSubjectNameIDValue());
nameID.setFormat(assertion.getAssertion().getSubject().getNameID().getFormat());
logoutRequest.setNameID(nameID);
SessionIndex sessionIndex = new SessionIndexBuilder().buildObject();
logoutRequest.getSessionIndexes().add(sessionIndex);
sessionIndex.setSessionIndex(assertion.getSessionIndex());
}
try {
if (log.isDebugEnabled()) {
log.debug("Validate the logoutRequest...");
}
logoutRequest.validate(true);
if (log.isDebugEnabled()) {
log.debug("...OK");
}
} catch (ValidationException e) {
throw new WrappedException(Layer.CLIENT, e);
}
return new OIOLogoutRequest(logoutRequest);
}
示例14: getSubjectNameIDValue
import org.opensaml.saml2.core.NameID; //导入依赖的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());
}
示例15: makeEmailFormatName
import org.opensaml.saml2.core.NameID; //导入依赖的package包/类
public static NameID makeEmailFormatName(final String subjectNameId, final String subjectNameIdFormat, final String subjectNameIdQualifier) {
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);
return nameID;
}