use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.
the class UmaPolicyServiceImplTest method shouldQueryUmaPoliciesByUnknownSubjectAndResourceServer.
@Test
@SuppressWarnings("unchecked")
public void shouldQueryUmaPoliciesByUnknownSubjectAndResourceServer() throws Exception {
//Given
Context context = createContext();
QueryRequest request = Requests.newQueryRequest("").setQueryFilter(QueryFilter.and(QueryFilter.equalTo(new JsonPointer("permissions/subject"), "OTHER_SUBJECT"), QueryFilter.equalTo(new JsonPointer("resourceServer"), "CLIENT_ID")));
mockBackendQuery(context, createBackendSubjectOnePolicyJson(), createBackendSubjectTwoPolicyJson());
//When
Pair<QueryResponse, Collection<UmaPolicy>> queryResult = policyService.queryPolicies(context, request).getOrThrowUninterruptibly();
//Then
assertThat(queryResult.getSecond()).hasSize(0);
}
use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.
the class PolicyResourceWithCopyMoveSupport method copyOrMovePoliciesByApplication.
private ActionResponse copyOrMovePoliciesByApplication(Context context, ActionRequest request, PolicyAction copyOrMoveAction) throws ResourceException {
JsonValue payload = request.getContent();
JsonValue from = payload.get("from");
JsonValue to = payload.get("to");
if (from.isNull()) {
throw new BadRequestException("from definition is missing");
}
if (!from.isDefined("application")) {
throw new BadRequestException("from application definition is missing");
}
String sourceApplication = from.get("application").asString();
if (to.isNull()) {
throw new BadRequestException("to definition is missing");
}
String sourceRealm = RealmContext.getRealm(context);
String destinationRealm = to.get("realm").defaultTo(sourceRealm).asString();
String destinationApplication = to.get("application").defaultTo(sourceApplication).asString();
JsonValue resourceTypeMapping = payload.get("resourceTypeMapping").defaultTo(Collections.emptyMap());
String namePostfix = to.get("namePostfix").defaultTo("").asString();
QueryRequest queryRequest = Requests.newQueryRequest("policies");
queryRequest.setQueryFilter(QueryFilter.equalTo(new JsonPointer("applicationName"), sourceApplication));
final List<JsonValue> policies = new ArrayList<>();
router.handleQuery(context, queryRequest, new QueryResourceHandler() {
@Override
public boolean handleResource(ResourceResponse resourceResponse) {
policies.add(resourceResponse.getContent());
return true;
}
}).getOrThrowUninterruptibly();
JsonValue actionResponseContent = json(array());
for (JsonValue policy : policies) {
ActionResponse response = copyOrMoveGivenPolicy(context, policy, destinationRealm, destinationApplication, namePostfix, resourceTypeMapping, copyOrMoveAction);
actionResponseContent.add(response.getJsonContent().asMap());
}
return Responses.newActionResponse(actionResponseContent);
}
use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldPrintComplexConditions.
@Test
public void shouldPrintComplexConditions() throws Exception {
// Given
Privilege policy = new StubPrivilege();
AndCondition and = new AndCondition();
Set<EntitlementCondition> subConditions = new LinkedHashSet<EntitlementCondition>();
Map<String, Set<String>> props = new HashMap<String, Set<String>>();
props.put("AuthenticateToRealm", Collections.singleton("REALM"));
PolicyCondition policyCondition = new PolicyCondition("test", AuthenticateToRealmCondition.class.getName(), props);
NotCondition not = new NotCondition(policyCondition);
subConditions.add(not);
and.setEConditions(subConditions);
policy.setCondition(and);
// When
JsonValue result = parser.printPolicy(policy);
// Then
assertThat(result.get(new JsonPointer("condition/type")).asString()).isEqualTo("AND");
assertThat(result.get(new JsonPointer("condition/conditions/0/type")).asString()).isEqualTo("NOT");
assertThat(result.get(new JsonPointer("condition/conditions/0/condition/type")).asString()).isEqualTo("Policy");
assertThat(result.get(new JsonPointer("condition/conditions/0/condition/className")).asString()).isEqualTo(AuthenticateToRealmCondition.class.getName());
assertThat(result.get(new JsonPointer("condition/conditions/0/condition/properties")).asMapOfList(String.class)).includes(entry("AuthenticateToRealm", Arrays.asList("REALM")));
}
use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldHandleStringEquality.
@Test
public void shouldHandleStringEquality() throws Exception {
// Given
String value = "testValue";
QueryRequest request = mockQueryRequest(equalTo(new JsonPointer(STRING_ATTRIBUTE), value));
Subject subject = new Subject();
// When
applicationsResource.query(request, subject, "/abc");
// Then
SearchFilter searchFilter = new SearchFilter(new SearchAttribute(STRING_ATTRIBUTE, "ou"), value);
verify(applicationManagerWrapper).search(eq(subject), eq("/abc"), eq(asSet(searchFilter)));
}
use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldTranslateSupportedOperators.
@Test(dataProvider = "SupportedQueryOperators")
public void shouldTranslateSupportedOperators(String queryOperator, SearchFilter.Operator expectedOperator) throws Exception {
// Given
long value = 123l;
QueryRequest request = mockQueryRequest(comparisonFilter(new JsonPointer(NUMERIC_ATTRIBUTE), queryOperator, value));
Subject subject = new Subject();
// When
applicationsResource.query(request, subject, "/abc");
// Then
SearchFilter searchFilter = new SearchFilter(new SearchAttribute(NUMERIC_ATTRIBUTE, "ou"), value, expectedOperator);
verify(applicationManagerWrapper).search(eq(subject), eq("/abc"), eq(asSet(searchFilter)));
}
Aggregations