Search in sources :

Example 1 with RsProtectResponse

use of io.jans.ca.common.response.RsProtectResponse in project jans by JanssenProject.

the class RsProtectOperation method execute.

@Override
public IOpResponse execute(final RsProtectParams params) throws Exception {
    validate(params);
    Rp rp = getRp();
    PatProvider patProvider = new PatProvider() {

        @Override
        public String getPatToken() {
            return getUmaTokenService().getPat(params.getRpId()).getToken();
        }

        @Override
        public void clearPat() {
        // do nothing
        }
    };
    ResourceRegistrar registrar = getOpClientFactory().createResourceRegistrar(patProvider, new ServiceProvider(rp.getOpHost()));
    try {
        registrar.register(params.getResources());
    } catch (ClientErrorException e) {
        LOG.debug("Failed to register resource. Entity: " + e.getResponse().readEntity(String.class) + ", status: " + e.getResponse().getStatus(), e);
        if (e.getResponse().getStatus() == 400 || e.getResponse().getStatus() == 401) {
            LOG.debug("Try maybe PAT is lost on AS, force refresh PAT and re-try ...");
            // force to refresh PAT
            getUmaTokenService().obtainPat(params.getRpId());
            registrar.register(params.getResources());
        } else {
            throw e;
        }
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throw e;
    }
    persist(registrar, rp);
    return new RsProtectResponse(rp.getRpId());
}
Also used : ServiceProvider(io.jans.ca.rs.protect.resteasy.ServiceProvider) RsProtectResponse(io.jans.ca.common.response.RsProtectResponse) PatProvider(io.jans.ca.rs.protect.resteasy.PatProvider) ClientErrorException(javax.ws.rs.ClientErrorException) ResourceRegistrar(io.jans.ca.rs.protect.resteasy.ResourceRegistrar) Rp(io.jans.ca.server.service.Rp) ClientErrorException(javax.ws.rs.ClientErrorException) HttpException(io.jans.ca.server.HttpException) IOException(java.io.IOException)

Example 2 with RsProtectResponse

use of io.jans.ca.common.response.RsProtectResponse in project jans by JanssenProject.

the class RsProtectTest method overwriteTrue.

@Parameters({ "host", "redirectUrls", "opHost", "rsProtect" })
@Test
public void overwriteTrue(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)));
    // force overwrite
    params.setOverwrite(true);
    RsProtectResponse response = client.umaRsProtect(Tester.getAuthorization(site), null, params);
    assertNotNull(response);
}
Also used : RsProtectParams2(io.jans.ca.client.RsProtectParams2) RsResource(io.jans.ca.rs.protect.RsResource) RsProtectResponse(io.jans.ca.common.response.RsProtectResponse) ClientInterface(io.jans.ca.client.ClientInterface) RegisterSiteResponse(io.jans.ca.common.response.RegisterSiteResponse) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 3 with RsProtectResponse

use of io.jans.ca.common.response.RsProtectResponse in project jans by JanssenProject.

the class RsProtectTest method protectResources.

public static RsProtectResponse protectResources(ClientInterface client, RegisterSiteResponse site, List<RsResource> resources) {
    final RsProtectParams2 params = new RsProtectParams2();
    params.setRpId(site.getRpId());
    try {
        params.setResources(Jackson2.createJsonMapper().readTree(Jackson2.asJsonSilently(resources)));
    } catch (IOException e) {
        e.printStackTrace();
    }
    final RsProtectResponse resp = client.umaRsProtect(Tester.getAuthorization(site), null, params);
    assertNotNull(resp);
    return resp;
}
Also used : RsProtectParams2(io.jans.ca.client.RsProtectParams2) RsProtectResponse(io.jans.ca.common.response.RsProtectResponse) IOException(java.io.IOException)

Example 4 with RsProtectResponse

use of io.jans.ca.common.response.RsProtectResponse in project jans by JanssenProject.

the class NotAllowedTest method main.

public static void main(String[] args) throws IOException {
    ClientInterface client = Tester.newClient(HOST);
    RegisterSiteResponse site = registerSite(client);
    final RsProtectParams2 params = new RsProtectParams2();
    params.setRpId(site.getRpId());
    params.setResources(Jackson2.createJsonMapper().readTree(rsProtect));
    final RsProtectResponse resp = client.umaRsProtect(Tester.getAuthorization(site), null, params);
    assertNotNull(resp);
}
Also used : RsProtectParams2(io.jans.ca.client.RsProtectParams2) RsProtectResponse(io.jans.ca.common.response.RsProtectResponse) ClientInterface(io.jans.ca.client.ClientInterface) RegisterSiteResponse(io.jans.ca.common.response.RegisterSiteResponse)

Aggregations

RsProtectResponse (io.jans.ca.common.response.RsProtectResponse)4 RsProtectParams2 (io.jans.ca.client.RsProtectParams2)3 ClientInterface (io.jans.ca.client.ClientInterface)2 RegisterSiteResponse (io.jans.ca.common.response.RegisterSiteResponse)2 IOException (java.io.IOException)2 RsResource (io.jans.ca.rs.protect.RsResource)1 PatProvider (io.jans.ca.rs.protect.resteasy.PatProvider)1 ResourceRegistrar (io.jans.ca.rs.protect.resteasy.ResourceRegistrar)1 ServiceProvider (io.jans.ca.rs.protect.resteasy.ServiceProvider)1 HttpException (io.jans.ca.server.HttpException)1 Rp (io.jans.ca.server.service.Rp)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 Parameters (org.testng.annotations.Parameters)1 Test (org.testng.annotations.Test)1