diff --git a/.gitignore b/.gitignore index e663c16b8..76bc01fc2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ target *~ bin *.idea +*node_modules *.iml *.eml .project diff --git a/perun-oidc-server-webapp/src/main/webapp/WEB-INF/tags/common/attributesConsent.tag b/perun-oidc-server-webapp/src/main/webapp/WEB-INF/tags/common/attributesConsent.tag index 77def45f2..a00db575a 100644 --- a/perun-oidc-server-webapp/src/main/webapp/WEB-INF/tags/common/attributesConsent.tag +++ b/perun-oidc-server-webapp/src/main/webapp/WEB-INF/tags/common/attributesConsent.tag @@ -51,15 +51,7 @@ - - -
  • <%= Ga4ghPassportAndVisaClaimSource.parseAndVerifyVisa( - (String) jspContext.findAttribute("subValue")).getPrettyString() %>
  • -
    - -
  • ${subValue}
  • -
    -
    +
  • ${subValue}
  • diff --git a/perun-oidc-server-webapp/src/main/webapp/WEB-INF/views/lsaai/approve.jsp b/perun-oidc-server-webapp/src/main/webapp/WEB-INF/views/lsaai/approve.jsp index 317e4f7b7..c686d7fdd 100644 --- a/perun-oidc-server-webapp/src/main/webapp/WEB-INF/views/lsaai/approve.jsp +++ b/perun-oidc-server-webapp/src/main/webapp/WEB-INF/views/lsaai/approve.jsp @@ -70,15 +70,7 @@
    - - - <%= Ga4ghPassportAndVisaClaimSource.parseAndVerifyVisa( - (String) pageContext.findAttribute("subValue")).getPrettyString() %> - - - ${subValue} - - + ${subValue}
    diff --git a/perun-oidc-server-webapp/src/main/webapp/WEB-INF/views/lsaai/approveDevice.jsp b/perun-oidc-server-webapp/src/main/webapp/WEB-INF/views/lsaai/approveDevice.jsp index 92ab6c48f..f6762cd97 100644 --- a/perun-oidc-server-webapp/src/main/webapp/WEB-INF/views/lsaai/approveDevice.jsp +++ b/perun-oidc-server-webapp/src/main/webapp/WEB-INF/views/lsaai/approveDevice.jsp @@ -71,15 +71,7 @@
    - - - <%= Ga4ghPassportAndVisaClaimSource.parseAndVerifyVisa( - (String) pageContext.findAttribute("subValue")).getPrettyString() %> - - - ${subValue} - - + ${subValue}
    diff --git a/perun-oidc-server/src/main/java/cz/muni/ics/oidc/server/claims/sources/Ga4ghApiClaimSource.java b/perun-oidc-server/src/main/java/cz/muni/ics/oidc/server/claims/sources/Ga4ghApiClaimSource.java new file mode 100644 index 000000000..39b4c0f40 --- /dev/null +++ b/perun-oidc-server/src/main/java/cz/muni/ics/oidc/server/claims/sources/Ga4ghApiClaimSource.java @@ -0,0 +1,81 @@ +package cz.muni.ics.oidc.server.claims.sources; + + +import com.fasterxml.jackson.databind.JsonNode; +import cz.muni.ics.oidc.server.claims.ClaimSource; +import cz.muni.ics.oidc.server.claims.ClaimSourceInitContext; +import cz.muni.ics.oidc.server.claims.ClaimSourceProduceContext; +import cz.muni.ics.oidc.server.claims.ClaimUtils; +import lombok.extern.slf4j.Slf4j; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.HttpClient; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.client.HttpClientBuilder; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +import java.util.Collections; +import java.util.Set; + +@Slf4j +public class Ga4ghApiClaimSource extends ClaimSource { + + private static final String ENDPOINT = "endpoint"; + private static final String USERNAME = "username"; + private static final String PASSWORD = "password"; + private static final String PARAM_NAME = "param_name"; + private static final String EPPN = "{eppn}"; + + private final String endpoint; + private final String username; + private final String password; + private final String paramName; + + public Ga4ghApiClaimSource(ClaimSourceInitContext ctx) { + super(ctx); + + this.endpoint = ClaimUtils.fillStringMandatoryProperty(ENDPOINT, ctx, getClaimName()); + this.username = ClaimUtils.fillStringMandatoryProperty(USERNAME, ctx, getClaimName()); + this.password = ClaimUtils.fillStringMandatoryProperty(PASSWORD, ctx, getClaimName()); + + this.paramName = ClaimUtils.fillStringPropertyOrDefaultVal(PARAM_NAME, ctx, EPPN); + + log.debug("{} - initialized", getClaimName()); + } + + @Override + public Set getAttrIdentifiers() { + return Collections.emptySet(); + } + + @Override + public JsonNode produceValue(ClaimSourceProduceContext pctx) { + RestTemplate restTemplate = new RestTemplate(getClientHttpRequestFactory()); + JsonNode result = restTemplate.getForObject(endpoint, JsonNode.class, Collections.singletonMap(paramName, pctx.getSub())); + + log.debug("{} - user: {}, GA4GH passports: {}", getClaimName(), pctx.getSub(), result); + + return result; + } + + private HttpComponentsClientHttpRequestFactory getClientHttpRequestFactory() + { + HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(); + clientHttpRequestFactory.setHttpClient(httpClient()); + + return clientHttpRequestFactory; + } + + private HttpClient httpClient() + { + CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); + credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); + + return HttpClientBuilder + .create() + .setDefaultCredentialsProvider(credentialsProvider) + .build(); + } +}