Search in sources :

Example 1 with GetRequestObjectUriResponse

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

the class GetRequestUriTest method test.

@Parameters({ "host", "redirectUrls", "opHost" })
@Test
public void test(String host, String redirectUrls, String opHost) {
    ClientInterface client = Tester.newClient(host);
    // client registration
    final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls);
    // jwks generation
    JsonNode jwks = client.getRpJwks();
    // update jwks in OP
    UpdateSiteParams updateSiteParams = new UpdateSiteParams();
    updateSiteParams.setRpId(site.getRpId());
    updateSiteParams.setJwks(jwks.asText());
    updateSiteParams.setRequestObjectSigningAlg("RS256");
    client.updateSite(Tester.getAuthorization(site), null, updateSiteParams);
    // Request uri
    GetRequestObjectUriParams getRequestUriParams = new GetRequestObjectUriParams();
    getRequestUriParams.setRpId(site.getRpId());
    getRequestUriParams.setRpHostUrl("http://localhost" + ":" + SetUpTest.SUPPORT.getLocalPort());
    GetRequestObjectUriResponse getRequestUriResponse = client.getRequestObjectUri(Tester.getAuthorization(site), null, getRequestUriParams);
    assertNotNull(getRequestUriResponse.getRequestUri());
    // Get Request object
    String requestObjectId = getRequestUriResponse.getRequestUri().substring(getRequestUriResponse.getRequestUri().lastIndexOf('/') + 1);
    String requestObject = client.getRequestObject(requestObjectId);
    assertNotNull(requestObject);
    Map<String, String> paramsMap = new HashMap<>();
    paramsMap.put("request", requestObject);
    final GetAuthorizationUrlParams commandParams = new GetAuthorizationUrlParams();
    commandParams.setRpId(site.getRpId());
    commandParams.setParams(paramsMap);
    final GetAuthorizationUrlResponse resp = client.getAuthorizationUrl(Tester.getAuthorization(site), null, commandParams);
    assertNotNull(resp);
    TestUtils.notEmpty(resp.getAuthorizationUrl());
}
Also used : GetAuthorizationUrlResponse(io.jans.ca.common.response.GetAuthorizationUrlResponse) HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) ClientInterface(io.jans.ca.client.ClientInterface) UpdateSiteParams(io.jans.ca.common.params.UpdateSiteParams) RegisterSiteResponse(io.jans.ca.common.response.RegisterSiteResponse) GetRequestObjectUriResponse(io.jans.ca.common.response.GetRequestObjectUriResponse) GetRequestObjectUriParams(io.jans.ca.common.params.GetRequestObjectUriParams) GetAuthorizationUrlParams(io.jans.ca.common.params.GetAuthorizationUrlParams) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 2 with GetRequestObjectUriResponse

use of io.jans.ca.common.response.GetRequestObjectUriResponse 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

GetRequestObjectUriResponse (io.jans.ca.common.response.GetRequestObjectUriResponse)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 SignatureAlgorithm (io.jans.as.model.crypto.signature.SignatureAlgorithm)1 Jwt (io.jans.as.model.jwt.Jwt)1 ClientInterface (io.jans.ca.client.ClientInterface)1 GetAuthorizationUrlParams (io.jans.ca.common.params.GetAuthorizationUrlParams)1 GetRequestObjectUriParams (io.jans.ca.common.params.GetRequestObjectUriParams)1 UpdateSiteParams (io.jans.ca.common.params.UpdateSiteParams)1 GetAuthorizationUrlResponse (io.jans.ca.common.response.GetAuthorizationUrlResponse)1 RegisterSiteResponse (io.jans.ca.common.response.RegisterSiteResponse)1 HttpException (io.jans.ca.server.HttpException)1 Rp (io.jans.ca.server.service.Rp)1 HashMap (java.util.HashMap)1 Parameters (org.testng.annotations.Parameters)1 Test (org.testng.annotations.Test)1