1. Dockerize service for test pourposes

2. Change cookies for aai
3. Change log4j properties with console append for test purposes.
4. Update pom.xml with gson library
This commit is contained in:
Panagiotis Kanakakis 2018-06-13 12:21:28 +00:00
parent 9d487d0773
commit de19920f3d
5 changed files with 97 additions and 35 deletions

16
pom.xml
View File

@ -222,6 +222,11 @@
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
</dependency>
</dependencies>
@ -231,7 +236,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
@ -269,6 +274,8 @@
</executions>
</plugin>
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -321,6 +328,13 @@
</executions>
</plugin>-->
</plugins>
<finalName>uoa-repository-manager-service</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

View File

@ -49,8 +49,10 @@ public class Config {
@Bean
public CookieSerializer cookieSerializer() {
DefaultCookieSerializer serializer = new DefaultCookieSerializer();
serializer.setCookieName("SESSION"); // <1>
serializer.setCookiePath("/"); // <2>
serializer.setCookieName("openAIRESession");
serializer.setCookiePath("/");
// serializer.setDomainName(".openaire.eu");
serializer.setDomainName(".di.uoa.gr");
LOGGER.info("Serializer : " + serializer);
return serializer;
}

View File

@ -1,16 +1,18 @@
package eu.dnetlib.repo.manager.service.config;
import com.google.gson.JsonObject;
import org.apache.log4j.Logger;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import javax.annotation.PostConstruct;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import com.google.gson.*;
public class FrontEndLinkURIAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
@ -27,12 +29,47 @@ public class FrontEndLinkURIAuthenticationSuccessHandler implements Authenticati
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("/");
// sessionCookie.setDomain();
response.addCookie(sessionCookie);
JsonObject userInfo = new JsonObject();
if (authOIDC.getUserInfo().getSub() == null)
userInfo.addProperty("sub", "");
else
userInfo.addProperty("sub", URLEncoder.encode(authOIDC.getUserInfo().getSub(), "UTF-8"));
userInfo.addProperty("fullname", URLEncoder.encode(authOIDC.getUserInfo().getName(), "UTF-8"));
if (authOIDC.getUserInfo().getGivenName() == null)
userInfo.addProperty("firstname", "");
else
userInfo.addProperty("firstname", URLEncoder.encode(authOIDC.getUserInfo().getGivenName(), "UTF-8") + "");
if (authOIDC.getUserInfo().getFamilyName() == null)
userInfo.addProperty("lastname", "");
else
userInfo.addProperty("lastname", URLEncoder.encode(authOIDC.getUserInfo().getFamilyName(), "UTF-8") + "");
userInfo.addProperty("email", authOIDC.getUserInfo().getEmail() + "");
if (authOIDC.getUserInfo().getSource().getAsJsonArray("edu_person_entitlements") == null)
userInfo.addProperty("role", "");
else
userInfo.addProperty("role", URLEncoder.encode(authOIDC.getUserInfo()
.getSource().getAsJsonArray("edu_person_entitlements").toString(), "UTF-8") + "");
Gson gson = new GsonBuilder().create();
Cookie openAIREUser = new Cookie("openAIREUser", new Gson().toJson(userInfo) );
openAIREUser .setMaxAge(14400);
// openAIREUser .setDomain(".openaire.eu");
openAIREUser .setDomain(".di.uoa.gr");
response.addCookie(openAIREUser);
Cookie accessToken = new Cookie("AccessToken", authOIDC.getAccessTokenValue());
accessToken.setMaxAge(14400);
// accessToken.setDomain(".openaire.eu");
accessToken.setDomain(".di.uoa.gr");
response.addCookie(accessToken);
response.sendRedirect(frontEndURI);
}

View File

@ -73,7 +73,7 @@ public class EmailUtilsImpl implements EmailUtils {
"Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" +
"\n" +
"For more information about this request, go here: \n" +
this.baseUrl + "/#admin/metrics\n" +
this.baseUrl + "/admin/metrics\n" +
"\n" +
"Best,\n" +
"The OpenAIRE team";
@ -107,7 +107,7 @@ public class EmailUtilsImpl implements EmailUtils {
"the OpenAIRE team in repositoryusagestats@openaire.eu in order to find a solution.\n" +
"\n" +
"For more information about your request and configuration details, go here: \n" +
this.baseUrl + "/#getImpact/instructions/" + piwikInfo.getRepositoryId() + "\n" +
this.baseUrl + "/getImpact/instructions/" + piwikInfo.getRepositoryId() + "\n" +
"\n" +
"Once you have finished configuring your repository or if you have any questions, please notify the OpenAIRE team by sending \n" +
"an email to repositoryusagestats@openaire.eu\n" +
@ -142,7 +142,7 @@ public class EmailUtilsImpl implements EmailUtils {
"Best,\n" +
"The OpenAIRE team";
this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null);
this.sendMail(this.usageStatsAdminEmail, subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error while sending metrics enabled notification email to administator: " + this.usageStatsAdminEmail, e);
@ -162,7 +162,7 @@ public class EmailUtilsImpl implements EmailUtils {
"\" has been completed and validated and the usage statistics have been enabled in OpenAIRE.\n" +
"\n" +
"You can preview the statistics in your repository's dashboard: \n" +
this.baseUrl + "/#getImpact/" + piwikInfo.getRepositoryId() + "\n" +
this.baseUrl + "/getImpact/" + piwikInfo.getRepositoryId() + "\n" +
"\n" +
" For more information and questions, you can contact the openaire support team by sending an email to " +
"repositoryusagestats@openaire.eu\n" +

View File

@ -1,7 +1,32 @@
#log4j.rootLogger = WARN, R
#
#log4j.logger.eu.dnetlib = DEBUG
#log4j.logger.eu.dnetlib.clients.data.datasourcemanager.ws.Converter = FATAL
#log4j.logger.org.springframework = DEBUG, S
#log4j.additivity.org.springframework = false
#
#log4j.logger.com.opensymphony.xwork2.ognl.OgnlValueStack = FATAL
#log4j.logger.com.opensymphony.xwork2.ObjectFactory = FATAL
#
#log4j.logger.eu.dnetlib.repo.manager=DEBUG
#
#log4j.appender.R=org.apache.log4j.RollingFileAppender
#log4j.appender.R.File=/var/log/dnet/repository-service/repository-service.log
#log4j.appender.R.MaxFileSize=10MB
#log4j.appender.R.MaxBackupIndex=10
#log4j.appender.R.layout=org.apache.log4j.PatternLayout
#log4j.appender.R.layout.ConversionPattern= %d %p %t [%c] - %m%n
#
#log4j.appender.S=org.apache.log4j.RollingFileAppender
#log4j.appender.S.File=/var/log/dnet/repository-service/repository-service-spring.log
#log4j.appender.S.MaxFileSize=10MB
#log4j.appender.S.MaxBackupIndex=10
#log4j.appender.S.layout=org.apache.log4j.PatternLayout
#log4j.appender.S.layout.ConversionPattern= %d %p %t [%c] - %m%n
log4j.rootLogger = WARN, R
log4j.logger.eu.dnetlib = DEBUG
log4j.logger.eu.dnetlib.clients.data.datasourcemanager.ws.Converter = FATAL
log4j.logger.org.springframework = DEBUG, S
log4j.additivity.org.springframework = false
@ -10,26 +35,10 @@ log4j.logger.com.opensymphony.xwork2.ObjectFactory = FATAL
log4j.logger.eu.dnetlib.repo.manager=DEBUG
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=/var/log/dnet/repository-service/repository-service.log
log4j.appender.R.MaxFileSize=10MB
log4j.appender.R.MaxBackupIndex=10
log4j.appender.R=org.apache.log4j.ConsoleAppender
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern= %d %p %t [%c] - %m%n
log4j.appender.S=org.apache.log4j.RollingFileAppender
log4j.appender.S.File=/var/log/dnet/repository-service/repository-service-spring.log
log4j.appender.S.MaxFileSize=10MB
log4j.appender.S.MaxBackupIndex=10
log4j.appender.S=org.apache.log4j.ConsoleAppender
log4j.appender.S.layout=org.apache.log4j.PatternLayout
log4j.appender.S.layout.ConversionPattern= %d %p %t [%c] - %m%n
#org.apache.cxf.Logger=org.apache.cxf.common.logging.Log4jLogger
#
#log4j.rootLogger=INFO, CONSOLE
#log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
#log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
#log4j.appender.CONSOLE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
#
#log4j.logger.eu.dnetlib.repo.manager=DEBUG
log4j.appender.S.layout.ConversionPattern= %d %p %t [%c] - %m%n