use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.
the class ApplicationPrivilegeBase method getApplicationResourcesMap.
protected Map<String, Set<String>> getApplicationResourcesMap(RequestContext rc, String realm) throws CLIException, EntitlementException {
String appName = getStringOptionValue(PARAM_APPL_NAME);
Subject subject = SubjectUtils.createSubject(getAdminSSOToken());
Application application = ApplicationManager.getApplication(subject, realm, appName);
if (application == null) {
String[] param = { appName };
throw new CLIException(MessageFormat.format(getResourceString("privilege-application-application-invalid"), (Object[]) param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
Set<String> delResources = new HashSet<String>();
List<String> resources = rc.getOption(PARAM_RESOURCES);
// if resources is not provided, delegate all resources
if ((resources == null) || resources.isEmpty()) {
delResources.addAll(getAllBaseResources(subject, realm, application));
} else {
delResources.addAll(resources);
}
Map<String, Set<String>> map = new HashMap<String, Set<String>>();
map.put(appName, delResources);
return map;
}
use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.
the class ConfigureOAuth2 method getUrlResourceTypeId.
private String getUrlResourceTypeId(Subject adminSubject, String realm) throws EntitlementException, WorkflowException {
Application application = ApplicationManager.getApplication(adminSubject, realm, POLICY_APPLICATION_NAME);
if (application == null) {
ApplicationType applicationType = ApplicationTypeManager.getAppplicationType(adminSubject, ApplicationTypeManager.URL_APPLICATION_TYPE_NAME);
application = ApplicationManager.newApplication(POLICY_APPLICATION_NAME, applicationType);
}
Set<String> resourceTypeIds = application.getResourceTypeUuids();
ResourceTypeService resourceTypeService = InjectorHolder.getInstance(ResourceTypeService.class);
for (String id : resourceTypeIds) {
ResourceType resourceType = resourceTypeService.getResourceType(adminSubject, realm, id);
if (POLICY_RESOURCE_TYPE_NAME.equalsIgnoreCase(resourceType.getName())) {
return id;
}
}
QueryFilter<SmsAttribute> name = equalTo(SmsAttribute.newSearchableInstance("name"), POLICY_RESOURCE_TYPE_NAME);
Set<ResourceType> types = resourceTypeService.getResourceTypes(name, adminSubject, realm);
ResourceType resourceType;
if (types == null || types.isEmpty()) {
resourceType = ResourceType.builder().addPatterns(asSet("*://*:*/*/authorize?*")).addActions(new ImmutableMap.Builder<String, Boolean>().put("GET", true).put("POST", true).build()).setName(POLICY_RESOURCE_TYPE_NAME).setUUID(UUID.randomUUID().toString()).build();
resourceType = resourceTypeService.saveResourceType(adminSubject, realm, resourceType);
} else {
resourceType = types.iterator().next();
}
application.addAllResourceTypeUuids(asSet(resourceType.getUUID()));
application.setEntitlementCombiner(DenyOverride.class);
ApplicationManager.saveApplication(adminSubject, realm, application);
return resourceType.getUUID();
}
use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.
the class PrivilegeUtils method referralPrivilegeToPolicy.
public static Policy referralPrivilegeToPolicy(String realm, ReferralPrivilege referralPrivilege) throws PolicyException, SSOException, EntitlementException {
Policy policy = new Policy(referralPrivilege.getName(), referralPrivilege.getDescription(), true);
SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
javax.security.auth.Subject adminSubject = SubjectUtils.createSubject(adminToken);
PolicyManager pm = new PolicyManager(adminToken, realm);
ReferralTypeManager rm = pm.getReferralTypeManager();
policy.setCreatedBy(referralPrivilege.getCreatedBy());
policy.setCreationDate(referralPrivilege.getCreationDate());
policy.setLastModifiedBy(referralPrivilege.getLastModifiedBy());
policy.setLastModifiedDate(referralPrivilege.getLastModifiedDate());
int count = 1;
for (String r : referralPrivilege.getRealms()) {
Referral referral = rm.getReferral("SubOrgReferral");
Set<String> tmp = new HashSet<String>();
tmp.add(r);
referral.setValues(tmp);
policy.addReferral("referral" + count++, referral);
}
Map<String, Set<String>> map = referralPrivilege.getOriginalMapApplNameToResources();
count = 1;
String realmName = LDAPUtils.isDN(realm) ? DNMapper.orgNameToRealmName(realm) : realm;
for (String appName : map.keySet()) {
Set<String> res = map.get(appName);
Application application = ApplicationManager.getApplication(PolicyConstants.SUPER_ADMIN_SUBJECT, realmName, appName);
if (application == null) {
Object[] params = { appName, realm };
throw new EntitlementException(105, params);
}
String serviceName = application.getApplicationType().getName();
for (String r : res) {
Rule rule = new Rule("rule" + count++, serviceName, r, Collections.EMPTY_MAP);
rule.setApplicationName(appName);
policy.addRule(rule);
}
}
return policy;
}
use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.
the class UmaPolicyApplicationListener method createApplication.
private void createApplication(String realm, String resourceServerId) {
Subject adminSubject = SubjectUtils.createSuperAdminSubject();
try {
Application application = applicationManager.getApplication(adminSubject, realm, resourceServerId);
if (application == null) {
ApplicationType applicationType = applicationTypeManagerWrapper.getApplicationType(adminSubject, UmaConstants.UMA_POLICY_APPLICATION_TYPE);
application = new Application(resourceServerId, applicationType);
application.setEntitlementCombiner(DenyOverride.class);
applicationManager.saveApplication(adminSubject, realm, application);
}
} catch (EntitlementException e) {
logger.error("Failed to create policy application", e);
}
}
use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.
the class UmaResourceSetRegistrationHook method resourceSetCreated.
/**
* Creates a ResourceType for the Resource Set and adds it to the Resource Server's policy Application.
*
* @param realm {@inheritDoc}
* @param resourceSet {@inheritDoc}
*/
@Override
public void resourceSetCreated(String realm, ResourceSetDescription resourceSet) throws ServerException {
Map<String, Boolean> resourceTypeActions = new HashMap<String, Boolean>();
for (String umaScope : resourceSet.getScopes()) {
resourceTypeActions.put(umaScope, Boolean.TRUE);
}
ResourceType resourceType = ResourceType.builder().setName(resourceSet.getName() + " - " + resourceSet.getId()).setUUID(resourceSet.getId()).setDescription("Dynamically created resource type for the UMA resource set. " + "Used to find all Policy Engine Policies that make up an UMA Policy").setActions(resourceTypeActions).addPattern(UmaConstants.UMA_POLICY_SCHEME_PATTERN).build();
Subject adminSubject = SubjectUtils.createSuperAdminSubject();
try {
resourceTypeService.saveResourceType(adminSubject, realm, resourceType);
} catch (EntitlementException e) {
logger.error("Failed to create resource type for resource set, {}", resourceSet, e);
throw new ServerException(e);
}
try {
Application application = applicationManager.getApplication(adminSubject, realm, resourceSet.getClientId().toLowerCase());
application.addResourceTypeUuid(resourceType.getUUID());
applicationManager.saveApplication(adminSubject, realm, application);
} catch (EntitlementException e) {
logger.error("Failed to add Resource Type, " + resourceType.getUUID() + " to application, " + resourceSet.getClientId(), e);
throw new ServerException(e);
}
}
Aggregations