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());
}
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);
}
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;
}
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);
}
Aggregations