use of com.sun.identity.entitlement.PrivilegeManager in project OpenAM by OpenRock.
the class PrivilegeRestTest method setup.
@BeforeClass
public void setup() throws Exception {
PrivilegeManager pm = PrivilegeManager.getInstance("/", adminSubject);
Privilege privilege = Privilege.getNewInstance();
privilege.setName(PRIVILEGE_NAME);
privilege.setDescription("desciption");
Map<String, Boolean> actions = new HashMap<String, Boolean>();
actions.put("GET", true);
Entitlement entitlement = new Entitlement(RESOURCE_NAME + "/*", actions);
privilege.setEntitlement(entitlement);
EntitlementSubject sbj = new AuthenticatedUsers();
privilege.setSubject(sbj);
pm.add(privilege);
String tokenId = adminToken.getTokenID().toString();
hashedTokenId = Hash.hash(tokenId);
tokenIdHeader = RestServiceManager.SSOTOKEN_SUBJECT_PREFIX + RestServiceManager.SUBJECT_DELIMITER + tokenId;
String cookieValue = tokenId;
if (Boolean.parseBoolean(SystemProperties.get(Constants.AM_COOKIE_ENCODE, "false"))) {
cookieValue = URLEncoder.encode(tokenId, "UTF-8");
}
cookie = new Cookie(SystemProperties.get(Constants.AM_COOKIE_NAME), cookieValue);
webClient = Client.create().resource(SystemProperties.getServerInstanceName() + "/ws/1/entitlement/privilege");
}
use of com.sun.identity.entitlement.PrivilegeManager in project OpenAM by OpenRock.
the class RestPermissionTest method createPrivilege.
private void createPrivilege() throws EntitlementException {
PrivilegeManager pm = PrivilegeManager.getInstance("/", adminSubject);
Privilege privilege = Privilege.getNewInstance();
privilege.setName(PRIVILEGE_NAME);
privilege.setDescription("desciption");
Map<String, Boolean> actions = new HashMap<String, Boolean>();
actions.put("GET", true);
Entitlement entitlement = new Entitlement(RESOURCE_NAME + "/*", actions);
privilege.setEntitlement(entitlement);
EntitlementSubject sbj = new AuthenticatedUsers();
privilege.setSubject(sbj);
pm.add(privilege);
}
use of com.sun.identity.entitlement.PrivilegeManager in project OpenAM by OpenRock.
the class RemoveReferralsStep method enactRequiredPolicyModelChanges.
private void enactRequiredPolicyModelChanges(Application application, String sourceRealm, String destinationRealm) throws EntitlementException, UpgradeException {
PrivilegeManager policyManager = policyServiceFactory.get(destinationRealm, getAdminSubject());
List<Privilege> policies = policyManager.findAllPoliciesByApplication(application.getName());
if (policies.isEmpty()) {
// Only necessary to reinstate application if policies exist in the realm.
return;
}
try {
UpgradeProgress.reportStart(AUDIT_CLONING_APPLICATION_START, application.getName(), destinationRealm);
String resourceTypeId = application.getResourceTypeUuids().iterator().next();
String clonedResourceTypeId = instateAssociatedResourceType(resourceTypeId, sourceRealm, destinationRealm);
Application clonedApplication = cloneApplication(application, clonedResourceTypeId);
applicationService.saveApplication(getAdminSubject(), destinationRealm, clonedApplication);
for (Privilege policy : policies) {
policy.setResourceTypeUuid(clonedResourceTypeId);
policyManager.modify(policy);
}
UpgradeProgress.reportEnd(AUDIT_UPGRADE_SUCCESS);
} catch (EntitlementException | UpgradeException e) {
UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
throw e;
}
}
use of com.sun.identity.entitlement.PrivilegeManager in project OpenAM by OpenRock.
the class UpgradeResourceTypeStep method perform.
/**
* {@inheritDoc}
*/
@Override
public void perform() throws UpgradeException {
for (Map.Entry<String, Set<ResourceTypeState>> entry : resourceTypeStatePerRealm.entrySet()) {
final String realm = entry.getKey();
final EntitlementConfiguration ec = EntitlementConfiguration.getInstance(getAdminSubject(), realm);
final PrivilegeManager pm = PrivilegeManager.getInstance(realm, getAdminSubject());
for (ResourceTypeState state : entry.getValue()) {
if (state.applicationNeedsResourceType) {
ResourceType resourceType = createResourceType(state, realm);
upgradeApplication(ec, state.appName, resourceType.getUUID());
// Application modified, clear cache.
ApplicationManager.clearCache(realm);
}
if (state.policiesNeedsResourceType) {
final Application application = ec.getApplication(state.appName);
final Set<String> uuids = application.getResourceTypeUuids();
if (!uuids.isEmpty()) {
// there should only be one resource type associated with the application at this stage
upgradePrivileges(pm, state.appName, uuids.iterator().next());
}
}
}
}
}
use of com.sun.identity.entitlement.PrivilegeManager in project OpenAM by OpenRock.
the class OldPolicyConditionMigrationUpgradeStep method perform.
/**
* Does the persisting of the upgraded policies.
*
* @throws UpgradeException If there is a problem saving the policies.
*/
@Override
public void perform() throws UpgradeException {
for (Map.Entry<String, Set<Privilege>> entry : privilegesToUpgrade.entrySet()) {
String realm = entry.getKey();
//ensure reading apps cleanly
ApplicationManager.clearCache(realm);
PrivilegeManager privilegeManager = getPrivilegeManager(realm);
for (Privilege privilege : entry.getValue()) {
privilege.getEntitlement().clearCache();
try {
addResourceType(privilege, realm);
privilegeManager.modify(privilege.getName(), privilege);
} catch (EntitlementException e) {
DEBUG.error("Failed to modify privilege!", e);
throw new UpgradeException("Failed to modify privilege!", e);
}
}
}
}
Aggregations