use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class XACMLPrivilegeUtils method policyToPrivilege.
public static Privilege policyToPrivilege(Policy policy) throws EntitlementException {
String policyId = policy.getPolicyId();
String privilegeName = policyIdToPrivilegeName(policyId);
String description = policy.getDescription();
String createdBy = getVariableById(policy, XACMLConstants.PRIVILEGE_CREATED_BY);
long createdAt = dateStringToLong(getVariableById(policy, XACMLConstants.PRIVILEGE_CREATION_DATE));
String lastModifiedBy = getVariableById(policy, XACMLConstants.PRIVILEGE_LAST_MODIFIED_BY);
long lastModifiedAt = dateStringToLong(getVariableById(policy, XACMLConstants.PRIVILEGE_LAST_MODIFIED_DATE));
String entitlementName = getVariableById(policy, XACMLConstants.ENTITLEMENT_NAME);
String applicationName = getVariableById(policy, XACMLConstants.APPLICATION_NAME);
List<Match> policyMatches = getAllMatchesFromTarget(policy.getTarget());
Set<String> resourceNames = getResourceNamesFromMatches(policyMatches);
Map<String, Boolean> actionValues = getActionValuesFromPolicy(policy);
EntitlementSubject es = getEntitlementSubjectFromPolicy(policy);
EntitlementCondition ec = getEntitlementConditionFromPolicy(policy);
/*
* Construct entitlement from Rule target
* Get resource names, excluded resource names, action names from Rule Match element
* One Match for Action
* One Rule per value
*/
Entitlement entitlement = new Entitlement(applicationName, resourceNames, actionValues);
if (entitlementName != null) {
entitlement.setName(entitlementName);
}
// Process AdviceExpressions from Export into ResourceAttributes
Set<ResourceAttribute> ras = schemaFactory.adviceExpressionsToResourceAttributes(policy.getAdviceExpressions());
Privilege privilege = new XACMLOpenSSOPrivilege();
privilege.setName(privilegeName);
privilege.setDescription(description);
privilege.setCreatedBy(createdBy);
privilege.setCreationDate(createdAt);
privilege.setLastModifiedBy(lastModifiedBy);
privilege.setLastModifiedDate(lastModifiedAt);
privilege.setEntitlement(entitlement);
privilege.setSubject(es);
privilege.setCondition(ec);
privilege.setResourceAttributes(ras);
return privilege;
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class FactoryMethods method getArbitraryPrivilegeAsPolicy.
public static Policy getArbitraryPrivilegeAsPolicy(long now) throws EntitlementException {
Set<Privilege> privileges = createArbitraryPrivilegeSet(now);
PolicySet policySet = XACMLPrivilegeUtils.privilegesToPolicySet("/", privileges);
return (Policy) policySet.getPolicySetOrPolicyOrPolicySetIdReference().get(0).getValue();
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class PolicyResource method updateInstance.
/**
* {@inheritDoc}
*/
@Override
public Promise<ResourceResponse, ResourceException> updateInstance(Context context, String resourceId, UpdateRequest request) {
try {
Privilege policy = policyParser.parsePolicy(resourceId, request.getContent());
ResourceResponse result = policyResource(policyStoreProvider.getPolicyStore(context).update(resourceId, policy));
return newResultPromise(result);
} catch (EntitlementException ex) {
DEBUG.error("PolicyResource :: UPDATE : Error updating policy, " + resourceId + ".", ex);
return resourceErrorHandler.handleError(context, request, ex).asPromise();
}
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class XACMLPrivilegeUtilsTest method shouldReturnNullWhenGivenNullAsPrivilegeSet.
@Test
public void shouldReturnNullWhenGivenNullAsPrivilegeSet() {
//Given
Set<Privilege> privileges = null;
//When
PolicySet policySet = XACMLPrivilegeUtils.privilegesToPolicySet("/", privileges);
//Then
assertNull(policySet, "Expected PolicySet to be null.");
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class XACMLPrivilegeUtilsTest method shouldResultInEquivalentPrivilegesWhenValidPrivilegeSetSerializedToXACMLThenDeserialized.
@Test
public void shouldResultInEquivalentPrivilegesWhenValidPrivilegeSetSerializedToXACMLThenDeserialized() throws EntitlementException {
//Given
Set<Privilege> privileges = createArbitraryPrivilegeSet(now);
PolicySet policySet = XACMLPrivilegeUtils.privilegesToPolicySet("/", privileges);
List<Policy> policies = getPoliciesFromPolicySet(policySet);
List<Privilege> deserializedPrivileges = new ArrayList<Privilege>();
for (Policy policy : policies) {
//When
deserializedPrivileges.add(XACMLPrivilegeUtils.policyToPrivilege(policy));
}
//Then
assertAllPrivilegesEquivalent(deserializedPrivileges, privileges);
}
Aggregations