Search in sources :

Example 1 with Key

use of io.jans.ca.rs.protect.resteasy.Key in project jans by JanssenProject.

the class RsProtectOperation method persist.

private void persist(ResourceRegistrar registrar, Rp rp) throws IOException {
    Map<Key, RsResource> resourceMapCopy = registrar.getResourceMapCopy();
    for (Map.Entry<Key, String> entry : registrar.getIdMapCopy().entrySet()) {
        UmaResource resource = new UmaResource();
        resource.setId(entry.getValue());
        resource.setPath(entry.getKey().getPath());
        resource.setHttpMethods(entry.getKey().getHttpMethods());
        Set<String> scopes = Sets.newHashSet();
        Set<String> scopesForTicket = Sets.newHashSet();
        Set<String> scopeExpressions = Sets.newHashSet();
        RsResource rsResource = resourceMapCopy.get(entry.getKey());
        for (String httpMethod : entry.getKey().getHttpMethods()) {
            List<String> rsScopes = rsResource.scopes(httpMethod);
            if (rsScopes != null) {
                scopes.addAll(rsScopes);
            }
            scopesForTicket.addAll(rsResource.getScopesForTicket(httpMethod));
            JsonNode scopeExpression = rsResource.getScopeExpression(httpMethod);
            if (scopeExpression != null) {
                scopeExpressions.add(scopeExpression.toString());
            }
        }
        resource.setScopes(Lists.newArrayList(scopes));
        resource.setTicketScopes(Lists.newArrayList(scopesForTicket));
        resource.setScopeExpressions(Lists.newArrayList(scopeExpressions));
        if (rsResource.getIat() != null && rsResource.getIat() > 0) {
            resource.setIat(rsResource.getIat());
        }
        if (rsResource.getExp() != null && rsResource.getExp() > 0) {
            resource.setExp(rsResource.getExp());
        }
        rp.getUmaProtectedResources().add(resource);
    }
    getRpService().update(rp);
}
Also used : RsResource(io.jans.ca.rs.protect.RsResource) JsonNode(com.fasterxml.jackson.databind.JsonNode) Map(java.util.Map) Key(io.jans.ca.rs.protect.resteasy.Key) UmaResource(io.jans.ca.server.model.UmaResource)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 RsResource (io.jans.ca.rs.protect.RsResource)1 Key (io.jans.ca.rs.protect.resteasy.Key)1 UmaResource (io.jans.ca.server.model.UmaResource)1 Map (java.util.Map)1