Search in sources :

Example 6 with RsResource

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

the class RsProtectTest method overwriteFalse.

@Parameters({ "host", "redirectUrls", "opHost", "rsProtect" })
@Test
public void overwriteFalse(String host, String redirectUrls, String opHost, String rsProtect) throws IOException {
    ClientInterface client = Tester.newClient(host);
    final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls);
    List<RsResource> resources = UmaFullTest.resourceList(rsProtect).getResources();
    protectResources(client, site, resources);
    final RsProtectParams2 params = new RsProtectParams2();
    params.setRpId(site.getRpId());
    params.setResources(Jackson2.createJsonMapper().readTree(Jackson2.asJsonSilently(resources)));
    try {
        client.umaRsProtect(Tester.getAuthorization(site), null, params);
    } catch (BadRequestException e) {
        assertEquals("uma_protection_exists", TestUtils.asError(e).getError());
        return;
    }
    throw new AssertionError("Expected 400 (bad request) but got successful result.");
}
Also used : RsProtectParams2(io.jans.ca.client.RsProtectParams2) RsResource(io.jans.ca.rs.protect.RsResource) BadRequestException(javax.ws.rs.BadRequestException) ClientInterface(io.jans.ca.client.ClientInterface) RegisterSiteResponse(io.jans.ca.common.response.RegisterSiteResponse) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 7 with RsResource

use of io.jans.ca.rs.protect.RsResource 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

RsResource (io.jans.ca.rs.protect.RsResource)7 Condition (io.jans.ca.rs.protect.Condition)4 RSAPublicKey (io.jans.as.model.crypto.signature.RSAPublicKey)2 ClientInterface (io.jans.ca.client.ClientInterface)2 RsProtectParams2 (io.jans.ca.client.RsProtectParams2)2 RegisterSiteResponse (io.jans.ca.common.response.RegisterSiteResponse)2 RsResourceList (io.jans.ca.rs.protect.RsResourceList)2 UmaResource (io.jans.ca.server.model.UmaResource)2 Parameters (org.testng.annotations.Parameters)2 Test (org.testng.annotations.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 UmaResourceService (io.jans.as.client.uma.UmaResourceService)1 UmaMetadata (io.jans.as.model.uma.UmaMetadata)1 Scope (io.jans.as.persistence.model.Scope)1 RsProtectResponse (io.jans.ca.common.response.RsProtectResponse)1 Key (io.jans.ca.rs.protect.resteasy.Key)1 HttpException (io.jans.ca.server.HttpException)1 Rp (io.jans.ca.server.service.Rp)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1