org.opensaml.saml2.core.Subject类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(13.0k)|赞(0)|评价(0)|浏览(77)

本文整理了Java中org.opensaml.saml2.core.Subject类的一些代码示例,展示了Subject类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Subject类的具体详情如下:
包路径:org.opensaml.saml2.core.Subject
类名称:Subject

Subject介绍

[英]SAML 2.0 Core Subject.
[中]SAML2.0核心课程。

代码示例

代码示例来源:origin: cloudfoundry/uaa

@Test
public void testBuildResponseForSamlRequestWithEmailAddressNameID() throws MessageEncodingException, SAMLException,
    MetadataProviderException, SecurityException, MarshallingException, SignatureException {
  String authenticationId = UUID.randomUUID().toString();
  Authentication authentication = samlTestUtils.mockUaaAuthentication(authenticationId);
  SAMLMessageContext context = samlTestUtils.mockSamlMessageContext(
      samlTestUtils.mockAuthnRequest(NameIDType.EMAIL));
  IdpWebSSOProfileOptions options = new IdpWebSSOProfileOptions();
  options.setAssertionsSigned(false);
  profile.buildResponse(authentication, context, options);
  AuthnRequest request = (AuthnRequest) context.getInboundSAMLMessage();
  Response response = (Response) context.getOutboundSAMLMessage();
  Assertion assertion = response.getAssertions().get(0);
  Subject subject = assertion.getSubject();
  assertEquals("marissa@testing.org", subject.getNameID().getValue());
  assertEquals(NameIDType.EMAIL, subject.getNameID().getFormat());
  SubjectConfirmation subjectConfirmation = subject.getSubjectConfirmations().get(0);
  SubjectConfirmationData subjectConfirmationData = subjectConfirmation.getSubjectConfirmationData();
  assertEquals(request.getID(), subjectConfirmationData.getInResponseTo());
  verifyAssertionAttributes(authenticationId, assertion);
}

代码示例来源:origin: cloudfoundry/uaa

if(null != authnRequest.getSubject() && null != authnRequest.getSubject().getNameID()
    && null != authnRequest.getSubject().getNameID().getFormat()){
  nameIDFormat = authnRequest.getSubject().getNameID().getFormat();
  switch (nameIDFormat) {
    case NameIDType.EMAIL:
subject.setNameID(nameID);
subjectConfirmationData.setRecipient(authnRequest.getAssertionConsumerServiceURL());
subjectConfirmation.setSubjectConfirmationData(subjectConfirmationData);
subject.getSubjectConfirmations().add(subjectConfirmation);
assertion.setSubject(subject);

代码示例来源:origin: apache/cloudstack

if (assertion!= null && assertion.getSubject() != null && assertion.getSubject().getNameID() != null) {
  session.setAttribute(SAMLPluginConstants.SAML_NAMEID, assertion.getSubject().getNameID().getValue());
  break;
    if (assertion.getSubject() != null && assertion.getSubject().getNameID() != null) {
      session.setAttribute(SAMLPluginConstants.SAML_NAMEID, assertion.getSubject().getNameID().getValue());

代码示例来源:origin: se.skltp.adapterservices.se.apotekensservice/TicketMachine

@Override
  public Subject build() {
    Subject subject = new SubjectBuilder().buildObject();
    subject.setNameID(nameId);		
    if(subjectConfermations.size() >0){
      for (SubjectConfirmation subjectConfirmation : subjectConfermations) {
        subject.getSubjectConfirmations().add(subjectConfirmation);
      }
    }
    return subject;
  }
}

代码示例来源:origin: org.wso2.carbon.identity.inbound.auth.oauth2/org.wso2.carbon.identity.oauth

private List<SubjectConfirmation> getSubjectConfirmations(Assertion assertion) throws IdentityOAuth2Exception {
  List<SubjectConfirmation> subjectConfirmations = assertion.getSubject().getSubjectConfirmations();
  if (subjectConfirmations == null || subjectConfirmations.isEmpty()) {
    throw new IdentityOAuth2Exception("No SubjectConfirmation exist in Assertion");
  }
  return subjectConfirmations;
}

代码示例来源:origin: org.springframework.security.extensions/spring-security-saml2-core

for (SubjectConfirmation confirmation : subject.getSubjectConfirmations()) {
    if (subject.getEncryptedID() != null) {
      Assert.notNull(context.getLocalDecrypter(), "Can't decrypt NameID, no decrypter is set in the context");
      nameID = (NameID) context.getLocalDecrypter().decrypt(subject.getEncryptedID());
    } else {
      nameID = subject.getNameID();

代码示例来源:origin: org.opensaml/opensaml

/** {@inheritDoc} */
  public void validate(Subject subject) throws ValidationException {
    if (subject.getBaseID() == null && subject.getNameID() == null
        && (subject.getSubjectConfirmations() == null || subject.getSubjectConfirmations().size() == 0)) {
      throw new ValidationException("ID or SubjectConfirmation required");
    }
  }
}

代码示例来源:origin: org.opensaml/opensaml

/** {@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);
    }
  }
}

代码示例来源:origin: cloudfoundry/uaa

public AuthnRequest buildIdpInitiatedAuthnRequest(String nameIDFormat,
                         String spEntityID,
                         String assertionUrl) {
  @SuppressWarnings("unchecked")
  SAMLObjectBuilder<AuthnRequest> builder = (SAMLObjectBuilder<AuthnRequest>) builderFactory
    .getBuilder(AuthnRequest.DEFAULT_ELEMENT_NAME);
  AuthnRequest request = builder.buildObject();
  request.setVersion(SAMLVersion.VERSION_20);
  request.setID(generateID());
  request.setIssuer(getIssuer(spEntityID));
  request.setVersion(SAMLVersion.VERSION_20);
  request.setIssueInstant(new DateTime());
  request.setID(null);
  request.setAssertionConsumerServiceURL(assertionUrl);
  if (null != nameIDFormat) {
    NameID nameID = ((SAMLObjectBuilder<NameID>) builderFactory.getBuilder(NameID.DEFAULT_ELEMENT_NAME)).buildObject();
    nameID.setFormat(nameIDFormat);
    Subject subject = ((SAMLObjectBuilder<Subject>) builderFactory.getBuilder(Subject.DEFAULT_ELEMENT_NAME)).buildObject();
    subject.setNameID(nameID);
    request.setSubject(subject);
  }
  return request;
}

代码示例来源:origin: OpenConext/Mujina

@Override
 @SuppressWarnings("unchecked")
 protected void verifyAssertion(Assertion assertion, AuthnRequest request, SAMLMessageContext context) throws AuthenticationException, SAMLException, org.opensaml.xml.security.SecurityException, ValidationException, DecryptionException {
  //nope
  context.setSubjectNameIdentifier(assertion.getSubject().getNameID());
 }
} : new WebSSOProfileConsumerImpl();

代码示例来源:origin: OpenConext/Mujina

private static Subject buildSubject(String subjectNameId, String subjectNameIdType, String recipient, String inResponseTo) {
 NameID nameID = buildSAMLObject(NameID.class, NameID.DEFAULT_ELEMENT_NAME);
 nameID.setValue(subjectNameId);
 nameID.setFormat(subjectNameIdType);
 Subject subject = buildSAMLObject(Subject.class, Subject.DEFAULT_ELEMENT_NAME);
 subject.setNameID(nameID);
 SubjectConfirmation subjectConfirmation = buildSAMLObject(SubjectConfirmation.class, SubjectConfirmation.DEFAULT_ELEMENT_NAME);
 subjectConfirmation.setMethod(SubjectConfirmation.METHOD_BEARER);
 SubjectConfirmationData subjectConfirmationData = buildSAMLObject(SubjectConfirmationData.class, SubjectConfirmationData.DEFAULT_ELEMENT_NAME);
 subjectConfirmationData.setRecipient(recipient);
 subjectConfirmationData.setInResponseTo(inResponseTo);
 subjectConfirmationData.setNotOnOrAfter(new DateTime().plusMinutes(8 * 60));
 subjectConfirmationData.setAddress(recipient);
 subjectConfirmation.setSubjectConfirmationData(subjectConfirmationData);
 subject.getSubjectConfirmations().add(subjectConfirmation);
 return subject;
}

代码示例来源:origin: org.apache.rampart/rampart-trust

/**
 * Get the subject confirmation method of a SAML 2.0 assertion
 *
 * @param assertion SAML 2.0 assertion
 * @return Subject Confirmation method
 */
public static String getSAML2SubjectConfirmationMethod(Assertion assertion) {
  String subjectConfirmationMethod = RahasConstants.SAML20_SUBJECT_CONFIRMATION_HOK;
  List<SubjectConfirmation> subjectConfirmations = assertion.getSubject().getSubjectConfirmations();
  if (subjectConfirmations.size() > 0) {
    subjectConfirmationMethod = subjectConfirmations.get(0).getMethod();
  }
  return subjectConfirmationMethod;
}

代码示例来源:origin: org.springframework.security.extensions/spring-security-saml2-core

for (SubjectConfirmation confirmation : subject.getSubjectConfirmations()) {
    if (subject.getEncryptedID() != null) {
      Assert.notNull(context.getLocalDecrypter(), "Can't decrypt NameID, no decrypter is set in the context");
      nameID = (NameID) context.getLocalDecrypter().decrypt(subject.getEncryptedID());
    } else {
      nameID = subject.getNameID();

代码示例来源:origin: cloudfoundry/uaa

public AuthnRequest mockAuthnRequest(String nameIDFormat) {
  @SuppressWarnings("unchecked")
  SAMLObjectBuilder<AuthnRequest> builder = (SAMLObjectBuilder<AuthnRequest>) builderFactory
   .getBuilder(AuthnRequest.DEFAULT_ELEMENT_NAME);
  AuthnRequest request = builder.buildObject();
  request.setVersion(SAMLVersion.VERSION_20);
  request.setID(generateID());
  request.setIssuer(getIssuer(SP_ENTITY_ID));
  request.setVersion(SAMLVersion.VERSION_20);
  request.setIssueInstant(new DateTime());
  if (null != nameIDFormat) {
    NameID nameID = ((SAMLObjectBuilder<NameID>) builderFactory.getBuilder(NameID.DEFAULT_ELEMENT_NAME))
     .buildObject();
    nameID.setFormat(nameIDFormat);
    Subject subject = ((SAMLObjectBuilder<Subject>) builderFactory.getBuilder(Subject.DEFAULT_ELEMENT_NAME))
     .buildObject();
    subject.setNameID(nameID);
    request.setSubject(subject);
  }
  return request;
}

代码示例来源:origin: cloudfoundry/uaa

@Test
public void testBuildResponseForSamlRequestWithPersistentNameID() throws Exception {
  String authenticationId = UUID.randomUUID().toString();
  Authentication authentication = samlTestUtils.mockUaaAuthentication(authenticationId);
  SAMLMessageContext context =
    samlTestUtils.mockSamlMessageContext(samlTestUtils.mockAuthnRequest(NameIDType.PERSISTENT));
  IdpWebSSOProfileOptions options = new IdpWebSSOProfileOptions();
  options.setAssertionsSigned(false);
  profile.buildResponse(authentication, context, options);
  AuthnRequest request = (AuthnRequest) context.getInboundSAMLMessage();
  Response response = (Response) context.getOutboundSAMLMessage();
  Assertion assertion = response.getAssertions().get(0);
  Subject subject = assertion.getSubject();
  assertEquals(authenticationId, subject.getNameID().getValue());
  assertEquals(NameIDType.PERSISTENT, subject.getNameID().getFormat());
  SubjectConfirmation subjectConfirmation = subject.getSubjectConfirmations().get(0);
  SubjectConfirmationData subjectConfirmationData = subjectConfirmation.getSubjectConfirmationData();
  assertEquals(request.getID(), subjectConfirmationData.getInResponseTo());
  verifyAssertionAttributes(authenticationId, assertion);
}

代码示例来源:origin: coveo/saml-client

/**
  * Retrieves the Name ID from the SAML response. This is normally the name of the authenticated
  * user.
  *
  * @return The Name ID from the SAML response.
  */
 public String getNameID() {
  return assertion.getSubject().getNameID().getValue();
 }
}

代码示例来源:origin: org.apache.ws.security/wss4j

subject.setNameID(nameID);
  );
subject.getSubjectConfirmations().add(subjectConfirmation);
return subject;

代码示例来源:origin: usnistgov/iheos-toolkit2

/**
 * Method getConfirmationMethods returns the confirmationMethods of this 
 * AssertionWrapper model.
 *
 * @return the confirmationMethods of this AssertionWrapper model.
 */
public List<String> getConfirmationMethods() {
  List<String> methods = new ArrayList<String>();
  if (saml2 != null) {
    org.opensaml.saml2.core.Subject subject = saml2.getSubject();
    List<org.opensaml.saml2.core.SubjectConfirmation> confirmations = 
      subject.getSubjectConfirmations();
    for (org.opensaml.saml2.core.SubjectConfirmation confirmation : confirmations) {
      methods.add(confirmation.getMethod());
    }
  } 
  return methods;
}

代码示例来源:origin: org.apache.rampart/rampart-trust

/**
 * This method will set the subject principal details to the given subject.
 * @param subject The subject.
 * @param subjectNameId Subject name id, to identify the principal
 * @param format Format of the subjectNameId, i.e. email, x509subject etc ...
 * @throws TrustException If an error occurred while building NameID.
 */
protected static void setSubjectNamedIdentifierData(Subject subject, String subjectNameId, String format)
    throws TrustException {
  //Create NameID and attach it to the subject
  NameID nameID = SAML2Utils.createNamedIdentifier(subjectNameId, format);
  subject.setNameID(nameID);
}

代码示例来源:origin: cloudfoundry/uaa

@Test
public void testBuildResponseForSamlRequestWithUnspecifiedNameID() throws MessageEncodingException, SAMLException,
    MetadataProviderException, SecurityException, MarshallingException, SignatureException {
  String authenticationId = UUID.randomUUID().toString();
  Authentication authentication = samlTestUtils.mockUaaAuthentication(authenticationId);
  SAMLMessageContext context = samlTestUtils.mockSamlMessageContext(
      samlTestUtils.mockAuthnRequest(NameIDType.UNSPECIFIED));
  IdpWebSSOProfileOptions options = new IdpWebSSOProfileOptions();
  options.setAssertionsSigned(false);
  profile.buildResponse(authentication, context, options);
  AuthnRequest request = (AuthnRequest) context.getInboundSAMLMessage();
  Response response = (Response) context.getOutboundSAMLMessage();
  Assertion assertion = response.getAssertions().get(0);
  Subject subject = assertion.getSubject();
  assertEquals("marissa", subject.getNameID().getValue());
  assertEquals(NameIDType.UNSPECIFIED, subject.getNameID().getFormat());
  SubjectConfirmation subjectConfirmation = subject.getSubjectConfirmations().get(0);
  SubjectConfirmationData subjectConfirmationData = subjectConfirmation.getSubjectConfirmationData();
  assertEquals(request.getID(), subjectConfirmationData.getInResponseTo());
  verifyAssertionAttributes(authenticationId, assertion);
}

相关文章