Search in sources :

Example 86 with JsonValue

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);
}
Also used : JsonValue(org.forgerock.json.JsonValue) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 87 with JsonValue

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());
}
Also used : JsonValue(org.forgerock.json.JsonValue) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 88 with JsonValue

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);
    }
}
Also used : HashMap(java.util.HashMap) JsonValue(org.forgerock.json.JsonValue) InvalidRequestException(org.forgerock.oauth2.core.exceptions.InvalidRequestException) HashMap(java.util.HashMap) Map(java.util.Map) AccessTokenVerifier(org.forgerock.oauth2.core.AccessTokenVerifier)

Example 89 with JsonValue

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)));
}
Also used : JsonValue(org.forgerock.json.JsonValue)

Example 90 with JsonValue

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());
    }
}
Also used : JsonValue(org.forgerock.json.JsonValue) AMAccessAuditEventBuilder(org.forgerock.openam.audit.AMAccessAuditEventBuilder)

Aggregations

JsonValue (org.forgerock.json.JsonValue)575 Test (org.testng.annotations.Test)333 ResourceException (org.forgerock.json.resource.ResourceException)144 ResourceResponse (org.forgerock.json.resource.ResourceResponse)123 RealmContext (org.forgerock.openam.rest.RealmContext)70 Context (org.forgerock.services.context.Context)63 HashSet (java.util.HashSet)56 SSOException (com.iplanet.sso.SSOException)54 ArrayList (java.util.ArrayList)51 BadRequestException (org.forgerock.json.resource.BadRequestException)47 Privilege (com.sun.identity.entitlement.Privilege)46 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)46 SSOToken (com.iplanet.sso.SSOToken)43 SMSException (com.sun.identity.sm.SMSException)42 HashMap (java.util.HashMap)42 NotFoundException (org.forgerock.json.resource.NotFoundException)41 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)41 CreateRequest (org.forgerock.json.resource.CreateRequest)40 OpenSSOPrivilege (com.sun.identity.entitlement.opensso.OpenSSOPrivilege)39 Subject (javax.security.auth.Subject)32