Search in sources :

Example 1 with XSInteger

use of org.opensaml.core.xml.schema.XSInteger in project spring-security by spring-projects.

the class TestOpenSamlObjects method attributeStatements.

static List<AttributeStatement> attributeStatements() {
    List<AttributeStatement> attributeStatements = new ArrayList<>();
    AttributeStatementBuilder attributeStatementBuilder = new AttributeStatementBuilder();
    AttributeBuilder attributeBuilder = new AttributeBuilder();
    AttributeStatement attrStmt1 = attributeStatementBuilder.buildObject();
    Attribute emailAttr = attributeBuilder.buildObject();
    emailAttr.setName("email");
    // gh-8864
    XSAny email1 = new XSAnyBuilder().buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSAny.TYPE_NAME);
    email1.setTextContent("john.doe@example.com");
    emailAttr.getAttributeValues().add(email1);
    XSAny email2 = new XSAnyBuilder().buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
    email2.setTextContent("doe.john@example.com");
    emailAttr.getAttributeValues().add(email2);
    attrStmt1.getAttributes().add(emailAttr);
    Attribute nameAttr = attributeBuilder.buildObject();
    nameAttr.setName("name");
    XSString name = new XSStringBuilder().buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
    name.setValue("John Doe");
    nameAttr.getAttributeValues().add(name);
    attrStmt1.getAttributes().add(nameAttr);
    Attribute ageAttr = attributeBuilder.buildObject();
    ageAttr.setName("age");
    XSInteger age = new XSIntegerBuilder().buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSInteger.TYPE_NAME);
    age.setValue(21);
    ageAttr.getAttributeValues().add(age);
    attrStmt1.getAttributes().add(ageAttr);
    attributeStatements.add(attrStmt1);
    AttributeStatement attrStmt2 = attributeStatementBuilder.buildObject();
    Attribute websiteAttr = attributeBuilder.buildObject();
    websiteAttr.setName("website");
    XSURI uri = new XSURIBuilder().buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSURI.TYPE_NAME);
    uri.setValue("https://johndoe.com/");
    websiteAttr.getAttributeValues().add(uri);
    attrStmt2.getAttributes().add(websiteAttr);
    Attribute registeredAttr = attributeBuilder.buildObject();
    registeredAttr.setName("registered");
    XSBoolean registered = new XSBooleanBuilder().buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSBoolean.TYPE_NAME);
    registered.setValue(new XSBooleanValue(true, false));
    registeredAttr.getAttributeValues().add(registered);
    attrStmt2.getAttributes().add(registeredAttr);
    attributeStatements.add(attrStmt2);
    return attributeStatements;
}
Also used : AttributeStatementBuilder(org.opensaml.saml.saml2.core.impl.AttributeStatementBuilder) AttributeBuilder(org.opensaml.saml.saml2.core.impl.AttributeBuilder) XSIntegerBuilder(org.opensaml.core.xml.schema.impl.XSIntegerBuilder) XSBooleanBuilder(org.opensaml.core.xml.schema.impl.XSBooleanBuilder) XSAnyBuilder(org.opensaml.core.xml.schema.impl.XSAnyBuilder) Attribute(org.opensaml.saml.saml2.core.Attribute) EncryptedAttribute(org.opensaml.saml.saml2.core.EncryptedAttribute) ArrayList(java.util.ArrayList) XSString(org.opensaml.core.xml.schema.XSString) XSStringBuilder(org.opensaml.core.xml.schema.impl.XSStringBuilder) XSURI(org.opensaml.core.xml.schema.XSURI) XSAny(org.opensaml.core.xml.schema.XSAny) XSBooleanValue(org.opensaml.core.xml.schema.XSBooleanValue) AttributeStatement(org.opensaml.saml.saml2.core.AttributeStatement) XSInteger(org.opensaml.core.xml.schema.XSInteger) XSBoolean(org.opensaml.core.xml.schema.XSBoolean) XSURIBuilder(org.opensaml.core.xml.schema.impl.XSURIBuilder)

Example 2 with XSInteger

use of org.opensaml.core.xml.schema.XSInteger in project cxf by apache.

the class CustomClaimsHandler method retrieveClaimValues.

public ProcessedClaimCollection retrieveClaimValues(ClaimCollection claims, ClaimsParameters parameters) {
    if (claims != null && !claims.isEmpty()) {
        ProcessedClaimCollection claimCollection = new ProcessedClaimCollection();
        for (Claim requestClaim : claims) {
            ProcessedClaim claim = new ProcessedClaim();
            claim.setClaimType(requestClaim.getClaimType());
            if (ClaimTypes.FIRSTNAME.toString().equals(requestClaim.getClaimType())) {
                if (requestClaim instanceof CustomRequestClaim) {
                    CustomRequestClaim customClaim = (CustomRequestClaim) requestClaim;
                    String customName = customClaim.getValues().get(0) + "@" + customClaim.getScope();
                    claim.addValue(customName);
                } else {
                    claim.addValue("alice");
                }
            } else if (ClaimTypes.LASTNAME.toString().equals(requestClaim.getClaimType())) {
                claim.addValue("doe");
            } else if (ClaimTypes.EMAILADDRESS.toString().equals(requestClaim.getClaimType())) {
                claim.addValue("alice@cxf.apache.org");
            } else if (ClaimTypes.STREETADDRESS.toString().equals(requestClaim.getClaimType())) {
                claim.addValue("1234 1st Street");
            } else if (ClaimTypes.MOBILEPHONE.toString().equals(requestClaim.getClaimType())) {
                // Test custom (Integer) attribute value
                XMLObjectBuilderFactory builderFactory = XMLObjectProviderRegistrySupport.getBuilderFactory();
                @SuppressWarnings("unchecked") XMLObjectBuilder<XSInteger> xsIntegerBuilder = (XMLObjectBuilder<XSInteger>) builderFactory.getBuilder(XSInteger.TYPE_NAME);
                XSInteger attributeValue = xsIntegerBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSInteger.TYPE_NAME);
                attributeValue.setValue(185912592);
                claim.addValue(attributeValue);
            } else if (ROLE_CLAIM.equals(requestClaim.getClaimType())) {
                if (requestClaim.getValues().size() > 0) {
                    for (Object requestedRole : requestClaim.getValues()) {
                        if (isUserInRole(parameters.getPrincipal(), requestedRole.toString())) {
                            claim.addValue(requestedRole);
                        }
                    }
                    if (claim.getValues().isEmpty()) {
                        continue;
                    }
                } else {
                    // If no specific role was requested return DUMMY role for user
                    claim.addValue(role);
                }
            }
            claimCollection.add(claim);
        }
        return claimCollection;
    }
    return null;
}
Also used : ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) XSInteger(org.opensaml.core.xml.schema.XSInteger) XMLObjectBuilder(org.opensaml.core.xml.XMLObjectBuilder) XMLObjectBuilderFactory(org.opensaml.core.xml.XMLObjectBuilderFactory) CustomRequestClaim(org.apache.cxf.sts.common.CustomClaimParser.CustomRequestClaim) CustomRequestClaim(org.apache.cxf.sts.common.CustomClaimParser.CustomRequestClaim) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) Claim(org.apache.cxf.rt.security.claims.Claim)

Aggregations

XSInteger (org.opensaml.core.xml.schema.XSInteger)2 ArrayList (java.util.ArrayList)1 Claim (org.apache.cxf.rt.security.claims.Claim)1 ProcessedClaim (org.apache.cxf.sts.claims.ProcessedClaim)1 ProcessedClaimCollection (org.apache.cxf.sts.claims.ProcessedClaimCollection)1 CustomRequestClaim (org.apache.cxf.sts.common.CustomClaimParser.CustomRequestClaim)1 XMLObjectBuilder (org.opensaml.core.xml.XMLObjectBuilder)1 XMLObjectBuilderFactory (org.opensaml.core.xml.XMLObjectBuilderFactory)1 XSAny (org.opensaml.core.xml.schema.XSAny)1 XSBoolean (org.opensaml.core.xml.schema.XSBoolean)1 XSBooleanValue (org.opensaml.core.xml.schema.XSBooleanValue)1 XSString (org.opensaml.core.xml.schema.XSString)1 XSURI (org.opensaml.core.xml.schema.XSURI)1 XSAnyBuilder (org.opensaml.core.xml.schema.impl.XSAnyBuilder)1 XSBooleanBuilder (org.opensaml.core.xml.schema.impl.XSBooleanBuilder)1 XSIntegerBuilder (org.opensaml.core.xml.schema.impl.XSIntegerBuilder)1 XSStringBuilder (org.opensaml.core.xml.schema.impl.XSStringBuilder)1 XSURIBuilder (org.opensaml.core.xml.schema.impl.XSURIBuilder)1 Attribute (org.opensaml.saml.saml2.core.Attribute)1 AttributeStatement (org.opensaml.saml.saml2.core.AttributeStatement)1