Search in sources :

Example 1 with RpGetClaimsGatheringUrlResponse

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

the class UmaGetClaimsGatheringUrlTest method test.

@Parameters({ "host", "opHost", "paramRedirectUrl", "rsProtect" })
@Test
public void test(String host, String opHost, String paramRedirectUrl, String rsProtect) throws IOException {
    ClientInterface client = Tester.newClient(host);
    RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, paramRedirectUrl);
    RsProtectTest.protectResources(client, site, UmaFullTest.resourceList(rsProtect).getResources());
    final RsCheckAccessResponse checkAccess = RsCheckAccessTest.checkAccess(client, site, null);
    final RpGetClaimsGatheringUrlParams params = new RpGetClaimsGatheringUrlParams();
    params.setRpId(site.getRpId());
    params.setTicket(checkAccess.getTicket());
    params.setClaimsRedirectUri(paramRedirectUrl);
    final RpGetClaimsGatheringUrlResponse response = client.umaRpGetClaimsGatheringUrl(Tester.getAuthorization(site), null, params);
    Map<String, String> parameters = CoreUtils.splitQuery(response.getUrl());
    assertTrue(StringUtils.isNotBlank(parameters.get("client_id")));
    assertTrue(StringUtils.isNotBlank(parameters.get("ticket")));
    assertTrue(StringUtils.isNotBlank(parameters.get("state")));
    assertTrue(StringUtils.isNotBlank(response.getState()));
    assertEquals(paramRedirectUrl, parameters.get("claims_redirect_uri"));
}
Also used : RpGetClaimsGatheringUrlParams(io.jans.ca.common.params.RpGetClaimsGatheringUrlParams) RpGetClaimsGatheringUrlResponse(io.jans.ca.common.response.RpGetClaimsGatheringUrlResponse) RsCheckAccessResponse(io.jans.ca.common.response.RsCheckAccessResponse) ClientInterface(io.jans.ca.client.ClientInterface) RegisterSiteResponse(io.jans.ca.common.response.RegisterSiteResponse) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 2 with RpGetClaimsGatheringUrlResponse

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

the class UmaGetClaimsGatheringUrlTest method test_withState.

@Parameters({ "host", "opHost", "paramRedirectUrl", "rsProtect", "state" })
@Test
public void test_withState(String host, String opHost, String paramRedirectUrl, String rsProtect, String state) throws IOException {
    ClientInterface client = Tester.newClient(host);
    RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, paramRedirectUrl);
    RsProtectTest.protectResources(client, site, UmaFullTest.resourceList(rsProtect).getResources());
    final RsCheckAccessResponse checkAccess = RsCheckAccessTest.checkAccess(client, site, null);
    final RpGetClaimsGatheringUrlParams params = new RpGetClaimsGatheringUrlParams();
    params.setRpId(site.getRpId());
    params.setTicket(checkAccess.getTicket());
    params.setClaimsRedirectUri(paramRedirectUrl);
    params.setState(state);
    final RpGetClaimsGatheringUrlResponse response = client.umaRpGetClaimsGatheringUrl(Tester.getAuthorization(site), null, params);
    Map<String, String> parameters = CoreUtils.splitQuery(response.getUrl());
    assertTrue(StringUtils.isNotBlank(parameters.get("client_id")));
    assertTrue(StringUtils.isNotBlank(parameters.get("ticket")));
    assertTrue(StringUtils.isNotBlank(parameters.get("state")));
    assertTrue(StringUtils.isNotBlank(response.getState()));
    assertEquals(paramRedirectUrl, parameters.get("claims_redirect_uri"));
    assertEquals(response.getState(), state);
}
Also used : RpGetClaimsGatheringUrlParams(io.jans.ca.common.params.RpGetClaimsGatheringUrlParams) RpGetClaimsGatheringUrlResponse(io.jans.ca.common.response.RpGetClaimsGatheringUrlResponse) RsCheckAccessResponse(io.jans.ca.common.response.RsCheckAccessResponse) 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 RpGetClaimsGatheringUrlResponse

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

the class UmaGetClaimsGatheringUrlTest method test_withCustomParameter.

@Parameters({ "host", "opHost", "paramRedirectUrl", "rsProtect" })
@Test
public void test_withCustomParameter(String host, String opHost, String paramRedirectUrl, String rsProtect) throws IOException {
    ClientInterface client = Tester.newClient(host);
    RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, paramRedirectUrl);
    RsProtectTest.protectResources(client, site, UmaFullTest.resourceList(rsProtect).getResources());
    final RsCheckAccessResponse checkAccess = RsCheckAccessTest.checkAccess(client, site, null);
    final RpGetClaimsGatheringUrlParams params = new RpGetClaimsGatheringUrlParams();
    params.setRpId(site.getRpId());
    params.setTicket(checkAccess.getTicket());
    params.setClaimsRedirectUri(paramRedirectUrl);
    Map<String, String> customParameterMap = Maps.newHashMap();
    customParameterMap.put("param1", "value1");
    customParameterMap.put("param2", "value2");
    params.setCustomParameters(customParameterMap);
    final RpGetClaimsGatheringUrlResponse response = client.umaRpGetClaimsGatheringUrl(Tester.getAuthorization(site), null, params);
    Map<String, String> parameters = CoreUtils.splitQuery(response.getUrl());
    assertTrue(StringUtils.isNotBlank(parameters.get("client_id")));
    assertTrue(StringUtils.isNotBlank(parameters.get("ticket")));
    assertTrue(StringUtils.isNotBlank(parameters.get("state")));
    assertTrue(StringUtils.isNotBlank(response.getState()));
    assertTrue(StringUtils.isNotBlank(parameters.get("param1")));
    assertTrue(StringUtils.isNotBlank(parameters.get("param2")));
    assertEquals(paramRedirectUrl, parameters.get("claims_redirect_uri"));
}
Also used : RpGetClaimsGatheringUrlParams(io.jans.ca.common.params.RpGetClaimsGatheringUrlParams) RpGetClaimsGatheringUrlResponse(io.jans.ca.common.response.RpGetClaimsGatheringUrlResponse) RsCheckAccessResponse(io.jans.ca.common.response.RsCheckAccessResponse) ClientInterface(io.jans.ca.client.ClientInterface) RegisterSiteResponse(io.jans.ca.common.response.RegisterSiteResponse) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 4 with RpGetClaimsGatheringUrlResponse

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

the class RpGetGetClaimsGatheringUrlOperation method execute.

@Override
public IOpResponse execute(RpGetClaimsGatheringUrlParams params) throws Exception {
    validate(params);
    final UmaMetadata metadata = getDiscoveryService().getUmaDiscoveryByRpId(params.getRpId());
    final Rp rp = getRp();
    final String state = StringUtils.isNotBlank(params.getState()) ? getStateService().putState(getStateService().encodeExpiredObject(params.getState(), ExpiredObjectType.STATE)) : getStateService().generateState();
    String url = metadata.getClaimsInteractionEndpoint() + "?client_id=" + rp.getClientId() + "&ticket=" + params.getTicket() + "&claims_redirect_uri=" + params.getClaimsRedirectUri() + "&state=" + state;
    if (params.getCustomParameters() != null && !params.getCustomParameters().isEmpty()) {
        List<String> paramsList = Lists.newArrayList("rp_id", "client_id", "ticket", "state", "claims_redirect_uri");
        Map<String, String> customParameterMap = params.getCustomParameters().entrySet().stream().filter(map -> !paramsList.contains(map.getKey())).collect(Collectors.toMap(map -> map.getKey(), map -> map.getValue()));
        if (!customParameterMap.isEmpty()) {
            url += "&" + Utils.mapAsStringWithEncodedValues(customParameterMap);
        }
    }
    final RpGetClaimsGatheringUrlResponse r = new RpGetClaimsGatheringUrlResponse();
    r.setUrl(url);
    r.setState(state);
    return r;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Utils(io.jans.ca.server.Utils) Collectors(java.util.stream.Collectors) Injector(com.google.inject.Injector) HttpException(io.jans.ca.server.HttpException) UmaMetadata(io.jans.as.model.uma.UmaMetadata) RpGetClaimsGatheringUrlParams(io.jans.ca.common.params.RpGetClaimsGatheringUrlParams) ErrorResponseCode(io.jans.ca.common.ErrorResponseCode) IOpResponse(io.jans.ca.common.response.IOpResponse) List(java.util.List) Lists(com.google.common.collect.Lists) ExpiredObjectType(io.jans.ca.common.ExpiredObjectType) Map(java.util.Map) RpGetClaimsGatheringUrlResponse(io.jans.ca.common.response.RpGetClaimsGatheringUrlResponse) Command(io.jans.ca.common.Command) Rp(io.jans.ca.server.service.Rp) UmaMetadata(io.jans.as.model.uma.UmaMetadata) RpGetClaimsGatheringUrlResponse(io.jans.ca.common.response.RpGetClaimsGatheringUrlResponse) Rp(io.jans.ca.server.service.Rp)

Aggregations

RpGetClaimsGatheringUrlParams (io.jans.ca.common.params.RpGetClaimsGatheringUrlParams)4 RpGetClaimsGatheringUrlResponse (io.jans.ca.common.response.RpGetClaimsGatheringUrlResponse)4 ClientInterface (io.jans.ca.client.ClientInterface)3 RegisterSiteResponse (io.jans.ca.common.response.RegisterSiteResponse)3 RsCheckAccessResponse (io.jans.ca.common.response.RsCheckAccessResponse)3 Parameters (org.testng.annotations.Parameters)3 Test (org.testng.annotations.Test)3 Lists (com.google.common.collect.Lists)1 Injector (com.google.inject.Injector)1 UmaMetadata (io.jans.as.model.uma.UmaMetadata)1 Command (io.jans.ca.common.Command)1 ErrorResponseCode (io.jans.ca.common.ErrorResponseCode)1 ExpiredObjectType (io.jans.ca.common.ExpiredObjectType)1 IOpResponse (io.jans.ca.common.response.IOpResponse)1 HttpException (io.jans.ca.server.HttpException)1 Utils (io.jans.ca.server.Utils)1 Rp (io.jans.ca.server.service.Rp)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1