Search in sources :

Example 26 with Rp

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);
    }
}
Also used : Rp(io.jans.ca.server.service.Rp) HashSet(java.util.HashSet)

Example 27 with Rp

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;
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) UmaResourceService(io.jans.as.client.uma.UmaResourceService) ClientErrorException(javax.ws.rs.ClientErrorException) HttpException(io.jans.ca.server.HttpException) WebApplicationException(javax.ws.rs.WebApplicationException) UmaMetadata(io.jans.as.model.uma.UmaMetadata) PatProvider(io.jans.ca.rs.protect.resteasy.PatProvider) ClientErrorException(javax.ws.rs.ClientErrorException) Rp(io.jans.ca.server.service.Rp) UmaResource(io.jans.as.model.uma.UmaResource)

Example 28 with Rp

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);
}
Also used : Jwt(io.jans.as.model.jwt.Jwt) SignatureAlgorithm(io.jans.as.model.crypto.signature.SignatureAlgorithm) HttpException(io.jans.ca.server.HttpException) GetRequestObjectUriResponse(io.jans.ca.common.response.GetRequestObjectUriResponse) Rp(io.jans.ca.server.service.Rp) HttpException(io.jans.ca.server.HttpException)

Aggregations

Rp (io.jans.ca.server.service.Rp)28 HttpException (io.jans.ca.server.HttpException)13 Injector (com.google.inject.Injector)4 OpenIdConfigurationResponse (io.jans.as.client.OpenIdConfigurationResponse)4 RegisterRequest (io.jans.as.client.RegisterRequest)4 SignatureAlgorithm (io.jans.as.model.crypto.signature.SignatureAlgorithm)4 Jwt (io.jans.as.model.jwt.Jwt)4 UmaMetadata (io.jans.as.model.uma.UmaMetadata)4 IOpResponse (io.jans.ca.common.response.IOpResponse)4 Lists (com.google.common.collect.Lists)3 Command (io.jans.ca.common.Command)3 ErrorResponseCode (io.jans.ca.common.ErrorResponseCode)3 RegisterSiteResponse (io.jans.ca.common.response.RegisterSiteResponse)3 Utils (io.jans.ca.server.Utils)3 List (java.util.List)3 StringUtils (org.apache.commons.lang.StringUtils)3 Test (org.testng.annotations.Test)3 Strings (com.google.common.base.Strings)2 Sets (com.google.common.collect.Sets)2 RegisterClient (io.jans.as.client.RegisterClient)2