use of com.sun.identity.entitlement.ResourceAttribute in project OpenAM by OpenRock.
the class XACMLSchemaFactoryTest method checkEqualAttributeValues.
/**
* Compare two AttributeValue objects, returning true if they contain equal values, false otherwise.
* @param first The first attribute value.
* @param second The second attribute value.
* @return true if the objects contain the same values, false otherwise.
*/
private boolean checkEqualAttributeValues(AttributeValue first, AttributeValue second) {
if (first == null && second == null) {
return true;
}
if (first == null || second == null) {
return false;
}
List<Object> firstList = first.getContent();
List<Object> secondList = second.getContent();
if (firstList == null && secondList == null) {
return true;
}
if (firstList == null || secondList == null) {
return false;
}
if (firstList.size() != secondList.size()) {
return false;
}
for (Object firstObject : firstList) {
boolean found = false;
for (Object secondObject : secondList) {
if (firstObject instanceof String && secondObject instanceof String) {
String firstString = (String) firstObject;
String secondString = (String) secondObject;
try {
ResourceAttribute firstRA = resourceAttributeUtil.fromJSON(firstString);
ResourceAttribute secondRA = resourceAttributeUtil.fromJSON(secondString);
found = checkEqualResourceAttributes(firstRA, secondRA);
if (found) {
break;
}
} catch (EntitlementException ignored) {
}
}
}
if (!found) {
return false;
}
}
return true;
}
use of com.sun.identity.entitlement.ResourceAttribute in project OpenAM by OpenRock.
the class XACMLSchemaFactoryTest method shouldConvertResourceAttributesToAndFrom.
@Test
public void shouldConvertResourceAttributesToAndFrom() throws EntitlementException {
for (ResourceAttribute ra : rpSet) {
// When...
AdviceExpression ae = xacmlSchemaFactory.resourceAttributeToAdviceExpression(ra);
ResourceAttribute transformed = xacmlSchemaFactory.adviceExpressionToResourceAttribute(ae);
// Then...
assertEqualResourceAttributeValues(ra, transformed);
}
}
use of com.sun.identity.entitlement.ResourceAttribute in project OpenAM by OpenRock.
the class ResourceAttributeUtilTest method shouldDeserialiseMockResourceAttribute.
@Test
public void shouldDeserialiseMockResourceAttribute() throws EntitlementException {
// Given
util = new ResourceAttributeUtil();
ResourceAttribute attribute = new MockResourceAttribute();
// When
ResourceAttribute result = util.fromJSON(util.toJSON(attribute));
// Then
assertThat(result.getPropertyName()).isEqualTo(attribute.getPropertyName());
}
use of com.sun.identity.entitlement.ResourceAttribute in project OpenAM by OpenRock.
the class XACMLSchemaFactoryTest method shouldConvertAdviceExpressionToAndFrom.
@Test
public void shouldConvertAdviceExpressionToAndFrom() throws EntitlementException {
for (AdviceExpression ae : aes.getAdviceExpression()) {
// When...
ResourceAttribute ra = xacmlSchemaFactory.adviceExpressionToResourceAttribute(ae);
AdviceExpression transformed = xacmlSchemaFactory.resourceAttributeToAdviceExpression(ra);
// Then...
assertEqualAdviceExpressionValues(ae, transformed);
}
}
use of com.sun.identity.entitlement.ResourceAttribute in project OpenAM by OpenRock.
the class PrivilegeUtils method policyToPrivileges.
public static void policyToPrivileges(Policy policy, Set<IPrivilege> privileges) throws SSOException, PolicyException, EntitlementException {
String policyName = policy.getName();
if (policy.isReferralPolicy()) {
Map<String, Set<String>> resources = getResources(policy);
Set<String> referredRealms = getReferrals(policy);
ReferralPrivilege rp = new ReferralPrivilege(policyName, resources, referredRealms);
rp.setDescription(policy.getDescription());
rp.setCreationDate(policy.getCreationDate());
rp.setCreatedBy(policy.getCreatedBy());
rp.setLastModifiedBy(policy.getLastModifiedBy());
rp.setLastModifiedDate(policy.getLastModifiedDate());
rp.setActive(policy.isActive());
privileges.add(rp);
} else {
Set<Entitlement> entitlements = rulesToEntitlement(policy);
EntitlementSubject eSubject = toEntitlementSubject(policy);
EntitlementCondition eCondition = toEntitlementCondition(policy);
Set<ResourceAttribute> resourceAttributesSet = toResourceAttributes(policy);
if (entitlements.size() == 1) {
privileges.add(createPrivilege(policyName, policyName, entitlements.iterator().next(), eSubject, eCondition, resourceAttributesSet, policy));
} else {
for (Entitlement e : entitlements) {
String pName = policyName + "_" + e.getName();
privileges.add(createPrivilege(pName, policyName, e, eSubject, eCondition, resourceAttributesSet, policy));
}
}
}
}
Aggregations