diff --git a/pom.xml b/pom.xml index 7124889..4d8bd80 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ eu.dnetlib uoa-repository-manager-service 1.0.0-SNAPSHOT - jar + war @@ -230,6 +230,29 @@ 9.1-901.jdbc3 + + org.mitre + openid-connect-client + 1.3.0 + + + org.slf4j + jcl-over-slf4j + + + + + + org.springframework.session + spring-session-data-redis + 1.3.1.RELEASE + pom + + + biz.paluch.redis + lettuce + 3.5.0.Final + diff --git a/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApi.java b/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApi.java index e129b42..dd9c679 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApi.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApi.java @@ -3,7 +3,7 @@ package eu.dnetlib.repo.manager.service.controllers; import eu.dnetlib.repo.manager.shared.BrokerException; import eu.dnetlib.repo.manager.shared.Term; import eu.dnetlib.repo.manager.shared.broker.*; -import io.swagger.annotations.*; +import io.swagger.annotations.Api; import org.json.JSONException; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; diff --git a/src/main/java/eu/dnetlib/repo/manager/service/controllers/UserApi.java b/src/main/java/eu/dnetlib/repo/manager/service/controllers/UserApi.java new file mode 100644 index 0000000..8703514 --- /dev/null +++ b/src/main/java/eu/dnetlib/repo/manager/service/controllers/UserApi.java @@ -0,0 +1,21 @@ +package eu.dnetlib.repo.manager.service.controllers; + +import io.swagger.annotations.Api; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@RestController +@RequestMapping(value = "/user") +@Api(description = "User API", tags = {"user"}) +public interface UserApi { + + @RequestMapping(value = "/login" , method = RequestMethod.GET) + void login(HttpServletRequest req, + HttpServletResponse resp); + + +} diff --git a/src/main/java/eu/dnetlib/repo/manager/service/controllers/UserApiImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/controllers/UserApiImpl.java new file mode 100644 index 0000000..32def27 --- /dev/null +++ b/src/main/java/eu/dnetlib/repo/manager/service/controllers/UserApiImpl.java @@ -0,0 +1,25 @@ +package eu.dnetlib.repo.manager.service.controllers; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@Component +public class UserApiImpl implements UserApi { + + private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger + .getLogger(UserApiImpl.class); + + @Value("${oidc.issuer}") + private String oidc_issuer; + + @Override + public void login(HttpServletRequest req, + HttpServletResponse resp) { + LOGGER.debug(oidc_issuer); + resp.setStatus(HttpServletResponse.SC_FOUND); + resp.setHeader("Location", oidc_issuer); + } +} diff --git a/src/main/java/eu/dnetlib/repo/manager/service/utils/Config.java b/src/main/java/eu/dnetlib/repo/manager/service/utils/Config.java new file mode 100644 index 0000000..580db00 --- /dev/null +++ b/src/main/java/eu/dnetlib/repo/manager/service/utils/Config.java @@ -0,0 +1,54 @@ +package eu.dnetlib.repo.manager.service.utils; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; +import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; +import org.springframework.session.web.http.CookieSerializer; +import org.springframework.session.web.http.DefaultCookieSerializer; + +import javax.annotation.PostConstruct; +import java.util.logging.Logger; + +@Configuration +@EnableRedisHttpSession +@PropertySource(value = { "classpath:eu/dnetlib/repo/manager/service/application.properties", "classpath:application.properties"} ) +@ComponentScan(basePackages = "eu.dnetlib.repo.manager") +public class Config { + + private static Logger LOGGER = Logger.getLogger(String.valueOf(Config.class)); + + @Value("${redis.host}") + private String host; + + @Value("${redis.port:6379}") + private String port; + + @Value("${redis.password:#{null}}") + private String password; + + @PostConstruct + private void init(){ + LOGGER.info(host); + } + + @Bean + public LettuceConnectionFactory connectionFactory() { + LOGGER.info(String.format("Redis connection listens to %s:%s",host,port)); + LettuceConnectionFactory factory = new LettuceConnectionFactory(host,Integer.parseInt(port)); + if(password != null) factory.setPassword(password); + return factory; + } + + @Bean + public CookieSerializer cookieSerializer() { + DefaultCookieSerializer serializer = new DefaultCookieSerializer(); + serializer.setCookieName("SESSION"); // <1> + serializer.setCookiePath("/"); // <2> + return serializer; + } + +} diff --git a/src/main/java/eu/dnetlib/repo/manager/service/utils/FrontEndLinkURIAuthenticationSuccessHandler.java b/src/main/java/eu/dnetlib/repo/manager/service/utils/FrontEndLinkURIAuthenticationSuccessHandler.java new file mode 100644 index 0000000..4f9b64e --- /dev/null +++ b/src/main/java/eu/dnetlib/repo/manager/service/utils/FrontEndLinkURIAuthenticationSuccessHandler.java @@ -0,0 +1,36 @@ +package eu.dnetlib.repo.manager.service.utils; + +import org.mitre.openid.connect.model.OIDCAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.web.authentication.AuthenticationSuccessHandler; + +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class FrontEndLinkURIAuthenticationSuccessHandler implements AuthenticationSuccessHandler { + + private String frontEndURI; + + @Override + public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { + OIDCAuthenticationToken authOIDC = (OIDCAuthenticationToken) authentication; + Cookie sessionCookie = new Cookie("currentUser", authOIDC.getSub()); + int expireSec = -1; + sessionCookie.setMaxAge(expireSec); + sessionCookie.setPath("/"); + response.addCookie(sessionCookie); + response.sendRedirect(frontEndURI); + } + + public String getFrontEndURI() { + return frontEndURI; + } + + public void setFrontEndURI(String frontEndURI) { + this.frontEndURI = frontEndURI; + } +} + diff --git a/src/main/resources/application-context.xml b/src/main/resources/application-context.xml index 1fcbfbd..c5d0e89 100644 --- a/src/main/resources/application-context.xml +++ b/src/main/resources/application-context.xml @@ -1,13 +1,15 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:security="http://www.springframework.org/schema/security" + xmlns:util="http://www.springframework.org/schema/util" xmlns:task="http://www.springframework.org/schema/task" + xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" + xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd + http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd + + http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd" + default-autowire="byType"> @@ -80,4 +84,168 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + openid + + + + + + ${webapp.home} + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/eu/dnetlib/repo/manager/service/application.properties b/src/main/resources/eu/dnetlib/repo/manager/service/application.properties index 047ecbf..32f97c2 100644 --- a/src/main/resources/eu/dnetlib/repo/manager/service/application.properties +++ b/src/main/resources/eu/dnetlib/repo/manager/service/application.properties @@ -96,4 +96,14 @@ repomanager.db.password = dnetPwd services.repomanager.analyticsURL = http://analytics.openaire.eu/addsite.php? -topic_types.url = https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:topic_types.json \ No newline at end of file +topic_types.url = https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:topic_types.json + +oidc.issuer = https://aai.openminted.eu/oidc/ +oidc.id = 24e83176-1312-4ba3-bc0b-ffeebea1603e +oidc.secret = U_gLOupYu2trYIOwfxGgZkkZoOHG_zGfaViOUsXcZ7qVQuF1rcJeQYKIDX1TY3z27CIoHaqq9ht2rmAiUmBRYQ +webapp.home = http://localhost:8380/repomanager-service/openid_connect_login +webapp.front=http://localhost:8380/ + +redis.host = 83.212.101.85 +#redis.port = 6379 +#redis.password \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index fb104ea..1db6c6c 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -17,6 +17,14 @@ http://xmlns.jcp.org/xml/ns/javaee " log4jExposeWebAppRoot false + + springSecurityFilterChain + org.springframework.web.filter.DelegatingFilterProxy + + + springSecurityFilterChain + /* + org.springframework.web.util.Log4jConfigListener @@ -33,17 +41,37 @@ http://xmlns.jcp.org/xml/ns/javaee " - - spring - - org.springframework.web.servlet.DispatcherServlet - - 1 - + + CorsFilter + org.apache.catalina.filters.CorsFilter + + cors.allowed.origins + * + + + cors.allowed.headers + Content-Type,X-Requested-With,accept,authorization,Origin,Access-Control-Request-Method,Access-Control-Request-Headers + + + cors.allowed.methods + GET, POST, PUT, DELETE, OPTIONS, HEAD + + - - spring - / - + + CorsFilter + /* + + + + springSessionRepositoryFilter + org.springframework.web.filter.DelegatingFilterProxy + + + springSessionRepositoryFilter + /* + REQUEST + ERROR + \ No newline at end of file