• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java AttributeValue类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: failOnMissingPrivilege

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


示例2: testGrantAccess

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


示例3: extractAttributeValueValue

import org.opensaml.saml2.core.AttributeValue; //导入依赖的package包/类
/**
 * Extract the value of the first attributeValue within an SAML20 attribute
 * 
 * @param attribute
 *            The attribute
 * @return The text value of the attributeValue
 */
public static String extractAttributeValueValue(Attribute attribute) {
	for (int i = 0; i < attribute.getAttributeValues().size(); i++) {
		if (attribute.getAttributeValues().get(i) instanceof XSString) {
			XSString str = (XSString) attribute.getAttributeValues().get(i);
			if (AttributeValue.DEFAULT_ELEMENT_LOCAL_NAME.equals(str.getElementQName().getLocalPart())
					&& SAMLConstants.SAML20_NS.equals(str.getElementQName().getNamespaceURI())) {
				return str.getValue();
			}
		} else {
			XSAny ep = (XSAny) attribute.getAttributeValues().get(i);
			if (AttributeValue.DEFAULT_ELEMENT_LOCAL_NAME.equals(ep.getElementQName().getLocalPart())
					&& SAMLConstants.SAML20_NS.equals(ep.getElementQName().getNamespaceURI())) {
				if (ep.getUnknownXMLObjects().size() > 0) {
					StringBuilder res = new StringBuilder();
					for (XMLObject obj : ep.getUnknownXMLObjects()) {
						res.append(XMLHelper.nodeToString(SAMLUtil.marshallObject(obj)));
					}
					return res.toString();
				}
				return ep.getTextContent();
			}
		}
	}
	return null;
}
 
开发者ID:amagdenko,项目名称:oiosaml.java,代码行数:33,代码来源:AttributeUtil.java


示例4: buildAttributeStatement

import org.opensaml.saml2.core.AttributeValue; //导入依赖的package包/类
/**
 * Build Attribute Statement
 *
 * @param claims
 * @return AttributeStatement
 */
private AttributeStatement buildAttributeStatement(Map<String, String> claims) {
    AttributeStatement attStmt = null;
    if (claims != null) {
        attStmt = new AttributeStatementBuilder().buildObject();
        Iterator<String> ite = claims.keySet().iterator();

        for (int i = 0; i < claims.size(); i++) {
            Attribute attrib = new AttributeBuilder().buildObject();
            String claimUri = ite.next();
            attrib.setName(claimUri);
            // look
            // https://wiki.shibboleth.net/confluence/display/OpenSAML/OSTwoUsrManJavaAnyTypes
            XSStringBuilder stringBuilder =
                    (XSStringBuilder) Configuration.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;
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:32,代码来源:SAMLResponseBuilder.java


示例5: createAttributeStatement

import org.opensaml.saml2.core.AttributeValue; //导入依赖的package包/类
private AttributeStatement createAttributeStatement(HashMap<String, List<String>> attributes) {
	// create authenticationstatement object
	AttributeStatementBuilder attributeStatementBuilder = new AttributeStatementBuilder();
	AttributeStatement attributeStatement = attributeStatementBuilder.buildObject();
	
	AttributeBuilder attributeBuilder = new AttributeBuilder();
	if (attributes != null) {
		for (Map.Entry<String, List<String>> entry : attributes.entrySet()) {
			Attribute attribute = attributeBuilder.buildObject();
			attribute.setName(entry.getKey());
			
			for (String value : entry.getValue()) {
				XSStringBuilder stringBuilder = new XSStringBuilder();
				XSString attributeValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
				attributeValue.setValue(value);
				attribute.getAttributeValues().add(attributeValue);
			}
			
			attributeStatement.getAttributes().add(attribute);
		}
	}
	
	return attributeStatement;
}
 
开发者ID:rackerlabs,项目名称:saml-generator,代码行数:25,代码来源:SamlAssertionProducer.java


示例6: buildAttributeStatement

import org.opensaml.saml2.core.AttributeValue; //导入依赖的package包/类
private AttributeStatement buildAttributeStatement() throws IllegalAccessException {
	AttributeStatement attributeStatement = buildXMLObjectDefaultName(AttributeStatement.class);

	Attribute attributeUserName = buildXMLObjectDefaultName(Attribute.class);

	XSStringBuilder stringBuilder = (XSStringBuilder)Configuration.getBuilderFactory().getBuilder(XSString.TYPE_NAME);
	XSString userNameValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
	userNameValue.setValue(MockIDPAuthnReq.userId);

	attributeUserName.getAttributeValues().add(userNameValue);
	attributeUserName.setName("uid");
	attributeStatement.getAttributes().add(attributeUserName);

	Attribute attributeLevel = buildXMLObjectDefaultName(Attribute.class);
	XSString levelValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
	levelValue.setValue(MockIDPAuthnReq.secLevel);

	attributeLevel.getAttributeValues().add(levelValue);
	attributeLevel.setName("SecurityLevel");
	attributeStatement.getAttributes().add(attributeLevel);

	return attributeStatement;

}
 
开发者ID:rasmusson,项目名称:MockIDP,代码行数:25,代码来源:MockIDPArtifactResolve.java


示例7: createAttributeStatement

import org.opensaml.saml2.core.AttributeValue; //导入依赖的package包/类
private static AttributeStatement createAttributeStatement() {

		AttributeStatement attributeStatement = create(AttributeStatement.DEFAULT_ELEMENT_NAME);

		for (AttributeData attributeData : samlResponseData.getAttributes()) {
			Attribute attribute = create(Attribute.DEFAULT_ELEMENT_NAME);
			attribute.setFriendlyName(attributeData.getFriendlyName());
			attribute.setName(attributeData.getName());
			attribute.setNameFormat(attributeData.getNameFormat());

			XMLObjectBuilder<XSAny> builder = getXMLObjectBuilder(XSAny.TYPE_NAME);

			for (String values : attributeData.getValue().split(";", -1)) {
				XSAny value = builder
						.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);

				value.setTextContent(values);

				attribute.getAttributeValues().add(value);
			}

			attributeStatement.getAttributes().add(attribute);
		}
		return attributeStatement;
	}
 
开发者ID:vetsin,项目名称:SamlSnort,代码行数:26,代码来源:SamlTool.java


示例8: testTransliteratedAttribute

import org.opensaml.saml2.core.AttributeValue; //导入依赖的package包/类
/**
 * Test creating and marshalling/unmarshalling an attribute with a name represented in two ways.
 * 
 * @throws Exception
 *           for errors
 */
@Test
public void testTransliteratedAttribute() throws Exception {
  Attribute attribute = OpenSAMLTestBase.createSamlObject(Attribute.class, Attribute.DEFAULT_ELEMENT_NAME);
  attribute.setName(AttributeConstants.EIDAS_CURRENT_FAMILY_NAME_ATTRIBUTE_NAME);
  attribute.setNameFormat(Attribute.URI_REFERENCE);

  XMLObjectBuilder<CurrentFamilyNameType> builder = OpenSAMLTestBase.getBuilder(CurrentFamilyNameType.TYPE_NAME);

  CurrentFamilyNameType name1 = builder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, CurrentFamilyNameType.TYPE_NAME);
  name1.setValue("Onasis");

  CurrentFamilyNameType name2 = builder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, CurrentFamilyNameType.TYPE_NAME);
  name2.setValue("Ωνασης");
  name2.setLatinScript(false);

  attribute.getAttributeValues().add(name1);
  attribute.getAttributeValues().add(name2);

  Element xml = OpenSAMLTestBase.marshall(attribute);

  Attribute attribute2 = OpenSAMLTestBase.unmarshall(xml, Attribute.class);
  Assert.assertEquals(((CurrentFamilyNameType) attribute.getAttributeValues().get(0)).getValue(), ((CurrentFamilyNameType) attribute2
    .getAttributeValues().get(0)).getValue());
  Assert.assertEquals(((CurrentFamilyNameType) attribute.getAttributeValues().get(1)).getValue(), ((CurrentFamilyNameType) attribute2
    .getAttributeValues().get(1)).getValue());

  // Unmarshall again, but this time from the XML string ...
  String xmlString = XMLHelper.prettyPrintXML(xml);

  Attribute attribute3 = (Attribute) OpenSAMLTestBase.unmarshallFromInputStream(Configuration.getParserPool(),
    new ByteArrayInputStream(xmlString.getBytes("UTF-8")));
  Assert.assertEquals(((CurrentFamilyNameType) attribute.getAttributeValues().get(0)).getValue(), ((CurrentFamilyNameType) attribute3
    .getAttributeValues().get(0)).getValue());
  Assert.assertEquals(((CurrentFamilyNameType) attribute.getAttributeValues().get(1)).getValue(), ((CurrentFamilyNameType) attribute3
    .getAttributeValues().get(1)).getValue());
}
 
开发者ID:litsec,项目名称:eidas-opensaml,代码行数:43,代码来源:CurrentFamilyNameTypeTest.java


示例9: testAttributeCreate

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


示例10: createAttributeValue

import org.opensaml.saml2.core.AttributeValue; //导入依赖的package包/类
private static XSAny createAttributeValue() {
	XSAnyBuilder builder = new XSAnyBuilder();
	XSAny ep = builder.buildObject(SAMLConstants.SAML20_NS,
			AttributeValue.DEFAULT_ELEMENT_LOCAL_NAME,
			SAMLConstants.SAML20_PREFIX);
	return ep;
}
 
开发者ID:amagdenko,项目名称:oiosaml.java,代码行数:8,代码来源:AttributeUtil.java


示例11: extractAttributeValueValues

import org.opensaml.saml2.core.AttributeValue; //导入依赖的package包/类
/**
 * Extract all attribute values within an SAML20 attribute
 * 
 * @param attribute The attribute
 * @return A list containing the text value of each attributeValue
 */
public static List<String> extractAttributeValueValues(Attribute attribute) {
	List<String> values = new ArrayList<String>();
	for (int i = 0; i < attribute.getAttributeValues().size(); i++) {
		if (attribute.getAttributeValues().get(i) instanceof XSString) {
			XSString str = (XSString) attribute.getAttributeValues().get(i);
			if (AttributeValue.DEFAULT_ELEMENT_LOCAL_NAME.equals(str.getElementQName().getLocalPart())
					&& SAMLConstants.SAML20_NS.equals(str.getElementQName().getNamespaceURI())) {
				values.add(str.getValue());
			}
		} else {
			XSAny ep = (XSAny) attribute.getAttributeValues().get(i);
			if (AttributeValue.DEFAULT_ELEMENT_LOCAL_NAME.equals(ep.getElementQName().getLocalPart())
					&& SAMLConstants.SAML20_NS.equals(ep.getElementQName().getNamespaceURI())) {
				if (ep.getUnknownXMLObjects().size() > 0) {
					StringBuilder res = new StringBuilder();
					for (XMLObject obj : ep.getUnknownXMLObjects()) {
						res.append(XMLHelper.nodeToString(SAMLUtil.marshallObject(obj)));
					}
					values.add(res.toString());
				}
				values.add(ep.getTextContent());
			}
		}
	}
	return values;
}
 
开发者ID:amagdenko,项目名称:oiosaml.java,代码行数:33,代码来源:AttributeUtil.java


示例12: createAttribute

import org.opensaml.saml2.core.AttributeValue; //导入依赖的package包/类
private Attribute createAttribute(String name, String value) {
	Attribute attr = SAMLUtil.buildXMLObject(Attribute.class);
	attr.setName(name);
	XSAnyBuilder builder = new XSAnyBuilder();
	XSAny ep = builder.buildObject(SAMLConstants.SAML20_NS,
			AttributeValue.DEFAULT_ELEMENT_LOCAL_NAME,
			SAMLConstants.SAML20_PREFIX);
	ep.setTextContent(value);
	ep.getUnknownAttributes().put(AttributeUtil.XSI_TYPE_ATTRIBUTE_NAME, AttributeUtil.XS_STRING);
	ep.addNamespace(new Namespace(XMLConstants.XSI_NS, XMLConstants.XSI_PREFIX));
	attr.getAttributeValues().add(ep);
	return attr;
}
 
开发者ID:amagdenko,项目名称:oiosaml.java,代码行数:14,代码来源:UserAssertionImplTest.java


示例13: testExtractComplexAttributeValue

import org.opensaml.saml2.core.AttributeValue; //导入依赖的package包/类
@Test
public void testExtractComplexAttributeValue() throws Exception {
	Attribute attr = AttributeUtil.createAttribute("test", "test", OIOSAMLConstants.URI_ATTRIBUTE_NAME_FORMAT);
	XSAnyBuilder builder = new XSAnyBuilder();
	XSAny ep = builder.buildObject(SAMLConstants.SAML20_NS, AttributeValue.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX);

	String xml = "<t:test xmlns:t=\"http://test.org\"><t:more>text here</t:more></t:test>";
	XMLObject val = new XSAnyUnmarshaller().unmarshall(SAMLUtil.loadElementFromString(xml));
	ep.getUnknownXMLObjects().add(val);
	attr.getAttributeValues().add(ep);
	
	assertNotNull(AttributeUtil.extractAttributeValueValue(attr));
	assertTrue(AttributeUtil.extractAttributeValueValue(attr).endsWith(xml));
}
 
开发者ID:amagdenko,项目名称:oiosaml.java,代码行数:15,代码来源:AttributeUtilTest.java


示例14: buildStringAttribute

import org.opensaml.saml2.core.AttributeValue; //导入依赖的package包/类
/**
    * Builds a SAML Attribute of type String
    * 
    * @param name
    * @param value
    * @param builderFactory
    * @return
    * @throws ConfigurationException
    */
   private Attribute buildStringAttribute(String name, String value, XMLObjectBuilderFactory builderFactory) throws ConfigurationException {
SAMLObjectBuilder attrBuilder = (SAMLObjectBuilder) getSAMLBuilder().getBuilder(Attribute.DEFAULT_ELEMENT_NAME);
Attribute attrFirstName = (Attribute) attrBuilder.buildObject();
attrFirstName.setName(name);

// Set custom Attributes
XMLObjectBuilder stringBuilder = getSAMLBuilder().getBuilder(XSString.TYPE_NAME);
XSString attrValueFirstName = (XSString) stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
attrValueFirstName.setValue(value);

attrFirstName.getAttributeValues().add(attrValueFirstName);
return attrFirstName;
   }
 
开发者ID:mwdb,项目名称:OA2C,代码行数:23,代码来源:LocalSamlTokenFactory.java


示例15: buildSAMLAssertion

import org.opensaml.saml2.core.AttributeValue; //导入依赖的package包/类
private Assertion buildSAMLAssertion(final String emailAddress)
{
    // Bootstrap the OpenSAML library
    try {
        DefaultBootstrap.bootstrap();
    } catch (ConfigurationException e) {
    }

    DateTime issueInstant = new DateTime();
    DateTime notOnOrAfter = issueInstant.plusMinutes(15);
    DateTime notBefore    = issueInstant.minusMinutes(5);
    
    NameID nameID = (new NameIDBuilder().buildObject());
    nameID.setFormat(NameIDType.EMAIL);
    nameID.setValue(emailAddress);
    
    SubjectConfirmationData subjectConfirmationData = (new SubjectConfirmationDataBuilder().buildObject());
    subjectConfirmationData.setRecipient(applicationLink.getRpcUrl().toString() + ACCESS_TOKEN_URL);
    subjectConfirmationData.setNotOnOrAfter(notOnOrAfter);
    
    SubjectConfirmation subjectConfirmation = (new SubjectConfirmationBuilder().buildObject());
    subjectConfirmation.setMethod(SubjectConfirmation.METHOD_BEARER);
    subjectConfirmation.setSubjectConfirmationData(subjectConfirmationData);

    Subject subject = (new SubjectBuilder().buildObject());
    subject.setNameID(nameID);
    subject.getSubjectConfirmations().add(subjectConfirmation);
    
    Issuer issuer = (new IssuerBuilder().buildObject());
    issuer.setValue(providerID);
    
    Audience audience = (new AudienceBuilder().buildObject());
    audience.setAudienceURI(AUDIENCE_RESTRICTION);
    
    AudienceRestriction audienceRestriction = (new AudienceRestrictionBuilder().buildObject());
    audienceRestriction.getAudiences().add(audience);
    
    Conditions conditions = (new ConditionsBuilder().buildObject());
    conditions.setNotBefore(notBefore);
    conditions.setNotOnOrAfter(notOnOrAfter);
    conditions.getAudienceRestrictions().add(audienceRestriction);
    
    XSString attributeValue = (XSString)Configuration.getBuilderFactory().getBuilder(XSString.TYPE_NAME).buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
    attributeValue.setValue(clientID);

    Attribute attribute = (new AttributeBuilder().buildObject());
    attribute.setName("client_id");
    attribute.getAttributeValues().add(attributeValue);

    AttributeStatement attributeStatement = (new AttributeStatementBuilder().buildObject());
    attributeStatement.getAttributes().add(attribute);

    Assertion assertion = (new AssertionBuilder().buildObject());
    assertion.setID(UUID.randomUUID().toString());
    assertion.setVersion(SAMLVersion.VERSION_20);
    assertion.setIssueInstant(issueInstant);
    assertion.setIssuer(issuer);
    assertion.setSubject(subject);
    assertion.setConditions(conditions);
    assertion.getAttributeStatements().add(attributeStatement);

    return assertion;
}
 
开发者ID:SAP,项目名称:SAPJamWorkPatternJIRAIntegration,代码行数:64,代码来源:JamConsumer.java


示例16: buildSAML2Assertion

import org.opensaml.saml2.core.AttributeValue; //导入依赖的package包/类
private static Assertion buildSAML2Assertion(boolean includeClientKeyAttribute)
{
    // Bootstrap the OpenSAML library
    try {
        DefaultBootstrap.bootstrap();
    } catch (ConfigurationException e) {
    }

    DateTime issueInstant = new DateTime();
    DateTime notOnOrAfter = issueInstant.plusMinutes(10);
    DateTime notBefore = issueInstant.minusMinutes(10);
    
    NameID nameID = (new NameIDBuilder().buildObject());
    if (SUBJECT_NAME_ID_FORMAT.equals("email")) {
        nameID.setFormat(NameIDType.EMAIL);
    } else if (SUBJECT_NAME_ID_FORMAT.equals("unspecified")) {
        nameID.setFormat(NameIDType.UNSPECIFIED);
    } else {
        throw new IllegalArgumentException("SUBJECT_NAME_ID_FORMAT must be 'email' or 'unspecified'.");
    }
    if (subjectNameIdQualifier != null) {
        nameID.setNameQualifier(subjectNameIdQualifier);
    }
    nameID.setValue(SUBJECT_NAME_ID);
    
    SubjectConfirmationData subjectConfirmationData = (new SubjectConfirmationDataBuilder().buildObject());
    subjectConfirmationData.setRecipient(BASE_URL + ACCESS_TOKEN_URL_PATH);
    subjectConfirmationData.setNotOnOrAfter(notOnOrAfter);
    
    SubjectConfirmation subjectConfirmation = (new SubjectConfirmationBuilder().buildObject());
    subjectConfirmation.setMethod(SubjectConfirmation.METHOD_BEARER);
    subjectConfirmation.setSubjectConfirmationData(subjectConfirmationData);

    Subject subject = (new SubjectBuilder().buildObject());
    subject.setNameID(nameID);
    subject.getSubjectConfirmations().add(subjectConfirmation);
    
    Issuer issuer = (new IssuerBuilder().buildObject());
    issuer.setValue(IDP_ID);
    
    Audience audience = (new AudienceBuilder().buildObject());
    audience.setAudienceURI(SP_ID_JAM);
    
    AudienceRestriction audienceRestriction = (new AudienceRestrictionBuilder().buildObject());
    audienceRestriction.getAudiences().add(audience);
    
    Conditions conditions = (new ConditionsBuilder().buildObject());
    conditions.setNotBefore(notBefore);
    conditions.setNotOnOrAfter(notOnOrAfter);
    conditions.getAudienceRestrictions().add(audienceRestriction);
   
    Assertion assertion = (new AssertionBuilder().buildObject());
    assertion.setID(UUID.randomUUID().toString());
    assertion.setVersion(SAMLVersion.VERSION_20);
    assertion.setIssueInstant(issueInstant);
    assertion.setIssuer(issuer);
    assertion.setSubject(subject);
    assertion.setConditions(conditions);
    
    if (includeClientKeyAttribute) {
        XSString attributeValue = (XSString)Configuration.getBuilderFactory().getBuilder(XSString.TYPE_NAME).buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
        attributeValue.setValue(CLIENT_KEY);

        Attribute attribute = (new AttributeBuilder().buildObject());
        attribute.setName("client_id");
        attribute.getAttributeValues().add(attributeValue);

        AttributeStatement attributeStatement = (new AttributeStatementBuilder().buildObject());
        attributeStatement.getAttributes().add(attribute);
        assertion.getAttributeStatements().add(attributeStatement);
    }

    return assertion;
}
 
开发者ID:SAP,项目名称:SAPJamSampleCode,代码行数:75,代码来源:OAuth2SAMLWorkflowSample.java


示例17: buildSAML2Assertion

import org.opensaml.saml2.core.AttributeValue; //导入依赖的package包/类
private static Assertion buildSAML2Assertion(
        String baseUrl,
        String subjectNameId,
        String subjectNameIdFormat,
        String subjectNameIdQualifier,
        String idpId,
        String clientKey,
        boolean includeClientKeyAttribute)
{
    // Bootstrap the OpenSAML library
    try {
        DefaultBootstrap.bootstrap();
    } catch (ConfigurationException e) {
    }

    DateTime issueInstant = new DateTime();
    DateTime notOnOrAfter = issueInstant.plusMinutes(10);
    DateTime notBefore = issueInstant.minusMinutes(10);
    
    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);
    
    SubjectConfirmationData subjectConfirmationData = (new SubjectConfirmationDataBuilder().buildObject());
    subjectConfirmationData.setRecipient(baseUrl + ACCESS_TOKEN_URL_PATH);
    subjectConfirmationData.setNotOnOrAfter(notOnOrAfter);
    
    SubjectConfirmation subjectConfirmation = (new SubjectConfirmationBuilder().buildObject());
    subjectConfirmation.setMethod(SubjectConfirmation.METHOD_BEARER);
    subjectConfirmation.setSubjectConfirmationData(subjectConfirmationData);

    Subject subject = (new SubjectBuilder().buildObject());
    subject.setNameID(nameID);
    subject.getSubjectConfirmations().add(subjectConfirmation);
    
    Issuer issuer = (new IssuerBuilder().buildObject());
    issuer.setValue(idpId);
    
    Audience audience = (new AudienceBuilder().buildObject());
    audience.setAudienceURI(SP_ID_JAM);
    
    AudienceRestriction audienceRestriction = (new AudienceRestrictionBuilder().buildObject());
    audienceRestriction.getAudiences().add(audience);
    
    Conditions conditions = (new ConditionsBuilder().buildObject());
    conditions.setNotBefore(notBefore);
    conditions.setNotOnOrAfter(notOnOrAfter);
    conditions.getAudienceRestrictions().add(audienceRestriction);
   
    Assertion assertion = (new AssertionBuilder().buildObject());
    assertion.setID(UUID.randomUUID().toString());
    assertion.setVersion(SAMLVersion.VERSION_20);
    assertion.setIssueInstant(issueInstant);
    assertion.setIssuer(issuer);
    assertion.setSubject(subject);
    assertion.setConditions(conditions);
    
    if (includeClientKeyAttribute) {
        XSString attributeValue = (XSString)Configuration.getBuilderFactory().getBuilder(XSString.TYPE_NAME).buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
        attributeValue.setValue(clientKey);

        Attribute attribute = (new AttributeBuilder().buildObject());
        attribute.setName("client_id");
        attribute.getAttributeValues().add(attributeValue);

        AttributeStatement attributeStatement = (new AttributeStatementBuilder().buildObject());
        attributeStatement.getAttributes().add(attribute);
        assertion.getAttributeStatements().add(attributeStatement);
    }

    return assertion;
}
 
开发者ID:SAP,项目名称:SAPJamSampleCode,代码行数:82,代码来源:OAuth2SAMLWorkflowSample.java


示例18: createStatement

import org.opensaml.saml2.core.AttributeValue; //导入依赖的package包/类
@Override
public void createStatement(GenericIdentityProviderData ipData, RahasData rahasData)
        throws IdentityProviderException {
    if (log.isDebugEnabled()) {
        log.debug("Begin SAML statement creation.");
    }
    attributeStmt = (AttributeStatement) buildXMLObject(AttributeStatement.DEFAULT_ELEMENT_NAME);

    Map<String, RequestedClaimData> mapClaims = ipData.getRequestedClaims();

    if (rahasData.getAppliesToAddress() != null) {
        appilesTo = rahasData.getAppliesToAddress();
    }

    Iterator<RequestedClaimData> ite = mapClaims.values().iterator();

    while (ite.hasNext()) {
        RequestedClaimData claim = ite.next();
        String uri = claim.getUri();

        int index = uri.lastIndexOf("/");
        String attrName = uri.substring(index + 1, uri.length());
        String attrNamespace = uri.substring(0, index);

        Attribute attribute = (Attribute) buildXMLObject(Attribute.DEFAULT_ELEMENT_NAME);
        attribute.setName(attrName);
        attribute.setNameFormat(attrNamespace);

        XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();

        // TODO remove this else if condition after WSO2 IS supports claim
        // types properly
        if (claim.getUri().equals(IdentityConstants.CLAIM_PPID)) {
            XSBase64BinaryBuilder ppidValueBuilder = (XSBase64BinaryBuilder) builderFactory
                    .getBuilder(XSBase64Binary.TYPE_NAME);
            XSBase64Binary ppidValue = ppidValueBuilder.buildObject(
                    AttributeValue.DEFAULT_ELEMENT_NAME, XSBase64Binary.TYPE_NAME);
            ppidValue.setValue(claim.getValue());
            attribute.getAttributeValues().add(ppidValue);
        } else {
            XSStringBuilder attributeValueBuilder = (XSStringBuilder) builderFactory
                    .getBuilder(XSString.TYPE_NAME);

            XSString stringValue = attributeValueBuilder.buildObject(
                    AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
            stringValue.setValue(claim.getValue());
            attribute.getAttributeValues().add(stringValue);
        }
        attributeStmt.getAttributes().add(attribute);
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:52,代码来源:SAML2TokenBuilder.java


示例19: buildAttributeStatement

import org.opensaml.saml2.core.AttributeValue; //导入依赖的package包/类
private AttributeStatement buildAttributeStatement(Map<String, String> claims) {

        String claimSeparator = claims.get(IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR);
        if (StringUtils.isNotBlank(claimSeparator)) {
            userAttributeSeparator = claimSeparator;
        }
        claims.remove(IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR);

        AttributeStatement attStmt = new AttributeStatementBuilder().buildObject();
        Iterator<Map.Entry<String, String>> iterator = claims.entrySet().iterator();
        boolean atLeastOneNotEmpty = false;
        for (int i = 0; i < claims.size(); i++) {
            Map.Entry<String, String> claimEntry = iterator.next();
            String claimUri = claimEntry.getKey();
            String claimValue = claimEntry.getValue();
            if (claimUri != null && !claimUri.trim().isEmpty() && claimValue != null && !claimValue.trim().isEmpty()) {
                atLeastOneNotEmpty = true;
                Attribute attribute = new AttributeBuilder().buildObject();
                attribute.setName(claimUri);
                //setting NAMEFORMAT attribute value to basic attribute profile
                attribute.setNameFormat(SAMLSSOConstants.NAME_FORMAT_BASIC);
                // look
                // https://wiki.shibboleth.net/confluence/display/OpenSAML/OSTwoUsrManJavaAnyTypes
                XSStringBuilder stringBuilder = (XSStringBuilder) Configuration.getBuilderFactory().
                        getBuilder(XSString.TYPE_NAME);
                XSString stringValue;

                //Need to check if the claim has multiple values
                if (userAttributeSeparator != null && claimValue.contains(userAttributeSeparator)) {
                    StringTokenizer st = new StringTokenizer(claimValue, userAttributeSeparator);
                    while (st.hasMoreElements()) {
                        String attValue = st.nextElement().toString();
                        if (attValue != null && attValue.trim().length() > 0) {
                            stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
                            stringValue.setValue(attValue);
                            attribute.getAttributeValues().add(stringValue);
                        }
                    }
                } else {
                    stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
                    stringValue.setValue(claimValue);
                    attribute.getAttributeValues().add(stringValue);
                }

                attStmt.getAttributes().add(attribute);
            }
        }
        if (atLeastOneNotEmpty) {
            return attStmt;
        } else {
            return null;
        }
    }
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:54,代码来源:DefaultSAMLAssertionBuilder.java


示例20: createAttributeValueObject

import org.opensaml.saml2.core.AttributeValue; //导入依赖的package包/类
/**
 * Creates an {@code AttributeValue} object of the given class and schema type.
 * <p>
 * After the object has been constructed, its setter methods should be called to setup the value object before adding
 * it to the attribute itself.
 * </p>
 * 
 * @param <T>
 *          the type
 * @param schemaType
 *          the schema type that should be assigned to the attribute value, i.e.,
 *          {@code xsi:type="eidas:CurrentFamilyNameType"}
 * @param clazz
 *          the type of the attribute value
 * @return the attribute value
 * @see #createAttributeValueObject(Class)
 */
public static <T extends XMLObject> T createAttributeValueObject(QName schemaType, Class<T> clazz) {
  XMLObjectBuilder<?> builder = Configuration.getBuilderFactory().getBuilder(schemaType);
  XMLObject object = builder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, schemaType);
  return clazz.cast(object);
}
 
开发者ID:litsec,项目名称:eidas-opensaml,代码行数:23,代码来源:AttributeUtils.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CDebugger类代码示例发布时间:2022-05-22
下一篇:
Java AccessPermission类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap