use of com.sun.identity.entitlement.EntitlementCondition in project OpenAM by OpenRock.
the class EntitlementRegistryTest method shouldNotReturnSuperTypeConditionNames.
@Test
public void shouldNotReturnSuperTypeConditionNames() {
// Given
EntitlementCondition testCondition = new NumericAttributeCondition();
// Only super-type registered
testRegistry.registerConditionType(EntitlementCondition.class);
// When
String result = testRegistry.getConditionName(testCondition);
// Then
assertThat(result).isNull();
}
use of com.sun.identity.entitlement.EntitlementCondition in project OpenAM by OpenRock.
the class PrivilegeUtils method mapGenericCondition.
private static EntitlementCondition mapGenericCondition(Object[] nCondition) throws EntitlementException {
try {
Object objCondition = nCondition[1];
if (objCondition instanceof com.sun.identity.policy.plugins.PrivilegeCondition) {
com.sun.identity.policy.plugins.PrivilegeCondition pipc = (com.sun.identity.policy.plugins.PrivilegeCondition) objCondition;
Map<String, Set<String>> props = pipc.getProperties();
String className = props.keySet().iterator().next();
EntitlementCondition ec = (EntitlementCondition) Class.forName(className).newInstance();
Set<String> setValues = props.get(className);
ec.setState(setValues.iterator().next());
ec.validate();
return ec;
} else if (objCondition instanceof Condition) {
Condition cond = (Condition) objCondition;
Map<String, Set<String>> props = cond.getProperties();
String className = cond.getClass().getName();
return new PolicyCondition((String) nCondition[0], className, props);
}
} catch (ClassNotFoundException e) {
PolicyConstants.DEBUG.error("PrivilegeUtils.mapGenericCondition", e);
} catch (InstantiationException e) {
PolicyConstants.DEBUG.error("PrivilegeUtils.mapGenericCondition", e);
} catch (IllegalAccessException e) {
PolicyConstants.DEBUG.error("PrivilegeUtils.mapGenericCondition", e);
}
return null;
}
use of com.sun.identity.entitlement.EntitlementCondition 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));
}
}
}
}
use of com.sun.identity.entitlement.EntitlementCondition in project OpenAM by OpenRock.
the class PrivilegeUtils method toEntitlementCondition.
private static EntitlementCondition toEntitlementCondition(Policy policy) throws PolicyException, EntitlementException {
Set conditionNames = policy.getConditionNames();
Set nConditions = new HashSet();
for (Object conditionNameObj : conditionNames) {
String conditionName = (String) conditionNameObj;
Condition condition = policy.getCondition(conditionName);
Object[] nCondition = new Object[2];
nCondition[0] = conditionName;
nCondition[1] = condition;
nConditions.add(nCondition);
}
return nConditionsToECondition(nConditions);
}
use of com.sun.identity.entitlement.EntitlementCondition in project OpenAM by OpenRock.
the class OpenSSOApplicationPrivilegeManager method toApplicationPrivilege.
private ApplicationPrivilege toApplicationPrivilege(Privilege p) throws EntitlementException {
ApplicationPrivilege ap = new ApplicationPrivilege(p.getName());
ap.setDescription(p.getDescription());
ap.setCreatedBy(p.getCreatedBy());
ap.setCreationDate(p.getCreationDate());
ap.setLastModifiedBy(p.getLastModifiedBy());
ap.setLastModifiedDate(p.getLastModifiedDate());
Entitlement ent = p.getEntitlement();
Set<String> resourceNames = ent.getResourceNames();
Map<String, Set<String>> mapAppToRes = getApplicationPrivilegeResourceNames(resourceNames);
ap.setApplicationResources(mapAppToRes);
ap.setActionValues(getActionValues(ent.getActionValues()));
Set<SubjectImplementation> subjects = new HashSet<SubjectImplementation>();
if (p.getSubject() instanceof OrSubject) {
OrSubject orSubject = (OrSubject) p.getSubject();
for (EntitlementSubject es : orSubject.getESubjects()) {
if (es instanceof SubjectImplementation) {
subjects.add((SubjectImplementation) es);
}
}
} else if (p.getSubject() instanceof SubjectImplementation) {
subjects.add((SubjectImplementation) p.getSubject());
}
ap.setSubject(subjects);
EntitlementCondition cond = p.getCondition();
if (cond instanceof SimpleTimeCondition) {
ap.setCondition(cond);
}
return ap;
}
Aggregations