Commit f812ac21 authored by Matija Obreza's avatar Matija Obreza
Browse files

Display artifact version information

- host.name must only contain host name (used for HZ cookie-domain)
parent 9e84a9a7
......@@ -19,7 +19,7 @@
<tomcat-jdbc-juli>8.5.13</tomcat-jdbc-juli>
<liquibase.version>3.5.3</liquibase.version>
<spring-security-jwt>1.0.8.RELEASE</spring-security-jwt>
<hazelcast.version>3.8.2-SNAPSHOT</hazelcast.version>
<hazelcast.version>3.8.1</hazelcast.version>
</properties>
<build>
......@@ -44,7 +44,8 @@
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<scanIntervalSeconds>0</scanIntervalSeconds>
<reload>manual</reload>
<webApp>
<baseResource implementation="org.eclipse.jetty.util.resource.ResourceCollection">
<resourcesAsCSV>src/main/webapp</resourcesAsCSV>
......@@ -82,6 +83,7 @@
<phase>validate</phase>
<goals>
<goal>create</goal>
<goal>create-timestamp</goal>
</goals>
</execution>
</executions>
......@@ -90,6 +92,9 @@
fail if there are any. -->
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<shortRevisionLength>8</shortRevisionLength>
<timestampFormat>{0,date,d MMMM yyyy}</timestampFormat>
<timestampPropertyName>buildDate</timestampPropertyName>
</configuration>
</plugin>
</plugins>
......
/*
* Copyright 2017 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys.catalog.server.components;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
@Component
public class AddStuffInterceptor implements HandlerInterceptor, InitializingBean {
@Value("${build.name}")
private String buildName;
@Value("${build.revision}")
private String buildRevision;
@Value("${cdn.servers}")
private String[] cdnServers;
@Value("${base.url}")
private String baseUrl;
@Value("${google.analytics.account}")
private String googleAnalyticsAccount;
public abstract interface RandomString {
/// Get a random CDN server
public String getNext();
/// Return all CDN servers in a JS array
public String getServerList();
}
private RandomString randomCdnServer;
@Override
public void afterPropertiesSet() throws Exception {
googleAnalyticsAccount = StringUtils.defaultIfBlank(googleAnalyticsAccount, null);
final String allCdnJs = new ObjectMapper().writeValueAsString(cdnServers);
randomCdnServer = new RandomString() {
@Override
public String getNext() {
return cdnServers[0];
}
@Override
public String getServerList() {
return allCdnJs;
}
};
}
@Override
public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3) throws Exception {
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object arg2, ModelAndView modelAndView) throws Exception {
final long startTime = (Long) request.getAttribute("springStartTime");
final long endTime = System.currentTimeMillis();
final long executeTime = endTime - startTime;
request.setAttribute("springExecuteTime", executeTime);
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
final long startTime = System.currentTimeMillis();
request.setAttribute("springStartTime", startTime);
request.setAttribute("buildName", buildName);
request.setAttribute("buildRevision", buildRevision);
request.setAttribute("cdnServers", randomCdnServer);
request.setAttribute("baseUrl", baseUrl);
if (googleAnalyticsAccount != null) {
request.setAttribute("googleAnalyticsAccount", googleAnalyticsAccount);
}
return true;
}
}
......@@ -17,13 +17,17 @@ package org.genesys.catalog.server.config;
import java.util.EnumSet;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterRegistration;
import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import javax.servlet.SessionTrackingMode;
import com.hazelcast.web.SessionListener;
import org.springframework.util.ClassUtils;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
......@@ -40,8 +44,11 @@ public class ApplicationInit extends AbstractDispatcherServletInitializer {
private static final long MAX_REQUEST_SIZE = MAX_FILE_SIZE * 2;
private static final int FILE_SIZE_THRESHOLD = 0;
/* (non-Javadoc)
* @see org.springframework.web.servlet.support.AbstractDispatcherServletInitializer#createServletApplicationContext()
/*
* (non-Javadoc)
* @see
* org.springframework.web.servlet.support.AbstractDispatcherServletInitializer#
* createServletApplicationContext()
*/
@Override
protected WebApplicationContext createServletApplicationContext() {
......@@ -50,37 +57,62 @@ public class ApplicationInit extends AbstractDispatcherServletInitializer {
return context;
}
/* (non-Javadoc)
* @see org.springframework.web.servlet.support.AbstractDispatcherServletInitializer#getServletMappings()
/*
* (non-Javadoc)
* @see
* org.springframework.web.servlet.support.AbstractDispatcherServletInitializer#
* getServletMappings()
*/
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
/* (non-Javadoc)
* @see org.springframework.web.context.AbstractContextLoaderInitializer#createRootApplicationContext()
/*
* (non-Javadoc)
* @see org.springframework.web.context.AbstractContextLoaderInitializer#
* createRootApplicationContext()
*/
@Override
protected WebApplicationContext createRootApplicationContext() {
return null;
}
/* (non-Javadoc)
* @see org.springframework.web.servlet.support.AbstractDispatcherServletInitializer#onStartup(javax.servlet.ServletContext)
/*
* (non-Javadoc)
* @see
* org.springframework.web.servlet.support.AbstractDispatcherServletInitializer#
* onStartup(javax.servlet.ServletContext)
*/
@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
servletContext.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE));
// Encoding filter configuration
final FilterRegistration.Dynamic encodingFilter = servletContext.addFilter("encodingFilter", CharacterEncodingFilter.class);
encodingFilter.setInitParameter("encoding", "UTF-8");
encodingFilter.setInitParameter("forceEncoding", "true");
encodingFilter.addMappingForUrlPatterns(null, false, "/*");
// Hazelcast web filter configuration goes first!
final FilterRegistration.Dynamic hazelcastWebFilter = servletContext.addFilter("hazelcastWebFilter", new DelegatingFilterProxy("hazelcastWebFilter"));
hazelcastWebFilter.setInitParameter("targetFilterLifecycle", "true");
hazelcastWebFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.REQUEST), false, "/*");
final DelegatingFilterProxy filter = new DelegatingFilterProxy("springSecurityFilterChain");
filter.setContextAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher");
servletContext.addFilter("springSecurityFilterChain", filter).addMappingForUrlPatterns(null, false, "/*");
// Hazelcast session listener
servletContext.addListener(new SessionListener());
}
/* (non-Javadoc)
* @see org.springframework.web.servlet.support.AbstractDispatcherServletInitializer#getServletFilters()
/*
* (non-Javadoc)
* @see
* org.springframework.web.servlet.support.AbstractDispatcherServletInitializer#
* getServletFilters()
*/
@Override
protected Filter[] getServletFilters() {
......@@ -89,8 +121,11 @@ public class ApplicationInit extends AbstractDispatcherServletInitializer {
return new Filter[] { characterEncodingFilter };
}
/* (non-Javadoc)
* @see org.springframework.web.servlet.support.AbstractDispatcherServletInitializer#customizeRegistration(javax.servlet.ServletRegistration.Dynamic)
/*
* (non-Javadoc)
* @see
* org.springframework.web.servlet.support.AbstractDispatcherServletInitializer#
* customizeRegistration(javax.servlet.ServletRegistration.Dynamic)
*/
@Override
protected void customizeRegistration(final ServletRegistration.Dynamic registration) {
......
......@@ -33,8 +33,8 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableSwagger2
public class SwaggerConfig {
@Value("${host.name}")
private String hostName;
@Value("${host.nameAndPort}")
private String hostAndPort;
/**
* Every Docket bean is picked up by the swagger-mvc framework - allowing for multiple swagger groups i.e. same code
......@@ -44,7 +44,7 @@ public class SwaggerConfig {
*/
@Bean
public Docket apiDocket() {
return new Docket(DocumentationType.SWAGGER_2).host(hostName).protocols(newHashSet("http", "https"))
return new Docket(DocumentationType.SWAGGER_2).host(hostAndPort).protocols(newHashSet("http", "https"))
// Paths
.select().paths(apiPaths()).build()
// General info
......@@ -80,7 +80,7 @@ public class SwaggerConfig {
@Bean
SecurityScheme oauthPassword() {
return new OAuthBuilder().name("oauth2").grantTypes(newArrayList(new ResourceOwnerPasswordCredentialsGrant("//" + hostName + "/oauth/token"))).scopes(newArrayList(scopes())).build();
return new OAuthBuilder().name("oauth2").grantTypes(newArrayList(new ResourceOwnerPasswordCredentialsGrant("//" + hostAndPort + "/oauth/token"))).scopes(newArrayList(scopes())).build();
}
@Bean
......@@ -96,9 +96,9 @@ public class SwaggerConfig {
List<GrantType> grantTypes() {
GrantType grantType = new AuthorizationCodeGrantBuilder()
// token request
.tokenRequestEndpoint(new TokenRequestEndpoint("//" + hostName + "/oauth/authorize", "client_id", "client_secreat"))
.tokenRequestEndpoint(new TokenRequestEndpoint("//" + hostAndPort + "/oauth/authorize", "client_id", "client_secreat"))
// token endpoint
.tokenEndpoint(new TokenEndpoint("//" + hostName + "/oauth/token", "foo"))
.tokenEndpoint(new TokenEndpoint("//" + hostAndPort + "/oauth/token", "foo"))
// do
.build();
return newArrayList(grantType);
......
......@@ -28,6 +28,8 @@ import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module;
import org.apache.commons.lang3.StringUtils;
import org.genesys.catalog.server.components.AddStuffInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
......@@ -65,6 +67,9 @@ import org.springframework.web.servlet.view.JstlView;
@ComponentScan({ "org.genesys.catalog.server" })
public class WebConfiguration extends WebMvcConfigurerAdapter {
@Autowired
private AddStuffInterceptor addStuffInterceptor;
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/html/**").addResourceLocations("/html/").setCacheControl(CacheControl.maxAge(42, TimeUnit.DAYS).cachePrivate());
......@@ -95,6 +100,9 @@ public class WebConfiguration extends WebMvcConfigurerAdapter {
final InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
resolver.setExposeContextBeansAsAttributes(true);
resolver.setRedirectHttp10Compatible(false);
resolver.setRequestContextAttribute("requestContext");
resolver.setViewClass(JstlView.class);
return resolver;
}
......@@ -150,6 +158,7 @@ public class WebConfiguration extends WebMvcConfigurerAdapter {
final LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
interceptor.setParamName("lang");
registry.addInterceptor(interceptor);
registry.addInterceptor(addStuffInterceptor);
}
@Bean(name = "messageSource")
......
......@@ -16,7 +16,7 @@ public class StartController {
private static final Logger LOG = LoggerFactory.getLogger(StartController.class);
@RequestMapping(value = "/", method = RequestMethod.GET)
public String loginForm() {
public String welcome() {
return "index";
}
}
# Host
host.name=localhost:8080
# Host name (and only the host name, no port)
host.name=localhost
# Override for proper deployments
host.nameAndPort=${host.name}:8080
base.cookie-domain=${host.name}
base.cookie-secure=false
base.cookie-http-only=true
base.url=//${host.nameAndPort}
cdn.servers=${base.url}
# Database connection
db.url=jdbc:mysql://localhost/catalog?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false&useSSL=false
......@@ -22,7 +30,7 @@ default.oauthclient.clientSecret=my-secret-client
#google properties
google.consumerKey=
google.consumerSecret=
google.analytics.account=
# Build information
build.version=${project.version}
......@@ -48,10 +56,9 @@ CLAMD_PORT=
access_token.validity_period=3600
#Hazelcast
Hazelcast instance name
hazelcast.instanceName=hz-genesyscatalog-instance1
# Hazelcast cluster configuration
hazelcast.name=hz-genesys-development
hazelcast.name=hz-catalog-development
hazelcast.password=hazelcastdevelopment
# Binding and public address
hazelcast.publicAddress=
......@@ -59,17 +66,6 @@ hazelcast.interfaces=
hazelcast.port=5701
hazelcast.members=
# AWS Autodetection
hazelcast.aws.access-key=
hazelcast.aws.secret-key=
hazelcast.aws.region=eu-west-1
hazelcast.aws.security-group=sg-hazelcast
base.cookie-domain=${host.name}
base.cookie-secure=false
base.cookie-http-only=true
# Cache configuration
cache.defaultCacheSize=2000
cache.eviction-policy=LRU
......
......@@ -9,3 +9,5 @@ oauth.scope.write=Modify data on your behalf
oauth.allow-access=Allow
oauth.deny-access=Deny
oauth.confirm-access=Grant selected permissions
page.rendertime=Processing this page took {0}ms.
\ No newline at end of file
......@@ -28,3 +28,6 @@ log4j.rootLogger=error, stdout
log4j.category.org.genesys=warn
log4j.category.org.genesys.catalog=info
log4j.category.org.genesys.catalog.server=info
#log4j.category.org.springframework.security=debug
#log4j.category.com.hazelcast=debug
......@@ -29,5 +29,11 @@
</li>
</ul>
</div>
<div>
<spring:message code="page.rendertime" arguments="${springExecuteTime}" />
<br /> <a target="_blank" href="<c:url value="https://gitlab.croptrust.org/genesys-pgr/catalog/genesys-catalog/commit/${buildRevision}" />"><c:out value="${buildName}" /></a>
- <%= java.net.InetAddress.getLocalHost().getHostName() %>
</div>
</body>
</html>
# Host
host.name=localhost:8080
# Host name (and only the host name, no port)
host.name=localhost
# Override for proper deployments
host.nameAndPort=${host.name}:8080
base.cookie-domain=${host.name}
base.cookie-secure=false
base.cookie-http-only=true
base.url=//${host.nameAndPort}
cdn.servers=${base.url}
# Database connection
db.url=jdbc:hsqldb:mem:test;sql.syntax_mys=true;sql.ignore_case=true
......@@ -36,7 +44,6 @@ s3.prefix=
CLAMD_HOSTNAME=
CLAMD_PORT=
access_token.validity_period=3600
#Hazelcast
......@@ -51,16 +58,6 @@ hazelcast.interfaces=
hazelcast.port=5701
hazelcast.members=
# AWS Autodetection
hazelcast.aws.access-key=
hazelcast.aws.secret-key=
hazelcast.aws.region=eu-west-1
hazelcast.aws.security-group=sg-hazelcast
base.cookie-domain=${host.name}
base.cookie-secure=false
base.cookie-http-only=true
# Cache configuration
cache.defaultCacheSize=2000
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment