当前位置: 首页>>代码示例>>Java>>正文


Java Attribute.getAttributeValues方法代码示例

本文整理汇总了Java中org.opensaml.saml2.core.Attribute.getAttributeValues方法的典型用法代码示例。如果您正苦于以下问题:Java Attribute.getAttributeValues方法的具体用法?Java Attribute.getAttributeValues怎么用?Java Attribute.getAttributeValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.opensaml.saml2.core.Attribute的用法示例。


在下文中一共展示了Attribute.getAttributeValues方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAssertionStatements

import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
private Map<String, String> getAssertionStatements(Assertion assertion) {

        Map<String, String> results = new HashMap<String, String>();

        if (assertion != null && assertion.getAttributeStatements() != null) {

            List<AttributeStatement> attributeStatementList = assertion.getAttributeStatements();


            for (AttributeStatement statement : attributeStatementList) {
                List<Attribute> attributesList = statement.getAttributes();
                for (Attribute attribute : attributesList) {
                    List<String> valueList = new ArrayList<>();
                    for (XMLObject xmlObject : attribute.getAttributeValues()) {
                        valueList.add(xmlObject.getDOM().getTextContent());
                    }
                    String value = StringUtils.join(valueList, ",");
                    results.put(attribute.getName(), value);
                }
            }

        }
        return results;
    }
 
开发者ID:wso2-extensions,项目名称:identity-agent-sso,代码行数:25,代码来源:SAML2SSOManager.java

示例2: getAssertionAttributeStringValueList

import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
/**
 * Get a list of string values for each value under a named Attribute in an Assertion from the SAML Response
 *
 * @param pSamlResponse Response with one assertion in it containing 0 or more attributes
 * @param pAttributeName Name of the attribute to get a list of values from
 * @return List of values for SAMLResponse/Assertion/Attribute[name=pAttributeName]
 */
private List<String> getAssertionAttributeStringValueList(Response pSamlResponse, String pAttributeName) {
  List<Attribute> lAttributesList = getResponseAttributes(pSamlResponse);

  for (Attribute lAttribute : lAttributesList) {
    if (!pAttributeName.equals(lAttribute.getName())) {
      continue;
    }
    List<XMLObject> lAttributeValues = lAttribute.getAttributeValues();

    return lAttributeValues.stream()
      // This could deserialise lXMLObject into a typed attribute but all attribute values we're interested in should just have plain text content
      .map(lAttrVal -> lAttrVal.getDOM().getTextContent())
      .collect(Collectors.toList());
  }

  return Collections.emptyList();
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:25,代码来源:AuthTypeSAML.java

示例3: getValueFromAttributeStatements

import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
public static String getValueFromAttributeStatements(final List<AttributeStatement> attributeStatements, final String attributeKey) {
    if (attributeStatements == null || attributeStatements.size() < 1 || attributeKey == null) {
        return null;
    }
    for (AttributeStatement attributeStatement : attributeStatements) {
        if (attributeStatement == null || attributeStatements.size() < 1) {
            continue;
        }
        for (Attribute attribute : attributeStatement.getAttributes()) {
            if (attribute.getAttributeValues() != null && attribute.getAttributeValues().size() > 0) {
                String value = attribute.getAttributeValues().get(0).getDOM().getTextContent();
                s_logger.debug("SAML attribute name: " + attribute.getName() + " friendly-name:" + attribute.getFriendlyName() + " value:" + value);
                if (attributeKey.equals(attribute.getName()) || attributeKey.equals(attribute.getFriendlyName())) {
                    return value;
                }
            }
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:21,代码来源:SAMLUtils.java

示例4: processAuthnAttributes

import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
/**
 * Add each assertion attributes and its values in the authentication data object.
 * 
 * @param assertion
 *            the assertion
 * @param authn
 *            the authentication data object
 * @throws DecryptionException
 * @throws SamlSecurityException
 */
protected void processAuthnAttributes(final Assertion assertion, final IInternalAuthentication authn)
		throws SamlSecurityException, DecryptionException {
	final List<Attribute> attributes = this.retrieveAttributes(assertion);
	if (!CollectionUtils.isEmpty(attributes)) {
		for (final Attribute attr : attributes) {
			if (attr != null) {
				final List<String> values = new ArrayList<String>();
				for (final XMLObject value : attr.getAttributeValues()) {
					if (value != null) {
						final String textContent = value.getDOM().getTextContent();
						if (StringUtils.hasText(textContent)) {
							values.add(textContent);
						}
					}
				}

				final String attrName = attr.getName();
				if (!CollectionUtils.isEmpty(values)) {
					authn.addAttribute(attrName, values);
				}
			}
		}
	}
}
 
开发者ID:mxbossard,项目名称:java-saml2-sp,代码行数:35,代码来源:AuthnResponseQueryProcessor.java

示例5: testUnmarshallExampleAttribute

import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
/**
 * Test unmarshalling an attribute holding a CurrentAddress type. Example is from eIDAS specs.
 * <p>
 * The example contains the Base64-encoding of the following XML-snippet:
 * 
 * <pre>
 *  <eidas:LocatorDesignator>22</eidas:LocatorDesignator>
 *  <eidas:Thoroughfare>Arcacia Avenue</eidas:Thoroughfare>
 *  <eidas:PostName>London</eidas:PostName>
*   <eidas:PostCode>SW1A 1AA</eidas:Postcode>
 * </pre>
 * </p>
 * 
 * @throws Exception
 *           for errors.
 */
@Test
public void testUnmarshallExampleAttribute() throws Exception {

  final String xml = "<saml:Attribute FriendlyName=\"CurrentAddress\" Name=\"http://eidas.europa.eu/attributes/naturalperson/CurrentAddress\" NameFormat=\"urn:oasis:names:tc:SAML:2.0:attrname-format:uri\" xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
      + "<saml:AttributeValue xmlns:eidas=\"http://eidas.europa.eu/attributes/naturalperson\" xsi:type=\"eidas:CurrentAddressType\">"
      + "PGVpZGFzOkxvY2F0b3JEZXNpZ25hdG9yPjIyPC9laWRhczpMb2NhdG9yRGVzaWduYX\n"
      + "Rvcj48ZWlkYXM6VGhvcm91Z2hmYXJlPkFyY2FjaWEgQXZlbnVlPC9laWRhczpUaG9y\n"
      + "b3VnaGZhcmU+DQo8ZWlkYXM6UG9zdE5hbWU+TG9uZG9uPC9laWRhczpQb3N0TmFtZT\n"
      + "4NCjxlaWRhczpQb3N0Q29kZT5TVzFBIDFBQTwvZWlkYXM6UG9zdENvZGU+"
      + "</saml:AttributeValue>"
      + "</saml:Attribute>";

  Document doc = Configuration.getParserPool().parse(new ByteArrayInputStream(xml.getBytes("UTF-8")));
  Element elm = doc.getDocumentElement();

  Attribute attribute = OpenSAMLTestBase.unmarshall(elm, Attribute.class);
  Assert.assertNotNull(attribute);
  Assert.assertEquals(AttributeConstants.EIDAS_CURRENT_ADDRESS_ATTRIBUTE_NAME, attribute.getName());
  Assert.assertEquals(AttributeConstants.EIDAS_CURRENT_ADDRESS_ATTRIBUTE_FRIENDLY_NAME, attribute.getFriendlyName());

  List<XMLObject> values = attribute.getAttributeValues();
  Assert.assertTrue(values.size() == 1);
  Assert.assertTrue(values.get(0) instanceof CurrentAddressType);
  CurrentAddressType address = (CurrentAddressType) values.get(0);
  Assert.assertEquals("22", address.getLocatorDesignator());
  Assert.assertEquals("Arcacia Avenue", address.getThoroughfare());
  Assert.assertEquals("London", address.getPostName());
  Assert.assertEquals("SW1A 1AA", address.getPostCode());
}
 
开发者ID:litsec,项目名称:eidas-opensaml,代码行数:46,代码来源:CurrentAddressTypeTest.java

示例6: testAttributeCreate

import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
/**
 * Test that creates an attribute and places a CurrentAddessType as a value.
 * 
 * @throws Exception
 *           for errors
 */
@Test
public void testAttributeCreate() throws Exception {

  Attribute attribute = OpenSAMLTestBase.createSamlObject(Attribute.class, Attribute.DEFAULT_ELEMENT_NAME);
  attribute.getNamespaceManager().registerNamespaceDeclaration(new Namespace(EidasConstants.EIDAS_NP_NS, "eidas"));
  attribute.setName(AttributeConstants.EIDAS_CURRENT_ADDRESS_ATTRIBUTE_NAME);
  attribute.setFriendlyName(AttributeConstants.EIDAS_CURRENT_ADDRESS_ATTRIBUTE_FRIENDLY_NAME);
  attribute.setNameFormat(Attribute.URI_REFERENCE);

  XMLObjectBuilder<CurrentAddressType> builder = OpenSAMLTestBase.getBuilder(CurrentAddressType.TYPE_NAME);
  CurrentAddressType address = builder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, 
    new QName(EidasConstants.EIDAS_NP_NS, CurrentAddressType.TYPE_NAME.getLocalPart(), "eidas"));
  fill(address);

  attribute.getAttributeValues().add(address);

  Element attrElement = OpenSAMLTestBase.marshall(attribute);

  System.out.println(XMLHelper.prettyPrintXML(attrElement));

  // Make sure we inserted the correct namespace prefix while marshalling the CurrentAddressType
  Assert.assertTrue((new String(Base64.decode(attrElement.getFirstChild().getFirstChild().getNodeValue()))).startsWith("<eidas:"));

  // Unmarshall
  Attribute attribute2 = OpenSAMLTestBase.unmarshall(attrElement, Attribute.class);

  Assert.assertNotNull(attribute2);
  Assert.assertEquals(AttributeConstants.EIDAS_CURRENT_ADDRESS_ATTRIBUTE_NAME, attribute2.getName());
  Assert.assertEquals(AttributeConstants.EIDAS_CURRENT_ADDRESS_ATTRIBUTE_FRIENDLY_NAME, attribute2.getFriendlyName());

  List<XMLObject> values = attribute.getAttributeValues();
  Assert.assertTrue(values.size() == 1);
  Assert.assertTrue(values.get(0) instanceof CurrentAddressType);
  CurrentAddressType address2 = (CurrentAddressType) values.get(0);
  verify(address, address2);
}
 
开发者ID:litsec,项目名称:eidas-opensaml,代码行数:43,代码来源:CurrentAddressTypeTest.java

示例7: getValue

import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
private String getValue(Attribute attribute) {
    List<XMLObject> attributeValues = attribute.getAttributeValues();
    if (attributeValues == null || attributeValues.size() == 0) {
        return null;
    }
    XMLObject xmlValue = attributeValues.iterator().next();
    return getString(xmlValue);
}
 
开发者ID:ulisesbocchio,项目名称:spring-boot-security-saml-samples,代码行数:9,代码来源:SAMLUserDetails.java

示例8: getAssertionAttributeStringValue

import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
/**
 * Get a list of string values for each value under a named Attribute in an Assertion from the SAML Response
 *
 * @param pSamlResponse Response with one assertion in it containing 0 or more attributes
 * @param pAttributeName Name of the attribute to get a list of values from
 * @return List of values for SAMLResponse/Assertion/Attribute[name=pAttributeName]
 */
private String getAssertionAttributeStringValue(Response pSamlResponse, String pAttributeName) {
  List<Attribute> lAttributesList = getResponseAttributes(pSamlResponse);

  for (Attribute lAttribute : lAttributesList) {
    if (!pAttributeName.equals(lAttribute.getName())) {
      continue;
    }
    List<XMLObject> lAttributeValues = lAttribute.getAttributeValues();

    return lAttributeValues.get(0).getDOM().getTextContent();
  }

  return null;
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:22,代码来源:AuthTypeSAML.java

示例9: authenticate

import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    if (configurationMediator.isSungardasSSO()) {
        Authentication result = super.authenticate(authentication);

        SAMLCredential credential = (SAMLCredential) result.getCredentials();
        Attribute attribute = credential.getAttribute(ALLOWED_LIST_ATTRIBUTE_NAME);
        if (attribute != null) {
            for (XMLObject object : attribute.getAttributeValues()) {
                String value = ((XSStringImpl) object).getValue();
                if (ADMIN_WILDCARD_EXP.equals(value)) {
                    LOG.warn("User ({}) has admin access, instance UUID: {}", credential.getNameID().getValue(), configurationMediator.getUUID());
                    return result;
                }
                if (configurationMediator.getUUID().equals(value)) {
                    return result;
                }
            }
        }

        LOG.error("User ({}) has not allowed to use this instance with UUID: {}", credential.getNameID().getValue(), configurationMediator.getUUID());

        userService.removeUser(result.getName());

        throw new AuthenticationServiceException("Access denied");
    } else {
        return super.authenticate(authentication);
    }
}
 
开发者ID:SungardAS,项目名称:enhanced-snapshots,代码行数:30,代码来源:SAMLAuthenticationProviderImpl.java

示例10: getUsernameFromAssertion

import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
/**
 * Get the username from the SAML2 Assertion
 *
 * @param assertion SAML2 assertion
 * @return username
 */
public static String getUsernameFromAssertion(Assertion assertion) {

    String loginAttributeName = getLoginAttributeName();

    if (loginAttributeName != null) {
        // There can be multiple AttributeStatements in Assertion
        List<AttributeStatement> attributeStatements = assertion
                .getAttributeStatements();
        if (attributeStatements != null) {
            for (AttributeStatement attributeStatement : attributeStatements) {
                // There can be multiple Attributes in a
                // attributeStatement
                List<Attribute> attributes = attributeStatement
                        .getAttributes();
                if (attributes != null) {
                    for (Attribute attribute : attributes) {
                        String attributeName = attribute.getDOM()
                                .getAttribute("Name");
                        if (attributeName.equals(loginAttributeName)) {
                            List<XMLObject> attributeValues = attribute
                                    .getAttributeValues();
                            // There can be multiple attribute values in
                            // a attribute, but get the first one
                            return attributeValues.get(0).getDOM()
                                    .getTextContent();
                        }
                    }
                }
            }
        }
    }
    return assertion.getSubject().getNameID().getValue();
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:40,代码来源:Util.java

示例11: getValue

import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
private String getValue(final Attribute attr) {
	if (attr == null) {
		return null;
	}
	
	if (attr.getAttributeValues() != null) {
		return getAttrValue(attr.getAttributeValues());
	}
	
	return null;
}
 
开发者ID:callista-software,项目名称:spring-saml,代码行数:12,代码来源:CitizenAuthenticationService.java

示例12: roleRelatedAttributeToGrantedAuthorities

import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
private Collection<GrantedAuthority> roleRelatedAttributeToGrantedAuthorities( Attribute roleRelatedAttribute ) {

    Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();

    if( roleRelatedAttribute != null && roleRelatedAttribute.hasChildren() ){

      List<XMLObject> roleXmlValues = roleRelatedAttribute.getAttributeValues();

      for( XMLObject xmlValue : roleXmlValues ) {

        if( xmlValue == null ){
          logger.warn( "Empty value for attribute '" + roleRelatedAttribute + "'" );
          continue;
        }

        String sanitizedValue = "";

        if( xmlValue instanceof XSStringImpl ) {
          sanitizedValue = ( ( XSStringImpl ) xmlValue ).getValue();
        } else if( xmlValue instanceof XSAnyImpl ) {
          sanitizedValue = ( ( XSAnyImpl ) xmlValue ).getTextContent();
        } else {
          logger.warn( "Unknown attribute type: " + xmlValue.toString() );
          continue;
        }

        // if there's a prefix configured, check it ( and trim it )
        if( getRoleRelatedAttributePrefix() != null && !getRoleRelatedAttributePrefix().isEmpty()
            && sanitizedValue.startsWith( getRoleRelatedAttributePrefix() ) ){

          sanitizedValue = sanitizedValue.replace( getRoleRelatedAttributePrefix(), "" );
        }

        // finally, add it to the authorities list as a granted authority
        if( sanitizedValue != null && !sanitizedValue.isEmpty() ) {
          authorities.add( new SimpleGrantedAuthority( sanitizedValue ) );
        }
      }
    }

    return authorities;
  }
 
开发者ID:pentaho,项目名称:pentaho-engineering-samples,代码行数:43,代码来源:PentahoSamlNativeUserDetailsService.java


注:本文中的org.opensaml.saml2.core.Attribute.getAttributeValues方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。