use of io.jans.ca.server.service.Rp in project jans by JanssenProject.
the class SqlPersistenceServiceImpl method getRps.
public Set<Rp> getRps() {
Connection conn = null;
try {
conn = provider.getConnection();
conn.setAutoCommit(false);
PreparedStatement query = conn.prepareStatement("select id, data from rp");
ResultSet rs = query.executeQuery();
Set<Rp> result = new HashSet<>();
while (rs.next()) {
String id = rs.getString("id");
String data = rs.getString("data");
Rp rp = MigrationService.parseRp(data);
if (rp != null) {
result.add(rp);
} else {
LOG.error("Failed to parse rp, id: " + id);
}
}
query.close();
conn.commit();
LOG.info("Loaded " + result.size() + " RPs.");
return result;
} catch (Exception e) {
LOG.error("Failed to fetch rps. Error: " + e.getMessage(), e);
rollbackSilently(conn);
throw new RuntimeException(e);
} finally {
IOUtils.closeSilently(conn);
}
}
use of io.jans.ca.server.service.Rp in project jans by JanssenProject.
the class RsModifyOperation method execute.
@Override
public IOpResponse execute(final RsModifyParams 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
}
};
io.jans.ca.server.model.UmaResource umaResource = rp.umaResource(params.getPath(), params.getHttpMethod());
if (umaResource == null) {
final ErrorResponse error = new ErrorResponse("invalid_request");
error.setErrorDescription("Resource is not protected with path: " + params.getPath() + " and httpMethod: " + params.getHttpMethod() + ". Please protect your resource first with uma_rs_modify command. Check details on " + CoreUtils.DOC_URL);
LOG.error(error.getErrorDescription());
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON_TYPE).entity(Jackson2.asJson(error)).build());
}
UmaMetadata discovery = getDiscoveryService().getUmaDiscoveryByRpId(params.getRpId());
UmaResourceService resourceService = UmaClientFactory.instance().createResourceService(discovery, getHttpService().getClientEngine());
UmaResource opUmaResource = getResource(resourceService, params, umaResource.getId());
try {
String pat = getUmaTokenService().getPat(params.getRpId()).getToken();
return update(pat, umaResource.getId(), rp, resourceService, opUmaResource);
} catch (ClientErrorException e) {
LOG.debug("Failed to update 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 ...");
return update(getUmaTokenService().obtainPat(params.getRpId()).getToken(), umaResource.getId(), rp, resourceService, opUmaResource);
} else {
throw e;
}
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw e;
}
}
use of io.jans.ca.server.service.Rp in project jans by JanssenProject.
the class GetRequestObjectUriOperation method execute.
public IOpResponse execute(GetRequestObjectUriParams params) {
try {
validate(params);
final Rp rp = getRp();
SignatureAlgorithm algo = SignatureAlgorithm.fromString(params.getRequestObjectSigningAlg()) != null ? SignatureAlgorithm.fromString(params.getRequestObjectSigningAlg()) : SignatureAlgorithm.fromString(rp.getRequestObjectSigningAlg());
if (algo == null) {
LOG.error("`request_object_signing_alg` is required parameter in request. Please set this parameter if it is not set during client registration.");
throw new HttpException(ErrorResponseCode.INVALID_ALGORITHM);
}
Jwt unsignedJwt = createRequestObject(algo, rp, params);
// signing request object
Jwt signedJwt = getKeyGeneratorService().sign(unsignedJwt, rp.getClientSecret(), algo);
// setting request object in Expired Object
String requestUriId = UUID.randomUUID().toString();
getRequestObjectService().put(requestUriId, signedJwt.toString());
String requestUri = baseRequestUri(params.getRpHostUrl()) + requestUriId;
LOG.trace("RequestObject created successfully. request_uri : {} ", requestUri);
GetRequestObjectUriResponse response = new GetRequestObjectUriResponse();
response.setRequestUri(requestUri);
return response;
} catch (HttpException e) {
throw e;
} catch (Exception e) {
LOG.error("Error in creating `request_uri` response ", e);
}
throw new HttpException(ErrorResponseCode.FAILED_TO_GET_REQUEST_URI);
}
Aggregations