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

x33g5p2x  于2022-01-16 转载在 其他  
字(13.2k)|赞(0)|评价(0)|浏览(139)

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

Attribute介绍

[英]SAML 2.0 Core Attribute.
[中]SAML2.0核心属性。

代码示例

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

private boolean findClaimInAssertion(org.opensaml.saml.saml2.core.Assertion assertion, URI claimURI) {
  List<org.opensaml.saml.saml2.core.AttributeStatement> attributeStatements =
    assertion.getAttributeStatements();
  if (attributeStatements == null || attributeStatements.isEmpty()) {
    return false;
  }
  for (org.opensaml.saml.saml2.core.AttributeStatement statement : attributeStatements) {
    List<org.opensaml.saml.saml2.core.Attribute> attributes = statement.getAttributes();
    for (org.opensaml.saml.saml2.core.Attribute attribute : attributes) {
      if (attribute.getName().equals(claimURI.toString())
        && attribute.getAttributeValues() != null && !attribute.getAttributeValues().isEmpty()) {
        return true;
      }
    }
  }
  return false;
}

代码示例来源:origin: Talend/tesb-rt-se

private String getRoleFromAssertion(SamlAssertionWrapper assertion) {
  Assertion saml2Assertion = assertion.getSaml2();
  if (saml2Assertion == null) {
    return null;
  }
  
  List<AttributeStatement> attributeStatements = saml2Assertion.getAttributeStatements();
  if (attributeStatements == null || attributeStatements.isEmpty()) {
    return null;
  }
  
  String nameFormat = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims";
  for (AttributeStatement statement : attributeStatements) {
    List<Attribute> attributes = statement.getAttributes();
    for (Attribute attribute : attributes) {
      if ("role".equals(attribute.getName()) 
        && nameFormat.equals(attribute.getNameFormat())) {
        Element attributeValueElement = attribute.getAttributeValues().get(0).getDOM();
        return attributeValueElement.getTextContent();
      }
    }
  }
  return null;
}

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

/** {@inheritDoc} */
  protected void marshallAttributes(XMLObject samlElement, Element domElement) throws MarshallingException {
    Attribute attribute = (Attribute) samlElement;

    if (attribute.getName() != null) {
      domElement.setAttributeNS(null, Attribute.NAME_ATTTRIB_NAME, attribute.getName());
    }

    if (attribute.getNameFormat() != null) {
      domElement.setAttributeNS(null, Attribute.NAME_FORMAT_ATTRIB_NAME, attribute.getNameFormat());
    }

    if (attribute.getFriendlyName() != null) {
      domElement.setAttributeNS(null, Attribute.FRIENDLY_NAME_ATTRIB_NAME, attribute.getFriendlyName());
    }

    marshallUnknownAttributes(attribute, domElement);
  }
}

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

/** {@inheritDoc} */
  protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {

    Attribute attrib = (Attribute) samlObject;

    if (attribute.getLocalName().equals(Attribute.NAME_ATTTRIB_NAME)) {
      attrib.setName(attribute.getValue());
    } else if (attribute.getLocalName().equals(Attribute.NAME_FORMAT_ATTRIB_NAME)) {
      attrib.setNameFormat(attribute.getValue());
    } else if (attribute.getLocalName().equals(Attribute.FRIENDLY_NAME_ATTRIB_NAME)) {
      attrib.setFriendlyName(attribute.getValue());
    } else {
      processUnknownAttribute(attrib, attribute);
    }
  }
}

代码示例来源:origin: spring-projects/spring-security-saml

protected List<Attribute> getAttributes(
  List<AttributeStatement> attributeStatements, List<SimpleKey>
  localKeys
) {
  List<Attribute> result = new LinkedList<>();
  for (AttributeStatement stmt : ofNullable(attributeStatements).orElse(emptyList())) {
    for (org.opensaml.saml.saml2.core.Attribute a : ofNullable(stmt.getAttributes()).orElse(emptyList())) {
      result.add(
        new Attribute()
          .setFriendlyName(a.getFriendlyName())
          .setName(a.getName())
          .setNameFormat(AttributeNameFormat.fromUrn(a.getNameFormat()))
          .setValues(getJavaValues(a.getAttributeValues()))
      );
    }
    for (EncryptedAttribute encryptedAttribute : ofNullable(stmt.getEncryptedAttributes()).orElse(emptyList())) {
      org.opensaml.saml.saml2.core.Attribute a = (org.opensaml.saml.saml2.core.Attribute) decrypt
        (encryptedAttribute, localKeys);
      result.add(
        new Attribute()
          .setFriendlyName(a.getFriendlyName())
          .setName(a.getName())
          .setNameFormat(AttributeNameFormat.fromUrn(a.getNameFormat()))
          .setValues(getJavaValues(a.getAttributeValues()))
      );
    }
  }
  return result;
}

代码示例来源:origin: org.apache.syncope.ext.saml2sp/syncope-ext-saml2sp-logic

if (!attr.getAttributeValues().isEmpty()) {
  String attrName = attr.getFriendlyName() == null ? attr.getName() : attr.getFriendlyName();
  if (attrName.equals(idp.getConnObjectKeyItem().getExtAttrName())) {
    if (attr.getAttributeValues().get(0) instanceof XSString) {
      keyValue = ((XSString) attr.getAttributeValues().get(0)).getValue();
    } else if (attr.getAttributeValues().get(0) instanceof XSAny) {
      keyValue = ((XSAny) attr.getAttributeValues().get(0)).getTextContent();
  attr.getAttributeValues().stream().
      filter(value -> value.getDOM() != null).
      forEachOrdered(value -> {

代码示例来源:origin: net.shibboleth.idp/idp-saml-impl

/**
 * Add Liberty SSOS service Endpoint Reference (EPR) attribute to Assertion's AttributeStatement.
 * 
 * @param requestContext the current request context
 * @param assertion the delegated assertion being issued
 */
private void addLibertySSOSEPRAttribute(@Nonnull final ProfileRequestContext requestContext, 
    @Nonnull final Assertion assertion) {
  final Attribute attribute = (Attribute) XMLObjectSupport.buildXMLObject(Attribute.DEFAULT_ELEMENT_NAME);
  attribute.setName(LibertyConstants.SERVICE_TYPE_SSOS);
  attribute.setNameFormat(Attribute.URI_REFERENCE);
  attribute.getAttributeValues().add(buildLibertSSOSEPRAttributeValue(requestContext, assertion));
  
  final List<AttributeStatement> attributeStatements = assertion.getAttributeStatements();
  AttributeStatement attributeStatement = null;
  if (attributeStatements.isEmpty()) {
    attributeStatement = 
        (AttributeStatement) XMLObjectSupport.buildXMLObject(AttributeStatement.DEFAULT_ELEMENT_NAME);
    assertion.getAttributeStatements().add(attributeStatement);
  } else {
    attributeStatement = attributeStatements.get(0);
  }
  attributeStatement.getAttributes().add(attribute);
}

代码示例来源:origin: org.apereo.cas/cas-server-support-saml-idp-web

private boolean shouldEncryptAttribute(final Attribute attribute) {
    val encryptableAttributes = service.getEncryptableAttributes();
    if (encryptableAttributes == null || encryptableAttributes.isEmpty() || encryptableAttributes.contains("*")) {
      LOGGER.debug("No explicit attribute encryption rules are defined; Attribute [{}] is selected for encryption.", attribute.getName());
      return true;
    }
    if (encryptableAttributes.contains(attribute.getName())) {
      LOGGER.debug("Attribute encryption rules allow [{}] to be encrypted", attribute.getName());
      return true;
    }
    LOGGER.debug("Skipping encryption as attribute encryption rules do NOT allow [{}] to be encrypted", attribute.getName());
    return false;
  }
}

代码示例来源:origin: codice/ddf

private static SortedSet<String> getAttributeValues(
   org.opensaml.saml.saml2.core.Attribute attribute) {
  return attribute
    .getAttributeValues()
    .stream()
    .filter(XSString.class::isInstance)
    .map(XSString.class::cast)
    .map(XSString::getValue)
    .collect(Collectors.toCollection(TreeSet::new));
 }
}

代码示例来源:origin: spring-projects/spring-security-saml

org.opensaml.saml.saml2.core.Attribute attribute =
  buildSAMLObject(org.opensaml.saml.saml2.core.Attribute.class);
attribute.setName(attr.getName());
attribute.setFriendlyName(attr.getFriendlyName());
attribute.setNameFormat(attr.getNameFormat().toString());
attr.getValues().stream().forEach(
  av -> attribute.getAttributeValues().add(objectToXmlObject(av))
);
astmt.getAttributes().add(attribute);

代码示例来源:origin: org.wso2.carbon.identity.inbound.auth.saml2/org.wso2.carbon.identity.query.saml

/**
 * This method is used to build Attribute Statement including user attributes
 *
 * @param claims List of requested claims
 * @return AttributeStatement set of attributes contain inside attribute statement
 * @throws  IdentitySAML2QueryException If unable to filter attributes from Map
 */
public static AttributeStatement buildAttributeStatement(Map<String, String> claims) throws IdentitySAML2QueryException {
  AttributeStatement attStmt = null;
  if (claims != null) {
    attStmt = new AttributeStatementBuilder().buildObject();
    Iterator<String> iterator = claims.keySet().iterator();
    for (int i = 0; i < claims.size(); i++) {
      Attribute attrib = new AttributeBuilder().buildObject();
      String claimUri = iterator.next();
      attrib.setName(claimUri);
      XSStringBuilder stringBuilder =
          (XSStringBuilder) XMLObjectProviderRegistrySupport.getBuilderFactory()
              .getBuilder(XSString.TYPE_NAME);
      XSString stringValue =
          stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME,
              XSString.TYPE_NAME);
      stringValue.setValue(claims.get(claimUri));
      attrib.getAttributeValues().add(stringValue);
      attStmt.getAttributes().add(attrib);
    }
  }
  return attStmt;
}

代码示例来源:origin: org.wso2.carbon.identity.inbound.auth.saml2/org.wso2.carbon.identity.query.saml

/**
   * This method is used to convert required claim list into a String array
   *
   * @param claimattributes List of requested claims
   * @return String[] List of requested claims
   * @throws  IdentitySAML2QueryException If friendly name is null
   */
  private String[] getAttributesAsArray(List<Attribute> claimattributes) throws IdentitySAML2QueryException {
    List<String> list = new ArrayList<String>();
    String[] claimArray = null;
    if (claimattributes.size() > 0) {
      for (Attribute attribute : claimattributes) {
        if (attribute.getFriendlyName() != null) {
          list.add(attribute.getFriendlyName());
        }
      }
      claimArray = list.toArray(new String[list.size()]);
      return claimArray;
    }
    return claimArray;
  }
}

代码示例来源:origin: org.pac4j/pac4j-saml

samlAttributes.forEach(attribute -> {
  final SAMLAttribute samlAttribute = new SAMLAttribute();
  samlAttribute.setFriendlyName(attribute.getFriendlyName());
  samlAttribute.setName(attribute.getName());
  samlAttribute.setNameFormat(attribute.getNameFormat());
  attribute.getAttributeValues().forEach(xmlObject -> {
    final Element dom = xmlObject.getDOM();
    if (dom != null && dom.getTextContent() != null) {

代码示例来源:origin: org.apereo.cas/cas-server-support-saml-idp-web

@Override
@SneakyThrows
public void build(final AttributeStatement attrStatement, final Attribute attribute) {
  if (!service.isEncryptAttributes() || !shouldEncryptAttribute(attribute)) {
    LOGGER.debug("Service [{}] is configured to not encrypt attributes for [{}]", service.getName(), attribute.getName());
    super.build(attrStatement, attribute);
    return;
  }
  val encryptedAttribute = samlObjectEncrypter.encode(attribute, service, adaptor);
  LOGGER.debug("Encrypted attribute [{}] for service [{}]", attribute.getName(), service.getName());
  attrStatement.getEncryptedAttributes().add(encryptedAttribute);
}

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

/** {@inheritDoc} */
protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
    throws UnmarshallingException {
  Attribute attribute = (Attribute) parentSAMLObject;
  QName childQName = childSAMLObject.getElementQName();
  if ("AttributeValue".equals(childQName.getLocalPart())
      && childQName.getNamespaceURI().equals(SAMLConstants.SAML20_NS)) {
    attribute.getAttributeValues().add(childSAMLObject);
  } else {
    super.processChildElement(parentSAMLObject, childSAMLObject);
  }
}

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

/**
 * Create an Attribute object.
 *
 * @param friendlyName of type String
 * @param name of type String
 * @param nameFormat of type String
 * @return an Attribute object
 */
@SuppressWarnings("unchecked")
public static Attribute createAttribute(String friendlyName, String name, String nameFormat) {
  if (attributeBuilder == null) {
    attributeBuilder = (SAMLObjectBuilder<Attribute>)
      builderFactory.getBuilder(Attribute.DEFAULT_ELEMENT_NAME);
  }
  Attribute attribute = attributeBuilder.buildObject();
  attribute.setFriendlyName(friendlyName);
  if (nameFormat == null) {
    attribute.setNameFormat(SAML2Constants.ATTRNAME_FORMAT_URI);
  } else {
    attribute.setNameFormat(nameFormat);
  }
  attribute.setName(name);
  return attribute;
}

代码示例来源:origin: org.apache.cxf/cxf-rt-ws-security

private boolean findClaimInAssertion(org.opensaml.saml.saml2.core.Assertion assertion, URI claimURI) {
  List<org.opensaml.saml.saml2.core.AttributeStatement> attributeStatements =
    assertion.getAttributeStatements();
  if (attributeStatements == null || attributeStatements.isEmpty()) {
    return false;
  }
  for (org.opensaml.saml.saml2.core.AttributeStatement statement : attributeStatements) {
    List<org.opensaml.saml.saml2.core.Attribute> attributes = statement.getAttributes();
    for (org.opensaml.saml.saml2.core.Attribute attribute : attributes) {
      if (attribute.getName().equals(claimURI.toString())
        && attribute.getAttributeValues() != null && !attribute.getAttributeValues().isEmpty()) {
        return true;
      }
    }
  }
  return false;
}

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

if (a.getName() != null && a.getName().equals(input.getName())
    && (input.getNameFormat() == null || input.getNameFormat().equals(a.getNameFormat()))) {
    final String tagvalstr = tagvals.get(tagindex);
    final List<XMLObject> cvals = a.getAttributeValues();
    for (final XMLObject cval : cvals) {
      final String cvalstr = xmlObjectToString(cval);
    final List<XMLObject> cvals = a.getAttributeValues();
    for (final XMLObject cval : cvals) {
      final String cvalstr = xmlObjectToString(cval);

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

for (Attribute atr : as.getAttributes()) {
  SAMLClaim claim = new SAMLClaim();
  claim.setClaimType(atr.getName());
  claim.setName(atr.getName());
  claim.setNameFormat(atr.getNameFormat());
  claim.setFriendlyName(atr.getFriendlyName());
  for (XMLObject o : atr.getAttributeValues()) {
    String attrValue = o.getDOM().getTextContent();
    claim.getValues().add(attrValue);

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

log.info("Adding EntityAttribute ({}) to EntityDescriptor ({})", attribute.getName(),
    descriptor.getEntityID());
final Attribute copy = XMLObjectSupport.cloneXMLObject(attribute);

相关文章