use of com.sun.identity.entitlement.opensso.OpenSSOUserSubject in project OpenAM by OpenRock.
the class OpenProvisioning method createPolicy.
private void createPolicy(SSOToken adminToken) throws EntitlementException {
PrivilegeManager pMgr = new PolicyPrivilegeManager(applicationServiceFactory, resourceTypeService, constraintValidator);
pMgr.initialize("/", SubjectUtils.createSubject(adminToken));
Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
actionValues.put("CREATE", Boolean.TRUE);
actionValues.put("READ", Boolean.TRUE);
actionValues.put("UPDATE", Boolean.TRUE);
actionValues.put("DELETE", Boolean.TRUE);
Entitlement entitlement = new Entitlement(APPLICATION, "/OP/*", actionValues);
entitlement.setName("openProvisioningPrivilege");
UserSubject sbj = new OpenSSOUserSubject();
sbj.setID(jSmith.getUniversalId());
AttributeLookupCondition cond = new AttributeLookupCondition("$USER.postaladdress", "$RES.postaladdress");
Privilege privilege = Privilege.getNewInstance();
privilege.setName(PRIVILEGE_NAME);
privilege.setEntitlement(entitlement);
privilege.setSubject(sbj);
privilege.setCondition(cond);
pMgr.add(privilege);
}
use of com.sun.identity.entitlement.opensso.OpenSSOUserSubject in project OpenAM by OpenRock.
the class ListPolicyNamesTest method createPrivilege.
private void createPrivilege(String name) throws EntitlementException {
Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
actionValues.put("GET", Boolean.TRUE);
actionValues.put("POST", Boolean.FALSE);
String resourceName = "http://www.listpolicynamestest.com:80";
Entitlement entitlement = new Entitlement(APPL_NAME, resourceName, actionValues);
entitlement.setName("ent1");
String user = "id=demo,ou=user," + ServiceManager.getBaseDN();
OpenSSOUserSubject usersubj = new OpenSSOUserSubject();
usersubj.setID(user);
Privilege priv = Privilege.getNewInstance();
priv.setName(name);
priv.setEntitlement(entitlement);
priv.setSubject(usersubj);
pm.addPrivilege(priv);
}
use of com.sun.identity.entitlement.opensso.OpenSSOUserSubject in project OpenAM by OpenRock.
the class ApplicationPrivilegeBase method getSubjects.
protected Map<String, Set<String>> getSubjects(ApplicationPrivilege appPrivilege) {
Map<String, Set<String>> results = new HashMap<String, Set<String>>();
Set<SubjectImplementation> subjects = appPrivilege.getSubjects();
for (SubjectImplementation subject : subjects) {
String type = null;
String uuid = null;
if (subject instanceof OpenSSOUserSubject) {
type = PARAM_SUBJECT_USER;
uuid = ((OpenSSOUserSubject) subject).getID();
} else if (subject instanceof OpenSSOGroupSubject) {
type = PARAM_SUBJECT_GROUP;
uuid = ((OpenSSOGroupSubject) subject).getID();
}
if (type != null) {
Set<String> set = results.get(type);
if (set == null) {
set = new HashSet<String>();
results.put(type, set);
}
set.add(uuid);
}
}
return results;
}
use of com.sun.identity.entitlement.opensso.OpenSSOUserSubject in project OpenAM by OpenRock.
the class ApplicationPrivilegeCLITest method validateSubjects.
private void validateSubjects(ApplicationPrivilege ap, Set<AMIdentity> users, String methodName) throws Exception {
Set<SubjectImplementation> subjects = ap.getSubjects();
if ((subjects == null) || (subjects.size() != users.size())) {
throw new Exception("ApplicationPrivilegeCLITest." + methodName + ": " + "subjects is empty.");
}
for (SubjectImplementation subject : subjects) {
if (!(subject instanceof OpenSSOUserSubject)) {
throw new Exception("ApplicationPrivilegeCLITest." + methodName + ": " + "subject is incorrect.");
}
String uuid = ((OpenSSOUserSubject) subject).getID();
boolean found = false;
for (AMIdentity user : users) {
if (uuid.equals(user.getUniversalId())) {
found = true;
break;
}
}
if (!found) {
throw new Exception("ApplicationPrivilegeCLITest." + methodName + ": " + "uuid is incorrect.");
}
}
}
use of com.sun.identity.entitlement.opensso.OpenSSOUserSubject in project OpenAM by OpenRock.
the class PrivilegeUtilsTest method testPrivilegeToPolicy.
@Test
public void testPrivilegeToPolicy() throws Exception {
String BASE_DN = Constants.DEFAULT_ROOT_SUFFIX;
Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
actionValues.put("GET", Boolean.TRUE);
actionValues.put("POST", Boolean.TRUE);
String resourceName = "http://www.sun.com";
Entitlement entitlement = new Entitlement("iPlanetAMWebAgentService", resourceName, actionValues);
entitlement.setName("ent1");
String user11 = "id=user11,ou=user," + BASE_DN;
String user12 = "id=user12,ou=user," + BASE_DN;
UserSubject us1 = new OpenSSOUserSubject();
us1.setID(user11);
UserSubject us2 = new OpenSSOUserSubject();
us2.setID(user12);
Set<EntitlementSubject> subjects = new HashSet<EntitlementSubject>();
subjects.add(us1);
subjects.add(us2);
OrSubject os = new OrSubject(subjects);
IPv4Condition ipc = new IPv4Condition();
ipc.setStartIpAndEndIp("100.100.100.100", "200.200.200.200");
Set<EntitlementCondition> setConditions = new HashSet<EntitlementCondition>();
setConditions.add(ipc);
AndCondition andCondition = new AndCondition();
andCondition.setEConditions(setConditions);
StaticAttributes sa1 = new StaticAttributes();
Set<String> aValues = new HashSet<String>();
aValues.add("a10");
aValues.add("a20");
sa1.setPropertyName("a");
sa1.setPropertyValues(aValues);
sa1.setPResponseProviderName("sa");
StaticAttributes sa2 = new StaticAttributes();
Set<String> bValues = new HashSet<String>();
bValues.add("b10");
bValues.add("b20");
sa2.setPropertyName("b");
sa2.setPropertyValues(bValues);
sa2.setPResponseProviderName("sa");
UserAttributes uat1 = new UserAttributes();
uat1.setPropertyName("email");
uat1.setPResponseProviderName("ua");
UserAttributes uat2 = new UserAttributes();
uat2.setPropertyName("uid");
uat2.setPResponseProviderName("ua");
Set<ResourceAttribute> ra = new HashSet<ResourceAttribute>();
ra.add(sa1);
ra.add(sa2);
ra.add(uat1);
ra.add(uat2);
Privilege privilege = Privilege.getNewInstance();
privilege.setName("PrivilegeUtilsTest");
privilege.setEntitlement(entitlement);
//orSubject
privilege.setSubject(os);
privilege.setCondition(andCondition);
privilege.setResourceAttributes(ra);
Policy policy = PrivilegeUtils.privilegeToPolicy("/", privilege);
Set<IPrivilege> ps = PrivilegeUtils.policyToPrivileges(policy);
if ((ps == null) || ps.isEmpty()) {
throw new Exception("PrivilegeUtilsTest.testPrivilegeToPolicy failed.");
}
}
Aggregations