diff --git a/rest/src/main/java/cz/incad/kramerius/rest/apiNew/client/v70/ClientKeycloakConfig.java b/rest/src/main/java/cz/incad/kramerius/rest/apiNew/client/v70/ClientKeycloakConfig.java index b3c741044..d02570135 100644 --- a/rest/src/main/java/cz/incad/kramerius/rest/apiNew/client/v70/ClientKeycloakConfig.java +++ b/rest/src/main/java/cz/incad/kramerius/rest/apiNew/client/v70/ClientKeycloakConfig.java @@ -3,6 +3,7 @@ import org.json.JSONObject; import cz.incad.kramerius.utils.StringUtils; +import cz.incad.kramerius.utils.conf.KConfiguration; public class ClientKeycloakConfig { @@ -36,7 +37,12 @@ public String getSecret() { return secret; } - public String loginKeycloak(String redirectUrl) { + public String loginKeycloak(String redirectUrl, String type) { + + if (type == null || !StringUtils.isAnyString(type)) { + type = KConfiguration.getInstance().getConfiguration().getString("default.eduid.type","all");; + } + StringBuilder builder = new StringBuilder(); builder.append(this.authServer); if (!builder.toString().endsWith("/")) builder.append("/"); @@ -47,6 +53,11 @@ public String loginKeycloak(String redirectUrl) { builder.append("&redirect_uri="+redirectUrl); } builder.append("&response_type=code"); + + if (type!= null) { + builder.append("#"+type); + } + return builder.toString(); } diff --git a/rest/src/main/java/cz/incad/kramerius/rest/apiNew/client/v70/ClientUserResource.java b/rest/src/main/java/cz/incad/kramerius/rest/apiNew/client/v70/ClientUserResource.java index 785d3f3fa..d6a4e6944 100644 --- a/rest/src/main/java/cz/incad/kramerius/rest/apiNew/client/v70/ClientUserResource.java +++ b/rest/src/main/java/cz/incad/kramerius/rest/apiNew/client/v70/ClientUserResource.java @@ -371,12 +371,13 @@ public Response changePassword(JSONObject rawdata) { @GET @Path("auth/login") - public Response login(@QueryParam("redirect_uri") String redirectUri) { + + public Response login(@QueryParam("redirect_uri") String redirectUri, @QueryParam("type") String type) { try { String path = WORKING_DIR + "/keycloak.json"; String str = IOUtils.toString(new FileInputStream(path),"UTF-8"); ClientKeycloakConfig cnf = ClientKeycloakConfig.load(new JSONObject(str)); - URI uri = URI.create(cnf.loginKeycloak(redirectUri)); + URI uri = URI.create(cnf.loginKeycloak(redirectUri, type)); return Response.temporaryRedirect(uri).build(); } catch (IOException e) { throw new GenericApplicationException(e.getMessage()); diff --git a/rest/src/test/java/cz/incad/kramerius/rest/apiNew/client/v70/ClientKeycloakConfigTest.java b/rest/src/test/java/cz/incad/kramerius/rest/apiNew/client/v70/ClientKeycloakConfigTest.java index 9650895b2..b87f9b166 100644 --- a/rest/src/test/java/cz/incad/kramerius/rest/apiNew/client/v70/ClientKeycloakConfigTest.java +++ b/rest/src/test/java/cz/incad/kramerius/rest/apiNew/client/v70/ClientKeycloakConfigTest.java @@ -4,6 +4,8 @@ import org.junit.Assert; import org.junit.Test; +import cz.incad.kramerius.utils.conf.KConfiguration; + public class ClientKeycloakConfigTest { @@ -28,9 +30,18 @@ public void testConfig() { Assert.assertTrue(config.getRealm().equals("kramerius")); Assert.assertTrue(config.getResource().equals("krameriusClient")); Assert.assertTrue(config.getSecret().equals("XXXXXXXXXXXX")); + + KConfiguration.getInstance().getConfiguration().setProperty("default.eduid.type","idp"); - String url = config.loginKeycloak("http://localhost:4200/keycloak"); - Assert.assertEquals("https://k7.inovatika.dev/auth/realms/kramerius/protocol/openid-connect/auth?client_id=krameriusClient&redirect_uri=http://localhost:4200/keycloak&response_type=code", url); + String url = config.loginKeycloak("http://localhost:4200/keycloak",null); + Assert.assertEquals("https://k7.inovatika.dev/auth/realms/kramerius/protocol/openid-connect/auth?client_id=krameriusClient&redirect_uri=http://localhost:4200/keycloak&response_type=code#idp", url); + + String urlIdp = config.loginKeycloak("http://localhost:4200/keycloak","idp"); + Assert.assertEquals("https://k7.inovatika.dev/auth/realms/kramerius/protocol/openid-connect/auth?client_id=krameriusClient&redirect_uri=http://localhost:4200/keycloak&response_type=code#idp", urlIdp); + + String urlForm = config.loginKeycloak("http://localhost:4200/keycloak","form"); + Assert.assertEquals("https://k7.inovatika.dev/auth/realms/kramerius/protocol/openid-connect/auth?client_id=krameriusClient&redirect_uri=http://localhost:4200/keycloak&response_type=code#form", urlForm); + } }