use of com.sun.identity.policy.interfaces.Subject in project OpenAM by OpenRock.
the class UpgradeUtils method createDatastoresReadOnlyPolicy.
/**
* Creates DataStores Read Only Policy
*
* @param policyManager the policy manager object.
* @param orgDN the organization dn.
* @param orgID the organization identifier.
*/
private static void createDatastoresReadOnlyPolicy(PolicyManager policyManager, String orgDN, String orgID) {
String classMethod = "UpgradeUtils:createDatastoresReadOnlyPolicy";
try {
String policyName = orgID + "^^" + DATA_STORE_READ_ONLY;
Policy realmPolicy = new Policy(policyName, null, false, true);
// create Rule
String serviceName = DELEGATION_SERVICE;
String resourceName = "sms://*" + orgDN + "/" + IDREPO_SERVICE;
Rule rule = getRule(serviceName, resourceName);
if (rule != null) {
realmPolicy.addRule(rule);
}
// add subjects
String policyAdminRoleUniversalID = getUniversalID(orgDN, ORG_POLICY_ADMIN_ROLE);
Subject subject = getSubject(policyManager, policyAdminRoleUniversalID);
if (subject != null) {
realmPolicy.addSubject(DELEGATION_SUBJECT, subject, false);
}
policyManager.addPolicy(realmPolicy);
} catch (Exception e) {
debug.error(classMethod + "Error creating datastores readonly policy", e);
}
}
use of com.sun.identity.policy.interfaces.Subject in project OpenAM by OpenRock.
the class PolicySubject method getPolicySubject.
/**
* Constructs a legacy policy subject based on the information in this adapter.
*
* @return the legacy policy subject
* @throws EntitlementException if an error occurs constructing the subject.
*/
@JsonIgnore
public Subject getPolicySubject() throws EntitlementException {
try {
Subject subject = Class.forName(className).asSubclass(Subject.class).newInstance();
subject.setValues(values);
return subject;
} catch (Exception ex) {
throw new EntitlementException(508, ex);
}
}
use of com.sun.identity.policy.interfaces.Subject in project OpenAM by OpenRock.
the class PrivilegeUtils method privilegeToPolicy.
public static Policy privilegeToPolicy(String realm, Privilege privilege) throws PolicyException, SSOException, EntitlementException {
Policy policy = new Policy(privilege.getName());
policy.setDescription(privilege.getDescription());
if (privilege.getEntitlement() != null) {
Entitlement entitlement = privilege.getEntitlement();
Set<Rule> rules = entitlementToRule(realm, entitlement);
for (Rule rule : rules) {
policy.addRule(rule);
}
}
EntitlementSubject es = privilege.getSubject();
if ((es != null) && (es != Privilege.NOT_SUBJECT)) {
Subject sbj = eSubjectToEPSubject(es);
policy.addSubject(getSubjectName(es), sbj, false);
}
EntitlementCondition ec = privilege.getCondition();
if (ec != null) {
Condition cond = eConditionToEPCondition(ec);
policy.addCondition(getConditionName(ec), cond);
}
if (privilege.getResourceAttributes() != null) {
Map<String, ResponseProvider> nrps = resourceAttributesToResponseProviders(privilege.getResourceAttributes());
for (String rpName : nrps.keySet()) {
ResponseProvider responseProvider = nrps.get(rpName);
policy.addResponseProvider(rpName, responseProvider);
}
}
policy.setCreatedBy(privilege.getCreatedBy());
policy.setCreationDate(privilege.getCreationDate());
policy.setLastModifiedBy(privilege.getLastModifiedBy());
policy.setLastModifiedDate(privilege.getLastModifiedDate());
return policy;
}
use of com.sun.identity.policy.interfaces.Subject in project OpenAM by OpenRock.
the class PrivilegeUtils method mapGenericSubject.
private static EntitlementSubject mapGenericSubject(String subjectName, Subject objSubject, boolean exclusive) {
try {
if (objSubject instanceof com.sun.identity.policy.plugins.PrivilegeSubject) {
com.sun.identity.policy.plugins.PrivilegeSubject pips = (com.sun.identity.policy.plugins.PrivilegeSubject) objSubject;
Set<String> values = pips.getValues();
String val = values.iterator().next();
int idx = val.indexOf("=");
String className = val.substring(0, idx);
String state = val.substring(idx + 1);
EntitlementSubject es = (EntitlementSubject) Class.forName(className).newInstance();
es.setState(state);
return es;
} else {
Subject sbj = (Subject) objSubject;
Set<String> val = sbj.getValues();
String className = sbj.getClass().getName();
return new PolicySubject(subjectName, className, val, exclusive);
}
} catch (ClassNotFoundException e) {
PolicyConstants.DEBUG.error("PrivilegeUtils.mapGenericSubject", e);
} catch (InstantiationException e) {
PolicyConstants.DEBUG.error("PrivilegeUtils.mapGenericSubject", e);
} catch (IllegalAccessException e) {
PolicyConstants.DEBUG.error("PrivilegeUtils.mapGenericSubject", e);
}
return null;
}
use of com.sun.identity.policy.interfaces.Subject in project OpenAM by OpenRock.
the class Util method createAMIdentitySubject.
/**
* Returns a Subject for the given AMIdentity.
* @param pm The PolicyManager to use.
* @param user The user to convert into a Subject
* @return a Subject for the given AMIdentity.
* @throws PolicyException if there was a problem creating the Subject.
*/
public static Subject createAMIdentitySubject(PolicyManager pm, AMIdentity user) throws PolicyException {
SubjectTypeManager mgr = pm.getSubjectTypeManager();
Subject subject = mgr.getSubject("AMIdentitySubject");
Set<String> set = new HashSet<String>();
set.add(user.getUniversalId());
subject.setValues(set);
return subject;
}
Aggregations