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