use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class PolicySearchTest method shouldRemovePolicySearches.
@Test
public void shouldRemovePolicySearches() throws Exception {
//Given
JsonValue policy1 = createUmaPolicyJson("SUBJECT_ONE");
JsonValue policy2 = createUmaPolicyJson("SUBJECT_THREE");
UmaPolicy umaPolicy1 = UmaPolicy.valueOf(resourceSet1, policy1);
UmaPolicy umaPolicy2 = UmaPolicy.valueOf(resourceSet2, policy2);
Set<UmaPolicy> policies1 = new HashSet<UmaPolicy>();
Set<UmaPolicy> policies2 = new HashSet<UmaPolicy>();
policies1.add(umaPolicy1);
policies1.add(umaPolicy2);
policies2.add(umaPolicy2);
PolicySearch policySearch1 = new PolicySearch(policies1);
PolicySearch policySearch2 = new PolicySearch(policies2);
//When
PolicySearch search = policySearch1.remove(policySearch2);
//Then
assertThat(search.getPolicies()).hasSize(1).contains(umaPolicy1);
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class ConsentRequiredResource method addDisplayScopesAndClaims.
private void addDisplayScopesAndClaims(ResourceOwnerConsentRequired consentRequired, Map<String, Object> data) {
JsonValue scopes = json(array());
Set<String> allScopeClaims = new HashSet<>();
final Map<String, List<String>> compositeScopes = consentRequired.getClaims().getCompositeScopes();
final Map<String, String> claimDescriptions = consentRequired.getClaimDescriptions();
final Map<String, Object> claimValues = new LinkedHashMap<>(consentRequired.getClaims().getValues());
for (Map.Entry<String, String> scope : consentRequired.getScopeDescriptions().entrySet()) {
JsonValue value = json(object(field("name", encodeForHTML(scope.getValue()))));
scopes.add(value.getObject());
List<String> scopeClaims = compositeScopes.get(scope.getKey());
if (scopeClaims != null) {
final LinkedHashMap<String, Object> claims = new LinkedHashMap<>();
value.put("values", claims);
for (String claim : scopeClaims) {
Object claimValue = claimValues.get(claim);
if (claimValue != null) {
String claimDescription = claimDescriptions.get(claim);
if (claimDescription == null) {
claimDescription = claim;
}
claims.put(encodeForHTML(claimDescription), encodeForHTML(claimValue.toString()));
allScopeClaims.add(claim);
}
}
}
}
data.put("display_scopes", scopes.toString());
for (String claim : allScopeClaims) {
claimValues.remove(claim);
}
JsonValue claims = json(array());
for (Map.Entry<String, Object> claim : claimValues.entrySet()) {
claims.add(object(field("name", encodeForHTML(claimDescriptions.get(claim.getKey()))), field("values", encodeForHTML(claimValues.get(claim.getKey()).toString()))));
}
data.put("display_claims", claims.toString());
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class TokenInfoServiceImpl method getTokenInfo.
/**
* {@inheritDoc}
*/
public JsonValue getTokenInfo(OAuth2Request request) throws InvalidTokenException, InvalidRequestException, ExpiredTokenException, ServerException, BadRequestException, InvalidGrantException, NotFoundException {
final AccessTokenVerifier.TokenState headerToken = headerTokenVerifier.verify(request);
final AccessTokenVerifier.TokenState queryToken = queryTokenVerifier.verify(request);
final Map<String, Object> response = new HashMap<String, Object>();
if (!headerToken.isValid() && !queryToken.isValid()) {
logger.error("Access Token not valid");
throw new InvalidRequestException("Access Token not valid");
} else if (headerToken.isValid() && queryToken.isValid()) {
logger.error("Access Token provided in both query and header in request");
throw new InvalidRequestException("Access Token cannot be provided in both query and header");
} else {
final AccessToken accessToken = request.getToken(AccessToken.class);
logger.trace("In Validator resource - got token = " + accessToken);
final OAuth2ProviderSettings providerSettings = providerSettingsFactory.get(request);
final Map<String, Object> scopeEvaluation = providerSettings.evaluateScope(accessToken);
response.putAll(accessToken.getTokenInfo());
response.putAll(scopeEvaluation);
return new JsonValue(response);
}
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class TokenIntrospectionServiceImpl method introspect.
/**
* {@inheritDoc}
*/
@Override
public JsonValue introspect(OAuth2Request request) throws InvalidClientException, InvalidRequestException, NotFoundException, ServerException {
ClientRegistration clientRegistration = clientAuthenticator.authenticate(request, urisFactory.get(request).getIntrospectionEndpoint());
String tokenType = request.getParameter(TOKEN_TYPE_HINT);
String tokenId = request.getParameter(TOKEN);
for (TokenIntrospectionHandler handler : handlers) {
JsonValue result = handler.introspect(request, clientRegistration.getClientId(), tokenType, tokenId);
if (result != null) {
return result;
}
}
return json(object(field(ACTIVE, false)));
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class AbstractRestletAccessAuditFilter method auditAccessFailure.
private void auditAccessFailure(Request request, Response response) {
String realm = getRealmFromRequest(request);
if (auditEventPublisher.isAuditing(realm, ACCESS_TOPIC, EventName.AM_ACCESS_OUTCOME)) {
long endTime = System.currentTimeMillis();
String responseCode = Integer.toString(response.getStatus().getCode());
long elapsedTime = endTime - request.getDate().getTime();
JsonValue responseDetail = json(object(field(ACCESS_RESPONSE_DETAIL_REASON, response.getStatus().getDescription())));
AMAccessAuditEventBuilder builder = auditEventFactory.accessEvent(realm).timestamp(endTime).transactionId(AuditRequestContext.getTransactionIdValue()).eventName(EventName.AM_ACCESS_OUTCOME).component(component).userId(getUserIdForAccessOutcome(request, response)).trackingIds(getTrackingIdsForAccessOutcome(request, response)).responseWithDetail(FAILED, responseCode, elapsedTime, MILLISECONDS, responseDetail);
addHttpData(request, builder);
auditEventPublisher.tryPublish(ACCESS_TOPIC, builder.toEvent());
}
}
Aggregations