Skip to content

Commit

Permalink
feat: integrate user console + fix request handling for application
Browse files Browse the repository at this point in the history
  • Loading branch information
matteo-s committed Mar 18, 2024
1 parent 4045849 commit 1ccbe0f
Show file tree
Hide file tree
Showing 18 changed files with 469 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "frontend/console"]
path = frontend/console
url = https://github.com/scc-digitalhub/digitalhub-console.git
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
"mainClass": "it.smartcommunitylabdhub.core.CoreApplication",
"projectName": "core",
"vmArgs": "-Dspring.profiles.active=local",
},
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
10 changes: 10 additions & 0 deletions application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
Expand Down Expand Up @@ -237,6 +241,12 @@
<artifactId>dh-runtime-mlrun</artifactId>
<version>${revision}</version>
</dependency>

<dependency>
<groupId>it.smartcommunitylabdhub</groupId>
<artifactId>dh-console</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

import it.smartcommunitylabdhub.core.config.handlers.VersionedHandlerMapping;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

@Configuration
public class ApiVersioningMappingConfig implements WebMvcRegistrations {
public class ApiVersioningMappingConfig {

@Override
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
return new VersionedHandlerMapping();
@Bean
public WebMvcRegistrations webMvcRegistrationsHandlerMapping() {
return new WebMvcRegistrations() {
@Override
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
return new VersionedHandlerMapping();
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.springframework.security.config.Customizer.withDefaults;

import it.smartcommunitylabdhub.commons.config.SecurityProperties;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down

This file was deleted.

5 changes: 4 additions & 1 deletion application/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ security:
password: ${DH_AUTH_BASIC_PASSWORD:}
jwt:
issuer-uri: ${DH_AUTH_JWT_ISSUER_URI:}
audience: ${DH_AUTH_JWT_AUDIENCE:dhcore}
audience: ${DH_AUTH_JWT_AUDIENCE:${security.oidc.client-id}}
claim: ${DH_AUTH_JWT_CLAIM:roles}
oidc:
client-id: ${DH_AUTH_OIDC_CLIENT_ID:}
scope:



Expand Down
53 changes: 53 additions & 0 deletions frontend/.flattened-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>it.smartcommunitylabdhub</groupId>
<artifactId>dh-console</artifactId>
<version>0.0.29</version>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>3.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>3.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>3.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>3.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>it.smartcommunitylabdhub</groupId>
<artifactId>dh-commons</artifactId>
<version>0.0.29</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-common</artifactId>
<version>2.2.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
1 change: 1 addition & 0 deletions frontend/console
Submodule console added at b96889
136 changes: 136 additions & 0 deletions frontend/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>it.smartcommunitylabdhub</groupId>
<artifactId>digitalhub-core</artifactId>
<version>${revision}</version>
<relativePath>../</relativePath> <!-- lookup parent from repository -->
</parent>
<groupId>it.smartcommunitylabdhub</groupId>
<artifactId>dh-console</artifactId>
<name>console</name>
<description>DHCore console</description>

<properties>
<yarn.version>v1.22.19</yarn.version>
<node.version>v18.17.1</node.version>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>${spring-boot.version}</version>
</dependency>

<dependency>
<groupId>it.smartcommunitylabdhub</groupId>
<artifactId>dh-commons</artifactId>
<version>${revision}</version>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-common</artifactId>
<version>${springdoc.version}</version>
</dependency>


</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.15.0</version>

<configuration>
<nodeVersion>${node.version}</nodeVersion>
<yarnVersion>${yarn.version}</yarnVersion>
<installDirectory>${project.build.directory}</installDirectory>
</configuration>
<executions>

<execution>
<id>install-node-and-yarn</id>
<goals>
<goal>install-node-and-yarn</goal>
</goals>
</execution>

<execution>
<id>frontent-yarn-install</id>
<goals>
<goal>yarn</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>install</arguments>
<workingDirectory>${project.basedir}/console</workingDirectory>
</configuration>
</execution>

<execution>
<id>frontend build</id>
<goals>
<goal>yarn</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<arguments>build:production</arguments>
<workingDirectory>${project.basedir}/console</workingDirectory>
</configuration>
</execution>

</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>frontend package</id>
<goals>
<goal>copy-resources</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<outputDirectory>${project.build.outputDirectory}/console</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/console/dist</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package it.smartcommunitylabdhub.console;

public class Keys {

public static final String CONSOLE_CONTEXT = "/console";

private Keys() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package it.smartcommunitylabdhub.console.config;

import it.smartcommunitylabdhub.commons.config.SecurityProperties;
import it.smartcommunitylabdhub.console.Keys;
import java.util.ArrayList;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.security.web.util.matcher.RequestMatcher;
import org.springframework.util.StringUtils;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

@Configuration
public class ConsoleSecurityConfig {

@Autowired
SecurityProperties properties;

@Value("${security.api.cors.origins}")
private String corsOrigins;

public RequestMatcher getRequestMatcher() {
return new AntPathRequestMatcher(Keys.CONSOLE_CONTEXT + "/**");
}

@Bean("consoleSecurityFilterChain")
public SecurityFilterChain apiSecurityFilterChain(HttpSecurity http) throws Exception {
http
.securityMatcher(getRequestMatcher())
.authorizeHttpRequests(auth -> {
auth.anyRequest().permitAll();
})
//disable csrf
.csrf(csrf -> csrf.disable())
// we don't want a session for these endpoints, each request should be evaluated
.sessionManagement(management -> management.sessionCreationPolicy(SessionCreationPolicy.STATELESS));

// allow cors
http.cors(cors -> {
if (StringUtils.hasText(corsOrigins)) {
cors.configurationSource(corsConfigurationSource(corsOrigins));
} else {
cors.disable();
}
});

return http.build();
}

private CorsConfigurationSource corsConfigurationSource(String origins) {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOriginPatterns(new ArrayList<>(StringUtils.commaDelimitedListToSet(origins)));
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "PATCH"));
configuration.setAllowedHeaders(Arrays.asList("*"));
configuration.setExposedHeaders(Arrays.asList("authorization", "range"));
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
}
Loading

0 comments on commit 1ccbe0f

Please sign in to comment.