Search in sources :

Example 1 with RsResourceList

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

the class ApiProtectionService method verifyResources.

public void verifyResources(String apiProtectionType, String clientId) throws IOException {
    log.debug("ApiProtectionService::verifyResources() - apiProtectionType:{}, clientId:{}, configurationFactory:{} ", apiProtectionType, clientId, configurationFactory);
    // Load the resource json
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    InputStream inputStream = loader.getResourceAsStream(PROTECTION_CONFIGURATION_FILE_NAME);
    RsResourceList resourceList = Jackson.createJsonMapper().readValue(inputStream, RsResourceList.class);
    this.rsResourceList = resourceList.getResources();
    log.debug("verifyResources() - rsResourceList{} ", rsResourceList);
    Preconditions.checkNotNull(rsResourceList, "Config Api Resource list cannot be null !!!");
    createScopeIfNeeded(apiProtectionType);
    log.trace("ApiProtectionService:::verifyResources() - allScopes:{}, allResources:{} ", ApiProtectionCache.getAllScopes(), ApiProtectionCache.getAllResources());
    updateScopeForClientIfNeeded(clientId);
}
Also used : InputStream(java.io.InputStream) RsResourceList(io.jans.ca.rs.protect.RsResourceList)

Example 2 with RsResourceList

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

the class OpClientFactoryMockImpl method getIdMap.

private static Map<Key, String> getIdMap(String rsProtect) {
    Map<Key, String> rsIdMap = new HashMap<>();
    try {
        rsProtect = StringUtils.replace(rsProtect, "'", "\"");
        RsResourceList rsResourceList = Jackson2.createJsonMapper().readValue(rsProtect, RsResourceList.class);
        for (RsResource rsResource : rsResourceList.getResources()) {
            for (Condition condition : rsResource.getConditions()) {
                Key key = new Key();
                key.setHttpMethods(condition.getHttpMethods());
                key.setPath(rsResource.getPath());
                rsIdMap.put(key, UUID.randomUUID().toString());
            }
        }
    } catch (Exception e) {
        LOG.error("Failed to parse uma-rs-protect resource json .", e);
    }
    return rsIdMap;
}
Also used : Condition(io.jans.ca.rs.protect.Condition) RsResource(io.jans.ca.rs.protect.RsResource) RsResourceList(io.jans.ca.rs.protect.RsResourceList) RSAPublicKey(io.jans.as.model.crypto.signature.RSAPublicKey)

Example 3 with RsResourceList

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

the class OpClientFactoryMockImpl method getResourceMap.

private static Map<Key, RsResource> getResourceMap(String rsProtect) {
    Map<Key, RsResource> rsResourceMap = new HashMap<>();
    try {
        rsProtect = StringUtils.replace(rsProtect, "'", "\"");
        RsResourceList rsResourceList = Jackson2.createJsonMapper().readValue(rsProtect, RsResourceList.class);
        for (RsResource rsResource : rsResourceList.getResources()) {
            for (Condition condition : rsResource.getConditions()) {
                Key key = new Key();
                key.setHttpMethods(condition.getHttpMethods());
                key.setPath(rsResource.getPath());
                rsResourceMap.put(key, rsResource);
            }
        }
    } catch (Exception e) {
        LOG.error("Failed to parse uma-rs-protect resource json .", e);
    }
    return rsResourceMap;
}
Also used : Condition(io.jans.ca.rs.protect.Condition) RsResource(io.jans.ca.rs.protect.RsResource) RsResourceList(io.jans.ca.rs.protect.RsResourceList) RSAPublicKey(io.jans.as.model.crypto.signature.RSAPublicKey)

Aggregations

RsResourceList (io.jans.ca.rs.protect.RsResourceList)3 RSAPublicKey (io.jans.as.model.crypto.signature.RSAPublicKey)2 Condition (io.jans.ca.rs.protect.Condition)2 RsResource (io.jans.ca.rs.protect.RsResource)2 InputStream (java.io.InputStream)1