use of org.forgerock.openam.entitlement.conditions.subject.AuthenticatedUsers in project OpenAM by OpenRock.
the class MultipleResourceRestTest method setup.
@BeforeClass
public void setup() throws Exception {
PrivilegeManager pm = PrivilegeManager.getInstance(REALM, adminSubject);
{
Privilege privilege = Privilege.getNewInstance();
privilege.setName(PRIVILEGE_NAME + "1");
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);
}
{
Privilege privilege = Privilege.getNewInstance();
privilege.setName(PRIVILEGE_NAME + "2");
Map<String, Boolean> actions = new HashMap<String, Boolean>();
actions.put("GET", false);
Entitlement entitlement = new Entitlement(RESOURCE_NAME + "/index.html", 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);
user = IdRepoUtils.createUser(REALM, "MultipleResourceRestTestUser");
decisionsClient = Client.create().resource(SystemProperties.getServerInstanceName() + "/ws/1/entitlement/decisions");
entitlementsClient = Client.create().resource(SystemProperties.getServerInstanceName() + "/ws/1/entitlement/entitlements");
}
use of org.forgerock.openam.entitlement.conditions.subject.AuthenticatedUsers in project OpenAM by OpenRock.
the class HttpStarEvaluationTest method setup.
@BeforeClass
public void setup() throws Exception {
SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
adminSubject = SubjectUtils.createSubject(adminToken);
PrivilegeManager pm = PrivilegeManager.getInstance("/", adminSubject);
Privilege privilege = Privilege.getNewInstance();
privilege.setName(POLICY_NAME);
Map<String, Boolean> actions = new HashMap<String, Boolean>();
actions.put("findAll", true);
Entitlement entitlement = new Entitlement(ApplicationTypeManager.URL_APPLICATION_TYPE_NAME, "http://*", actions);
privilege.setEntitlement(entitlement);
privilege.setSubject(new AuthenticatedUsers());
pm.add(privilege);
}
use of org.forgerock.openam.entitlement.conditions.subject.AuthenticatedUsers in project OpenAM by OpenRock.
the class CanBeDeletedAppTest method createPrivilege.
private void createPrivilege() throws EntitlementException {
PrivilegeManager pm = PrivilegeManager.getInstance("/", adminSubject);
Privilege p = Privilege.getNewInstance();
p.setName(PRIVILEGE_NAME);
Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
actionValues.put("GET", true);
Entitlement entitlement = new Entitlement(APPL_NAME, "http://www.CanBeDeletedAppTest.com/*", actionValues);
p.setEntitlement(entitlement);
p.setSubject(new AuthenticatedUsers());
pm.add(p);
}
use of org.forgerock.openam.entitlement.conditions.subject.AuthenticatedUsers in project OpenAM by OpenRock.
the class ConfigureOAuth2 method execute.
public String execute(Locale locale, Map params) throws WorkflowException {
final String type = getString(params, TYPE);
final String realm = getString(params, REALM);
final SSOToken token = AccessController.doPrivileged(AdminTokenAction.getInstance());
if (StringUtils.isEmpty(type)) {
throw new WorkflowException("type parameter is required");
}
//replace service attributes
final Map<String, Set<String>> attrValues = getDefaultOAuth2ProviderAttributes(token);
attrValues.putAll(PROFILE_SETTINGS.get(type));
attrValues.put(SUPPORTED_SCOPES, translate(realm, SUPPORTED_SCOPE_KEYS.get(type)));
attrValues.put(SUPPORTED_CLAIMS, translate(realm, SUPPORTED_CLAIM_KEYS.get(type)));
attrValues.put(REFRESH_TOKEN_LIFETIME_NAME, singleton(getString(params, RTL)));
attrValues.put(AUTHZ_CODE_LIFETIME_NAME, singleton(getString(params, ACL)));
attrValues.put(ACCESS_TOKEN_LIFETIME_NAME, singleton(getString(params, ATL)));
attrValues.put(ISSUE_REFRESH_TOKEN, singleton(getString(params, IRT)));
attrValues.put(ISSUE_REFRESH_TOKEN_ON_REFRESHING_TOKEN, singleton(getString(params, IRTR)));
attrValues.put(SCOPE_PLUGIN_CLASS, singleton(getString(params, SIC)));
createProvider(OAUTH2_SERVICE_NAME, token, realm, attrValues);
final boolean createUmaService = "uma".equals(type);
if (createUmaService) {
createProvider(UMA_SERVICE_NAME, token, realm, Collections.<String, Set<String>>emptyMap());
}
String policyURL = getRequestURL(params) + format(OAUTH2_AUTHORIZE_ENDPOINT, "/".equals(realm) ? "" : realm);
//check if policy exists
boolean createPolicy = false;
try {
Subject adminSubject = SubjectUtils.createSuperAdminSubject();
PolicyStore policyStore = storeProvider.getPolicyStore(adminSubject, realm);
try {
if (policyStore.read(POLICY_NAME) == null) {
createPolicy = true;
}
} catch (Exception e) {
createPolicy = true;
}
if (createPolicy) {
Privilege toStore = Privilege.getNewInstance();
Map<String, Boolean> actions = new HashMap<>();
actions.put("POST", true);
actions.put("GET", true);
Entitlement entitlement = new Entitlement();
entitlement.setActionValues(actions);
entitlement.setResourceName(policyURL);
entitlement.setApplicationName(POLICY_APPLICATION_NAME);
toStore.setResourceTypeUuid(getUrlResourceTypeId(adminSubject, realm));
toStore.setSubject(new AuthenticatedUsers());
toStore.setName(POLICY_NAME);
toStore.setEntitlement(entitlement);
policyStore.create(toStore);
}
} catch (EntitlementException e) {
DEBUG.error("ConfigureOAuth2.execute() : Unable to create policy", e);
throw new WorkflowException("oauth2.provider.policy.failed");
}
String messageTemplate = getMessage(MESSAGE, locale);
return format(messageTemplate, createUmaService ? getMessage(UMA_SERVICE_CREATED, locale) : "", realm, format(getMessage(createPolicy ? POLICY_CREATED : POLICY_EXISTS, locale), POLICY_NAME));
}
use of org.forgerock.openam.entitlement.conditions.subject.AuthenticatedUsers in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldPrintSimpleSubjects.
@Test
public void shouldPrintSimpleSubjects() throws Exception {
// Given
Privilege policy = new StubPrivilege();
policy.setSubject(new AuthenticatedUsers());
// When
JsonValue result = parser.printPolicy(policy);
// Then
assertThat(result.get(new JsonPointer("subject/type")).asString()).isEqualTo("AuthenticatedUsers");
}
Aggregations