Search in sources :

Example 6 with AttributeValue

use of org.opensaml.saml.saml2.core.AttributeValue in project OpenAM by OpenRock.

the class XACMLSchemaFactoryTest method createAdviceExpression.

/**
     * Create an advice expression using the values in the specified resource attribute
     * @param ra the specified resource attribute
     * @return an advice expression
     * @throws EntitlementException if there are JSON errors
     */
private AdviceExpression createAdviceExpression(final ResourceAttribute ra) throws EntitlementException {
    AdviceExpression result = new AdviceExpression();
    AttributeValue attributeValue = new AttributeValue();
    attributeValue.setDataType(XACMLConstants.XS_STRING);
    // We bypass much of the grief of conversion by getting JSON to do the heavy lifting for us.
    attributeValue.getContent().add(resourceAttributeUtil.toJSON(ra));
    JAXBElement<AttributeValue> jaxbElement = new JAXBElement<AttributeValue>(QName.valueOf(AttributeValue.class.getSimpleName()), AttributeValue.class, null, attributeValue);
    AttributeAssignmentExpression attributeAssignmentExpression = new AttributeAssignmentExpression();
    attributeAssignmentExpression.setExpression(jaxbElement);
    attributeAssignmentExpression.setAttributeId(XACMLConstants.JSON_RESOURCE_ATTRIBUTE_ADVICE_ID + ":" + ra.getClass().getName() + ":" + ra.getPropertyName());
    result.getAttributeAssignmentExpression().add(attributeAssignmentExpression);
    result.setAppliesTo(EffectType.PERMIT);
    result.setAdviceId(XACMLConstants.JSON_RESOURCE_ATTRIBUTE_ADVICE_ID + ":" + ra.getClass().getName());
    return result;
}
Also used : AdviceExpression(com.sun.identity.entitlement.xacml3.core.AdviceExpression) AttributeValue(com.sun.identity.entitlement.xacml3.core.AttributeValue) AttributeAssignmentExpression(com.sun.identity.entitlement.xacml3.core.AttributeAssignmentExpression) JAXBElement(javax.xml.bind.JAXBElement)

Example 7 with AttributeValue

use of org.opensaml.saml.saml2.core.AttributeValue in project OpenAM by OpenRock.

the class XACMLPrivilegeUtils method resourceNameToMatch.

public static Match resourceNameToMatch(String resourceName, String applicationName) {
    if (resourceName == null || resourceName.length() == 0) {
        return null;
    }
    Match match = new Match();
    String matchId = XACMLConstants.ENTITLEMENT_RESOURCE_MATCH + ":" + applicationName;
    match.setMatchId(matchId);
    AttributeValue attributeValue = new AttributeValue();
    String dataType = XACMLConstants.XS_STRING;
    attributeValue.setDataType(dataType);
    attributeValue.getContent().add(resourceName);
    AttributeDesignator attributeDesignator = new AttributeDesignator();
    String category = XACMLConstants.XACML_RESOURCE_CATEGORY;
    attributeDesignator.setCategory(category);
    String attributeId = XACMLConstants.XACML_RESOURCE_ID;
    attributeDesignator.setAttributeId(attributeId);
    String dt = XACMLConstants.XS_STRING;
    attributeDesignator.setDataType(dt);
    // TOOD: not a constant?
    String issuer = XACMLConstants.RESOURCE_ISSUER;
    // attributeDesignator.setIssuer(issuer); TODO: verify and fix
    boolean mustBePresent = true;
    attributeDesignator.setMustBePresent(mustBePresent);
    match.setAttributeValue(attributeValue);
    match.setAttributeDesignator(attributeDesignator);
    return match;
}
Also used : AttributeValue(com.sun.identity.entitlement.xacml3.core.AttributeValue) AttributeDesignator(com.sun.identity.entitlement.xacml3.core.AttributeDesignator) Match(com.sun.identity.entitlement.xacml3.core.Match)

Example 8 with AttributeValue

use of org.opensaml.saml.saml2.core.AttributeValue in project OpenAM by OpenRock.

the class XACMLPrivilegeUtils method getRealmsAppsResources.

static JSONObject getRealmsAppsResources(List<Match> matches) throws JSONException {
    if (matches == null) {
        return null;
    }
    JSONObject jo = null;
    String jsonString = null;
    for (Match match : matches) {
        String matchId = match.getMatchId();
        if ((matchId != null) && matchId.equals(XACMLConstants.JSON_REALMS_APPS_RESOURCES_MATCH)) {
            AttributeValue attributeValue = match.getAttributeValue();
            if (attributeValue != null) {
                List<Object> contentList = attributeValue.getContent();
                if ((contentList != null) && !contentList.isEmpty()) {
                    Object obj = contentList.get(0);
                    jsonString = obj.toString();
                    break;
                }
            }
        }
    }
    if (jsonString != null) {
        jo = new JSONObject(jsonString);
    }
    return jo;
}
Also used : AttributeValue(com.sun.identity.entitlement.xacml3.core.AttributeValue) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) Match(com.sun.identity.entitlement.xacml3.core.Match)

Example 9 with AttributeValue

use of org.opensaml.saml.saml2.core.AttributeValue in project OpenAM by OpenRock.

the class XACMLSchemaFactory method adviceExpressionToResourceAttribute.

/**
     * Convert the specified {@link com.sun.identity.entitlement.xacml3.core.AdviceExpression} object into a
     * {@link com.sun.identity.entitlement.ResourceAttribute}.
     *
     * @param adviceExpression The specified advice expression
     * @return The resource attribute
     * @throws com.sun.identity.entitlement.EntitlementException if JSON exceptions occur
     */
public ResourceAttribute adviceExpressionToResourceAttribute(AdviceExpression adviceExpression) throws EntitlementException {
    for (AttributeAssignmentExpression attributeAssignmentExpression : adviceExpression.getAttributeAssignmentExpression()) {
        JAXBElement<?> jaxbElement = attributeAssignmentExpression.getExpression();
        Object value = jaxbElement.getValue();
        if (value instanceof AttributeValue) {
            AttributeValue attributeValue = (AttributeValue) value;
            for (Object content : attributeValue.getContent()) {
                if (content instanceof String) {
                    return resourceAttributeUtil.fromJSON((String) content);
                }
            }
        }
    }
    return null;
}
Also used : AttributeValue(com.sun.identity.entitlement.xacml3.core.AttributeValue) AttributeAssignmentExpression(com.sun.identity.entitlement.xacml3.core.AttributeAssignmentExpression)

Example 10 with AttributeValue

use of org.opensaml.saml.saml2.core.AttributeValue in project verify-hub by alphagov.

the class VerifiedAttributesLoggerTest method shouldLogMiddleNamesNameHistory.

@Test
public void shouldLogMiddleNamesNameHistory() throws Exception {
    AttributeValue oldMiddleNamesAttributeValue = new PersonNameAttributeValueBuilder().withFrom(DateTime.parse("2000-12-31")).withTo(DateTime.now().minusDays(406)).withVerified(true).build();
    AttributeValue currentMiddleNamesAttributeValue = new PersonNameAttributeValueBuilder().withFrom(DateTime.now().minusDays(405)).withVerified(true).build();
    Attribute middleNamesAttribute = new AttributeBuilder().buildObject();
    middleNamesAttribute.setName(IdaConstants.Attributes_1_1.Middlename.NAME);
    middleNamesAttribute.getAttributeValues().add(oldMiddleNamesAttributeValue);
    middleNamesAttribute.getAttributeValues().add(currentMiddleNamesAttributeValue);
    List<Attribute> attributes = aMatchingDatasetAttributeStatement_1_1().withMiddleNames(middleNamesAttribute).build().getAttributes();
    AttributeStatementLogData actual = mapper.readValue(formatAttributes("any-issuer", LEVEL_2, attributes), AttributeStatementLogData.class);
    Map<String, List<VerifiedAttributeLogData>> attributesMap = actual.getAttributes();
    assertThat(attributesMap.get(IdaConstants.Attributes_1_1.Middlename.NAME)).isEqualTo(ImmutableList.of(new VerifiedAttributeLogData(true, "more than 405 days"), new VerifiedAttributeLogData(true, null)));
}
Also used : AttributeValue(org.opensaml.saml.saml2.core.AttributeValue) AttributeBuilder(org.opensaml.saml.saml2.core.impl.AttributeBuilder) Attribute(org.opensaml.saml.saml2.core.Attribute) AttributeStatementLogData(uk.gov.ida.hub.samlengine.logging.data.AttributeStatementLogData) PersonNameAttributeValueBuilder(uk.gov.ida.saml.core.test.builders.PersonNameAttributeValueBuilder) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) VerifiedAttributeLogData(uk.gov.ida.hub.samlengine.logging.data.VerifiedAttributeLogData) Test(org.junit.Test)

Aggregations

AttributeValue (com.sun.identity.entitlement.xacml3.core.AttributeValue)20 Match (com.sun.identity.entitlement.xacml3.core.Match)10 JSONObject (org.json.JSONObject)9 AttributeDesignator (com.sun.identity.entitlement.xacml3.core.AttributeDesignator)7 List (java.util.List)7 Attribute (org.opensaml.saml.saml2.core.Attribute)7 ImmutableList (com.google.common.collect.ImmutableList)6 Test (org.junit.Test)6 AttributeValue (org.opensaml.saml.saml2.core.AttributeValue)6 AttributeBuilder (org.opensaml.saml.saml2.core.impl.AttributeBuilder)6 AttributeStatementLogData (uk.gov.ida.hub.samlengine.logging.data.AttributeStatementLogData)6 VerifiedAttributeLogData (uk.gov.ida.hub.samlengine.logging.data.VerifiedAttributeLogData)6 AnyOf (com.sun.identity.entitlement.xacml3.core.AnyOf)5 JAXBElement (javax.xml.bind.JAXBElement)5 EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)4 Condition (com.sun.identity.entitlement.xacml3.core.Condition)4 Rule (com.sun.identity.entitlement.xacml3.core.Rule)4 HashSet (java.util.HashSet)4 AllOf (com.sun.identity.entitlement.xacml3.core.AllOf)3 Apply (com.sun.identity.entitlement.xacml3.core.Apply)3