Skip to content
Snippets Groups Projects
Commit f0b95daa authored by Mirco Nasuti's avatar Mirco Nasuti
Browse files

big refactoring step 1

parent 29ea1f85
No related branches found
No related tags found
No related merge requests found
# Configuration for the portal running inside a Docker container for development
# Configuration for the portal running inside a Docker container
connection:
url: "jdbc:postgresql://portaldb:5432/postgres"
username: "postgres"
password: "test"
spring:
datasource:
url: jdbc:postgresql://portaldb:5432/postgres
username: postgres
password: test
driver-class-name: org.postgresql.Driver
jpa:
hibernate:
dialect: org.hibernate.dialect.PostgreSQL9Dialect
security:
enabled: false
......@@ -17,9 +22,6 @@ hbp:
tokenName: oauth_token
authenticationScheme: query
clientAuthenticationScheme: form
# use-current-uri: false # For both production and HBPS1 deployments
# pre-established-redirect-uri: https://mip.humanbrainproject.eu/services/login/hbp # For production deployment
# pre-established-redirect-uri: http://hbps1.chuv.ch/services/login/hbp # For HBPS1 deployment
resource:
userInfoUri: https://services.humanbrainproject.eu/oidc/userinfo
......@@ -45,3 +47,6 @@ workflow:
miningMipUrl: http://dockerhost:8087/mining
miningExaremeUrl: http://hbps2.chuv.ch:9090/mining/query
frontend:
redirect:
url: http://frontend/home
......@@ -17,59 +17,17 @@
<version>1.3.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<profiles>
<profile>
<id>prod</id>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<connection.driver_class>org.postgresql.Driver</connection.driver_class>
<connection.url>jdbc:postgresql://hbpmdw1.chuv.ch:31432/portal</connection.url>
<connection.username>portal</connection.username>
<connection.password>iaezXODVLb1e70I</connection.password>
<hibernate.dialect>org.hibernate.dialect.PostgreSQL82Dialect</hibernate.dialect>
<schema.deploy>false</schema.deploy>
<frontend.redirect>https://mip.humanbrainproject.eu/home</frontend.redirect>
<flyway.url>${connection.url}</flyway.url>
<flyway.user>${connection.username}</flyway.user>
<flyway.password>${connection.password}</flyway.password>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<connection.driver_class>org.postgresql.Driver</connection.driver_class>
<connection.url>jdbc:postgresql://portaldb:5432/postgres</connection.url>
<connection.username>postgres</connection.username>
<connection.password>test</connection.password>
<hibernate.dialect>org.hibernate.dialect.PostgreSQL82Dialect</hibernate.dialect>
<schema.deploy>false</schema.deploy>
<frontend.redirect>http://frontend/home</frontend.redirect>
<flyway.url>${connection.url}</flyway.url>
<flyway.user>${connection.username}</flyway.user>
<flyway.password>${connection.password}</flyway.password>
</properties>
</profile>
<profile>
<id>hbps1</id>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<connection.driver_class>org.postgresql.Driver</connection.driver_class>
<connection.url>jdbc:postgresql://portaldb:5432/postgres</connection.url>
<connection.username>postgres</connection.username>
<connection.password>test</connection.password>
<hibernate.dialect>org.hibernate.dialect.PostgreSQL82Dialect</hibernate.dialect>
<schema.deploy>false</schema.deploy>
<frontend.redirect>http://hbps1.chuv.ch/home</frontend.redirect>
<flyway.url>${connection.url}</flyway.url>
<flyway.user>${connection.username}</flyway.user>
<flyway.password>${connection.password}</flyway.password>
</properties>
</profile>
</profiles>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<asciidoctor.maven.plugin.version>1.5.3</asciidoctor.maven.plugin.version>
<asciidoctorj.pdf.version>1.5.0-alpha.11</asciidoctorj.pdf.version>
<asciidoctorj.version>1.5.4</asciidoctorj.version>
<sonar.host.url>http://dockerhost:9000</sonar.host.url>
<sonar.projectName>MIP Backend</sonar.projectName>
<sonar.sources>src/main/java/</sonar.sources>
</properties>
<dependencies>
<dependency>
......@@ -176,14 +134,7 @@
</pluginRepository>
</pluginRepositories>
<properties>
<asciidoctor.maven.plugin.version>1.5.3</asciidoctor.maven.plugin.version>
<asciidoctorj.pdf.version>1.5.0-alpha.11</asciidoctorj.pdf.version>
<asciidoctorj.version>1.5.4</asciidoctorj.version>
<sonar.host.url>http://dockerhost:9000</sonar.host.url>
<sonar.projectName>MIP Backend</sonar.projectName>
<sonar.sources>src/main/java/</sonar.sources>
</properties>
<build>
<resources>
......
......@@ -18,11 +18,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties;
import org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
......@@ -31,6 +31,7 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
import org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter;
import org.springframework.security.oauth2.client.filter.OAuth2ClientContextFilter;
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails;
......@@ -39,6 +40,7 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.E
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.web.access.channel.ChannelProcessingFilter;
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
import org.springframework.security.web.csrf.CsrfFilter;
import org.springframework.security.web.csrf.CsrfToken;
......@@ -71,7 +73,6 @@ import java.security.Principal;
@SpringBootApplication
@Configuration
@ImportResource("classpath:spring/application-context.xml")
@RestController
@EnableOAuth2Client
@EnableSwagger2
......@@ -83,12 +84,6 @@ public class MIPApplication extends WebSecurityConfigurerAdapter {
@Autowired
OAuth2ClientContext oauth2ClientContext;
@Autowired
HttpSessionCsrfTokenRepository httpSessionCsrfTokenRepository;
@Autowired
OAuth2ClientAuthenticationProcessingFilter hbpFilter;
public static void main(String[] args) {
SpringApplication.run(MIPApplication.class, args);
......@@ -216,7 +211,16 @@ public class MIPApplication extends WebSecurityConfigurerAdapter {
.and().logout().logoutUrl("/logout").permitAll()
.and().csrf().ignoringAntMatchers("/logout").csrfTokenRepository(csrfTokenRepository())
.and().addFilterAfter(csrfHeaderFilter(), CsrfFilter.class)
.addFilterBefore(hbpFilter, BasicAuthenticationFilter.class);
.addFilterBefore(ssoFilter(), BasicAuthenticationFilter.class);
}
private Filter ssoFilter() {
OAuth2ClientAuthenticationProcessingFilter hbpFilter = new OAuth2ClientAuthenticationProcessingFilter("/login/hbp");
OAuth2RestTemplate hbpTemplate = new OAuth2RestTemplate(hbp(), oauth2ClientContext);
hbpFilter.setAuthenticationSuccessHandler(new SimpleUrlAuthenticationSuccessHandler("http://frontend/#/home"));
hbpFilter.setRestTemplate(hbpTemplate);
hbpFilter.setTokenServices(new UserInfoTokenServices(hbpResource().getUserInfoUri(), hbp().getClientId()));
return hbpFilter;
}
@Bean
......@@ -261,7 +265,9 @@ public class MIPApplication extends WebSecurityConfigurerAdapter {
}
private CsrfTokenRepository csrfTokenRepository() {
return httpSessionCsrfTokenRepository;
HttpSessionCsrfTokenRepository repository = new HttpSessionCsrfTokenRepository();
repository.setHeaderName("X-XSRF-TOKEN");
return repository;
}
}
......
......@@ -5,18 +5,6 @@
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">${connection.driver_class}</property>
<property name="connection.url">${connection.url}</property>
<property name="connection.username">${connection.username}</property>
<property name="connection.password">${connection.password}</property>
<property name="hibernate.format_sql">true</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect">${hibernate.dialect}</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping class="org.hbp.mip.model.Article"/>
<mapping class="org.hbp.mip.model.Dataset"/>
<mapping class="org.hbp.mip.model.Model"/>
......@@ -31,6 +19,5 @@
<mapping class="org.hbp.mip.model.Config"/>
<mapping class="org.hbp.mip.model.App"/>
<mapping class="org.hbp.mip.model.Vote"/>
</session-factory>
</hibernate-configuration>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<context:component-scan base-package="org.hbp.mip" />
<bean id="httpSessionCsrfTokenRepository" class="org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository">
<property name="headerName" value="X-XSRF-TOKEN" />
</bean>
<bean id="hbpFilter" class="org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter">
<constructor-arg value="/login/hbp"></constructor-arg>
<property name="authenticationSuccessHandler">
<bean class="org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler">
<property name="defaultTargetUrl" value="${frontend.redirect}" />
</bean>
</property>
<property name="restTemplate">
<bean class="org.springframework.security.oauth2.client.OAuth2RestTemplate">
<constructor-arg name="resource" ref="hbp" />
<constructor-arg name="context" ref="oauth2ClientContext" />
</bean>
</property>
<property name="tokenServices">
<bean class="org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices">
<constructor-arg name="clientId" value="996f97c5-a3ca-460e-b18b-00df3e2be89a" />
<constructor-arg name="userInfoEndpointUrl" value="https://services.humanbrainproject.eu/oidc/userinfo" />
</bean>
</property>
</bean>
</beans>
......@@ -22,6 +22,6 @@ import org.springframework.test.context.web.WebAppConfiguration;
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@SpringApplicationConfiguration(classes=MIPApplication.class, locations={"classpath:spring/application-context.xml"})
@SpringApplicationConfiguration(classes=MIPApplication.class)
public class MIPApplicationTests {
}
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