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


Java Attribute类代码示例

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


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

示例1: query

import org.opensaml.saml2.core.Attribute; //导入依赖的package包/类
public Collection<UserAttribute> query(String nameId, NameIDFormat format, UserAttribute... attributes)
		throws InvalidCertificateException, IOException {
	OIOAttributeQuery q = OIOAttributeQuery.newQuery(
			idpMetadata.getAttributeQueryServiceLocation(SAMLConstants.SAML2_SOAP11_BINDING_URI), nameId, format,
			spEntityId);
	for (UserAttribute attribute : attributes) {
		q.addAttribute(attribute.getName(), attribute.getFormat());
	}
	OIOAssertion res = q.executeQuery(client, credential, username, password, ignoreCertPath,
			idpMetadata.getCertificates(), !requireEncryption);
	Collection<UserAttribute> attrs = new ArrayList<UserAttribute>();
	for (AttributeStatement attrStatement : res.getAssertion().getAttributeStatements()) {
		for (Attribute attr : attrStatement.getAttributes()) {
			attrs.add(new UserAttribute(attr.getName(), attr.getFriendlyName(), AttributeUtil
					.extractAttributeValueValues(attr), attr.getNameFormat()));
		}
	}
	return attrs;
}
 
开发者ID:amagdenko,项目名称:oiosaml.java,代码行数:20,代码来源:UserAttributeQuery.java

示例2: processChildElement

import org.opensaml.saml2.core.Attribute; //导入依赖的package包/类
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentObject, XMLObject childObject) throws UnmarshallingException {
    IDPSSODescriptor descriptor = (IDPSSODescriptor) parentObject;

    if (childObject instanceof SingleSignOnService) {
        descriptor.getSingleSignOnServices().add((SingleSignOnService) childObject);
    } else if (childObject instanceof NameIDMappingService) {
        descriptor.getNameIDMappingServices().add((NameIDMappingService) childObject);
    } else if (childObject instanceof AssertionIDRequestService) {
        descriptor.getAssertionIDRequestServices().add((AssertionIDRequestService) childObject);
    } else if (childObject instanceof AttributeProfile) {
        descriptor.getAttributeProfiles().add((AttributeProfile) childObject);
    } else if (childObject instanceof Attribute) {
        descriptor.getAttributes().add((Attribute) childObject);
    } else {
        super.processChildElement(parentObject, childObject);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:IDPSSODescriptorUnmarshaller.java

示例3: processChildElement

import org.opensaml.saml2.core.Attribute; //导入依赖的package包/类
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentElement, XMLObject childElement) throws UnmarshallingException {
    AttributeAuthorityDescriptor descriptor = (AttributeAuthorityDescriptor) parentElement;

    if (childElement instanceof AttributeService) {
        descriptor.getAttributeServices().add((AttributeService) childElement);
    } else if (childElement instanceof AssertionIDRequestService) {
        descriptor.getAssertionIDRequestServices().add((AssertionIDRequestService) childElement);
    } else if (childElement instanceof NameIDFormat) {
        descriptor.getNameIDFormats().add((NameIDFormat) childElement);
    } else if (childElement instanceof AttributeProfile) {
        descriptor.getAttributeProfiles().add((AttributeProfile) childElement);
    } else if (childElement instanceof Attribute) {
        descriptor.getAttributes().add((Attribute) childElement);
    } else {
        super.processChildElement(parentElement, childElement);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:AttributeAuthorityDescriptorUnmarshaller.java

示例4: validateUniqueAttributeIdentifiers

import org.opensaml.saml2.core.Attribute; //导入依赖的package包/类
/**
 * Checks that all the attributes have a unique Name/NameFormat pair.
 * 
 * @param query the attribute query to validate
 * 
 * @throws ValidationException thrown if more than on Name/NameFormat pair is found in the list of attributes in
 *             this query
 */
protected void validateUniqueAttributeIdentifiers(AttributeQuery query) throws ValidationException {
    List<Attribute> attributes = query.getAttributes();

    HashSet<Pair<String, String>> encounteredNames = new HashSet<Pair<String, String>>();
    String attributeName;
    String attributeNameFormat;
    for (Attribute attribute : attributes) {
        attributeName = attribute.getName();
        attributeNameFormat = attribute.getNameFormat();
        if (DatatypeHelper.isEmpty(attributeNameFormat)) {
            // SAML 2 core, sec. 2.7.3.1, if no format is specified,
            // unspecified is in effect. This avoids bug in processing null value.
            attributeNameFormat = Attribute.UNSPECIFIED;
        }
        
        Pair<String, String> pair = new Pair<String, String>(attributeName, attributeNameFormat);
        if (encounteredNames.contains(pair)) {
            throw new ValidationException(
                    "Attribute query contains more than one attribute with the same Name and NameFormat");
        } else {
            encounteredNames.add(pair);
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:AttributeQuerySchemaValidator.java

示例5: processAttribute

import org.opensaml.saml2.core.Attribute; //导入依赖的package包/类
/** {@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 {
        QName attribQName = XMLHelper.getNodeQName(attribute);
        if (attribute.isId()) {
            attrib.getUnknownAttributes().registerID(attribQName);
        }
        attrib.getUnknownAttributes().put(attribQName, attribute.getValue());
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:AttributeUnmarshaller.java

示例6: testAttributes

import org.opensaml.saml2.core.Attribute; //导入依赖的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

示例7: testAttributes

import org.opensaml.saml2.core.Attribute; //导入依赖的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");
}
 
开发者ID:ulisesbocchio,项目名称:spring-boot-security-saml,代码行数:26,代码来源:SAMLUserDetailsTest.java

示例8: 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

示例9: printAssertion

import org.opensaml.saml2.core.Attribute; //导入依赖的package包/类
public static void printAssertion(Assertion assertion) {
  
  System.out.println("Attributes:");
  if (assertion.getAttributeStatements().isEmpty()) {
    System.out.println("  No attribute statement available in assertion");
  }
  else {
    AttributeStatement as = assertion.getAttributeStatements().get(0);
    for (Attribute attr : as.getAttributes()) {
      System.out.println("  " + attr.getName());        
    }
  }
  
  // TODO
  
}
 
开发者ID:litsec,项目名称:eidas-opensaml,代码行数:17,代码来源:ParseAssertionExample.java

示例10: testUnmarshallExample

import org.opensaml.saml2.core.Attribute; //导入依赖的package包/类
/**
 * Verifies that we can unmarshall the example given in section 2.4 of
 * <a href="https://joinup.ec.europa.eu/sites/default/files/eidas_saml_attribute_profile_v1.0_2.pdf">eIDAS SAML
 * Attribute Profile</a>.
 * 
 * @throws Exception
 *           for errors
 */
@Test
public void testUnmarshallExample() throws Exception {
  InputStream is = this.getClass().getResourceAsStream("/example-transliteration.xml");
  Attribute attribute = (Attribute) OpenSAMLTestBase.unmarshallFromInputStream(Configuration.getParserPool(), is);
  Assert.assertNotNull(attribute);

  Assert.assertEquals(AttributeConstants.EIDAS_CURRENT_FAMILY_NAME_ATTRIBUTE_NAME, attribute.getName());
  Assert.assertEquals(AttributeConstants.EIDAS_CURRENT_FAMILY_NAME_ATTRIBUTE_FRIENDLY_NAME, attribute.getFriendlyName());
  Assert.assertEquals(Attribute.URI_REFERENCE, attribute.getNameFormat());

  Assert.assertTrue(attribute.getAttributeValues().size() == 2);
  Assert.assertTrue(attribute.getAttributeValues().get(0) instanceof CurrentFamilyNameType);
  Assert.assertTrue(attribute.getAttributeValues().get(1) instanceof CurrentFamilyNameType);

  CurrentFamilyNameType v1 = (CurrentFamilyNameType) attribute.getAttributeValues().get(0);
  Assert.assertTrue(v1.getLatinScript());
  Assert.assertNull(v1.getLatinScriptXSBooleanValue());
  Assert.assertEquals("Onasis", v1.getValue());

  CurrentFamilyNameType v2 = (CurrentFamilyNameType) attribute.getAttributeValues().get(1);
  Assert.assertFalse(v2.getLatinScript());
  Assert.assertNotNull(v2.getLatinScriptXSBooleanValue());
  Assert.assertEquals("Ωνασης", v2.getValue());
  Assert.assertEquals("&#937;&#957;&#945;&#963;&#951;&#962;", StringEscapeUtils.escapeXml(v2.getValue()));
}
 
开发者ID:litsec,项目名称:eidas-opensaml,代码行数:34,代码来源:CurrentFamilyNameTypeTest.java

示例11: userDetailsService

import org.opensaml.saml2.core.Attribute; //导入依赖的package包/类
@Bean
public SAMLUserDetailsService userDetailsService() {
    return new SAMLUserDetailsService() {
        @Override
        public Object loadUserBySAML(SAMLCredential samlCredential) throws UsernameNotFoundException {
            return new SAMLUserDetails(samlCredential) {
                @Override
                public Map<String, String> getAttributes() {
                    return samlCredential.getAttributes().stream()
                            .collect(Collectors.toMap(Attribute::getName, this::getValue));
                }

                private String getValue(Attribute attribute) {
                    return Optional.ofNullable(getAttribute(attribute.getName())).orElse("");
                }
            };
        }
    };
}
 
开发者ID:ulisesbocchio,项目名称:spring-boot-security-saml-samples,代码行数:20,代码来源:Auth0SSODemoApplication.java

示例12: failOnMissingPrivilege

import org.opensaml.saml2.core.Attribute; //导入依赖的package包/类
@Test
public void failOnMissingPrivilege() throws Exception {
	final OIOAssertion assertion = getAssertion("assertion.xml", "1029275212");

	Attribute attr = AttributeUtil.createAttribute(Constants.AUTHORISATIONS_ATTRIBUTE, "", "uri");
	XSAnyBuilder builder = new XSAnyBuilder();
	XSAny ep = builder.buildObject(SAMLConstants.SAML20_NS, AttributeValue.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX);

	XSAnyUnmarshaller unmarshaller = new XSAnyUnmarshaller();
	XMLObject val = unmarshaller.unmarshall(SAMLUtil.loadElementFromString(IOUtils.toString(getClass().getResourceAsStream("authorisations.xml"))));
	ep.getUnknownXMLObjects().add(val);
	attr.getAttributeValues().add(ep);
	
	assertion.getAssertion().getAttributeStatements().get(0).getAttributes().add(attr);
	
	context.checking(new Expectations() {{
		one(req).getUserPrincipal(); will(returnValue(new OIOPrincipal(new UserAssertionImpl(assertion))));
		one(req).getSession();
		one(req).getRequestURI(); will(returnValue("/context/admin"));
		one(req).getContextPath(); will(returnValue("/context"));
		one(req).getMethod(); will(returnValue("post"));
		one(res).sendError(with(equal(HttpServletResponse.SC_FORBIDDEN)), with(any(String.class)));
	}});
	filter.doFilter(req, res, chain);
}
 
开发者ID:amagdenko,项目名称:oiosaml.java,代码行数:26,代码来源:AuthzFilterTest.java

示例13: testGrantAccess

import org.opensaml.saml2.core.Attribute; //导入依赖的package包/类
@Test
public void testGrantAccess() throws Exception {
	final OIOAssertion assertion = getAssertion("assertion.xml", "1029275212");

	Attribute attr = AttributeUtil.createAttribute(Constants.AUTHORISATIONS_ATTRIBUTE, "", "uri");
	XSAnyBuilder builder = new XSAnyBuilder();
	XSAny ep = builder.buildObject(SAMLConstants.SAML20_NS, AttributeValue.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX);

	XSAnyUnmarshaller unmarshaller = new XSAnyUnmarshaller();
	XMLObject val = unmarshaller.unmarshall(SAMLUtil.loadElementFromString(IOUtils.toString(getClass().getResourceAsStream("authorisations.xml"))));
	ep.getUnknownXMLObjects().add(val);
	attr.getAttributeValues().add(ep);
	
	assertion.getAssertion().getAttributeStatements().get(0).getAttributes().add(attr);
	
	context.checking(new Expectations() {{
		one(req).getUserPrincipal(); will(returnValue(new OIOPrincipal(new UserAssertionImpl(assertion))));
		one(req).getSession();
		one(req).getRequestURI(); will(returnValue("/context/test"));
		one(req).getContextPath(); will(returnValue("/context"));
		one(req).getMethod(); will(returnValue("post"));
		one(chain).doFilter(req, res);
	}});
	filter.doFilter(req, res, chain);
}
 
开发者ID:amagdenko,项目名称:oiosaml.java,代码行数:26,代码来源:AuthzFilterTest.java

示例14: query

import org.opensaml.saml2.core.Attribute; //导入依赖的package包/类
public Collection<UserAttribute> query(String nameId, NameIDFormat format, UserAttribute... attributes)
		throws InvalidCertificateException, IOException {
	OIOAttributeQuery q = OIOAttributeQuery.newQuery(
			idpMetadata.getAttributeQueryServiceLocation(SAMLConstants.SAML2_SOAP11_BINDING_URI), nameId, format,
			spEntityId);
	for (UserAttribute attribute : attributes) {
		q.addAttribute(attribute.getName(), attribute.getFormat());
	}
	OIOAssertion res = q.executeQuery(client, credential, username, password, ignoreCertPath,
			idpMetadata.getValidCertificates(), !requireEncryption);
	Collection<UserAttribute> attrs = new ArrayList<UserAttribute>();
	for (AttributeStatement attrStatement : res.getAssertion().getAttributeStatements()) {
		for (Attribute attr : attrStatement.getAttributes()) {
			attrs.add(new UserAttribute(attr.getName(), attr.getFriendlyName(), AttributeUtil
					.extractAttributeValueValues(attr), attr.getNameFormat()));
		}
	}
	return attrs;
}
 
开发者ID:amagdenko,项目名称:oiosaml.java,代码行数:20,代码来源:UserAttributeQuery.java

示例15: selectUser

import org.opensaml.saml2.core.Attribute; //导入依赖的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));
}
 
开发者ID:amagdenko,项目名称:oiosaml.java,代码行数:20,代码来源:DevelModeImpl.java


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