Skip to content

Commit cb13b7d

Browse files
authored
Merge pull request #19 from PatternAtlas/ba-meyer-master
BA Meyer final commit
2 parents b66669c + 74909cb commit cb13b7d

File tree

124 files changed

+4070
-956
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+4070
-956
lines changed

.docker/application.properties.tpl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ spring.jpa.properties.hibernate.show_sql=true
1515
spring.jpa.properties.hibernate.format_sql=true
1616
spring.jpa.properties.hibernate.use_sql_comments=true
1717
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
18-
spring.liquibase.enabled={{default .Env.PATTERN_ATLAS_FETCH_INITIAL_DATA "false"}}
18+
spring.liquibase.enabled=true
19+
spring.liquibase.change-log=file:patternatlas.xml
1920
spring.liquibase.password={{.Env.DB_INIT_PASSWORD}}
2021
spring.liquibase.user={{.Env.DB_INIT_USER}}
21-
spring.liquibase.url=jdbc:postgresql://{{.Env.JDBC_DATABASE_URL}}:{{.Env.JDBC_DATABASE_PORT}}/{{.Env.JDBC_DATABASE_NAME}}
22+
spring.liquibase.url=jdbc:postgresql://{{.Env.JDBC_DATABASE_URL}}:{{.Env.JDBC_DATABASE_PORT}}/{{.Env.JDBC_DATABASE_NAME}}
23+
security.oauth2.resource.jwk.key-set-uri={{.Env.JWK_URI}}

.docker/docker-compose.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: '3'
2+
services:
3+
db:
4+
image: postgres:10
5+
environment:
6+
POSTGRES_USER: postgres
7+
POSTGRES_PASSWORD: postgres
8+
POSTGRES_DB: postgres
9+
ports:
10+
- "5432:5432"
11+
networks:
12+
- default
13+
networks:
14+
default:
15+
driver: bridge

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
HELP.md
23
target/
34
!.mvn/wrapper/maven-wrapper.jar
@@ -30,10 +31,13 @@ build/
3031
### VS Code ###
3132
.vscode/
3233

34+
### MacOS File System ###
35+
**/.DS_STORE
36+
3337
### TexRendering ###
3438
*.png
3539
*.tex
3640
*.pdf
3741
*.log
3842
*.aux
39-
*.svg
43+
*.svg

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ ENV JDBC_DATABASE_NAME postgres
3636
ENV JDBC_DATABASE_PORT 5060
3737
ENV HAL_EXPLORER true
3838

39+
ENV JWK_URI "http://localhost:8080/realms/patternatlas/protocol/openid-connect/certs"
40+
3941
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
4042
&& tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
4143
&& rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz

docs/dev/index.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# PatternAtlas Developer Guide
2-
This document provides an index to all development guidelines and background information of the PatternPedia.
2+
This document provides an index to all development guidelines and background information of the PatternAtlas.
33
- [ADR](/adr) - Information on Architectural decisions can be found here
44

55
## Quick Develop
6-
<!---
76
### PatternPediaAuth
7+
PatternPediaAuth is a Spring Boot Authentication Server and it's main purpose is to give PatternAtlasAPI user management capabilities.
8+
This is achieved through using the OAuth 2.0 Authentication Code Flow, additionally new users can create accounts.
9+
It runs on Port 8081
10+
11+
### Development
812
1. Clone the repository `git clone https://github.com/PatternAtlas/pattern-pedia-auth.git`.
913
2. Navigate to repository directory `cd pattern-pedia-auth/`.
1014
2. Build the repository
@@ -22,8 +26,12 @@ This document provides an index to all development guidelines and background inf
2226
5. Insert the following commands `docker-compose up -d`
2327

2428
#### IntelliJ
25-
3. [Follow PatternPediaAPI from Step 5 pls](#step5)
29+
3. [Follow PatternAtlasAPI from Step 5 pls](#step5)
2630

31+
#### Turn authentication on/off for PatternAtlasAPI
32+
If you don't need the capabilities of the PatternPediaAuth server during development. You can follow the instructions in the following file
33+
[Security Config file](https://github.com/PatternAtlas/pattern-atlas-api/blob/ba-meyer-master/src/main/java/io/github/patternatlas/api/config/ResourceServerConfig.java)
34+
to turn those off or on. An easier way will be added in a future realease.
2735

2836
#### Default User
2937
During development default users are
@@ -32,9 +40,9 @@ During development default users are
3240

3341
### PatternAtlasAPI
3442
--->
35-
1. Clone the repository `git clone https://github.com/PatternPedia/pattern-atlas-api.git`.
43+
1. Clone the repository `git clone https://github.com/PatternAtlas/pattern-atlas-api.git`.
3644
2. Build the repository `mvn package -DskipTests` (skiping the tests for a faster build), Java 8 required.
37-
3. Clone the repository `git clone https://github.com/PatternPedia/pattern-atlas-ui.git`.
45+
3. Clone the repository `git clone https://github.com/PatternAtlas/pattern-atlas-ui.git`.
3846
4. Build the repository `mvn package -DskipTests` (skiping the tests for a faster build), npm is required. (plus yarn, optionally)
3947
5. <a name="step5"></a>Continue your IDE setup:
4048
- [IntelliJ Ultimate](IntelliJ/)

pom.xml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<java.version>1.8</java.version>
1818
<springdoc-ui.version>1.5.9</springdoc-ui.version>
1919
<spring-oauth2.version>2.5.0</spring-oauth2.version>
20+
<jackson.version>2.13.2</jackson.version>
2021
</properties>
2122

2223
<profiles>
@@ -137,11 +138,6 @@
137138

138139
<!-- Swagger -->
139140

140-
<dependency>
141-
<groupId>org.springdoc</groupId>
142-
<artifactId>springdoc-openapi-ui</artifactId>
143-
<version>${springdoc-ui.version}</version>
144-
</dependency>
145141
<dependency>
146142
<groupId>org.springdoc</groupId>
147143
<artifactId>springdoc-openapi-data-rest</artifactId>
@@ -169,7 +165,17 @@
169165
<dependency>
170166
<groupId>com.fasterxml.jackson.core</groupId>
171167
<artifactId>jackson-databind</artifactId>
172-
<version>2.10.0</version>
168+
<version>${jackson.version}</version>
169+
</dependency>
170+
<dependency>
171+
<groupId>com.fasterxml.jackson.core</groupId>
172+
<artifactId>jackson-annotations</artifactId>
173+
<version>${jackson.version}</version>
174+
</dependency>
175+
<dependency>
176+
<groupId>com.fasterxml.jackson.core</groupId>
177+
<artifactId>jackson-core</artifactId>
178+
<version>${jackson.version}</version>
173179
</dependency>
174180
</dependencies>
175181

src/main/java/io/github/patternatlas/api/PatternAtlasAPI.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,33 @@
44
import org.springframework.boot.SpringApplication;
55
import org.springframework.boot.autoconfigure.SpringBootApplication;
66
import org.springframework.transaction.annotation.EnableTransactionManagement;
7-
8-
import com.vladmihalcea.hibernate.type.util.Configuration;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.web.bind.annotation.RestController;
99

1010
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
1111
import io.swagger.v3.oas.annotations.info.Contact;
1212
import io.swagger.v3.oas.annotations.info.Info;
13+
14+
import com.vladmihalcea.hibernate.type.util.Configuration;
15+
1316
import lombok.extern.slf4j.Slf4j;
1417

18+
import io.github.patternatlas.api.rest.controller.UserController;
19+
import io.github.patternatlas.api.service.IssueService;
20+
1521
@EnableTransactionManagement
1622
@Slf4j
23+
@RestController
1724
@SpringBootApplication
1825
@OpenAPIDefinition(info = @Info(title = "pattern-atlas-api", version = "1.0", contact = @Contact(url = "https://github.com/PatternAtlas/pattern-atlas-api", name = "Pattern Atlas API")))
1926
public class PatternAtlasAPI implements CommandLineRunner {
2027

28+
@Autowired
29+
private UserController userController;
30+
31+
@Autowired
32+
private IssueService issueService;
33+
2134
public static void main(String[] args) {
2235
System.setProperty(Configuration.PropertyKey.PRINT_BANNER.getKey(), Boolean.FALSE.toString());
2336
SpringApplication.run(PatternAtlasAPI.class, args);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.github.patternatlas.api.config;
2+
3+
public interface Authority {
4+
5+
// TODO will be phased out - after all authority checks are changed to hasResourcePermission, this file should not be
6+
// needed anymore
7+
8+
/** Pattern */
9+
String APPROVED_PATTERN_READ = "hasAuthority('APPROVED_PATTERN_READ')";
10+
String APPROVED_PATTERN_CREATE = "hasAuthority('APPROVED_PATTERN_CREATE')";
11+
String APPROVED_PATTERN_EDIT = "hasAuthority('APPROVED_PATTERN_EDIT')";
12+
String APPROVED_PATTERN_DELETE = "hasAuthority('APPROVED_PATTERN_DELETE')";
13+
String APPROVED_PATTERN_READ_ALL = "hasAuthority('APPROVED_PATTERN_READ_ALL')";
14+
String APPROVED_PATTERN_EDIT_ALL = "hasAuthority('APPROVED_PATTERN_EDIT_ALL')";
15+
String APPROVED_PATTERN_DELETE_ALL = "hasAuthority('APPROVED_PATTERN_DELETE_ALL')";
16+
/** USER */
17+
String USER_READ = "hasAuthority('USER_READ')";
18+
String USER_CREATE = "hasAuthority('USER_CREATE')";
19+
String USER_EDIT = "hasAuthority('USER_EDIT')";
20+
String USER_DELETE = "hasAuthority('USER_DELETE')";
21+
String USER_READ_ALL = "hasAuthority('USER_READ_ALL')";
22+
String USER_EDIT_ALL = "hasAuthority('USER_EDIT_ALL')";
23+
String USER_DELETE_ALL = "hasAuthority('USER_DELETE_ALL')";
24+
String USER_ALL = "hasAuthority('USER_ALL')";
25+
/** GENERAL */
26+
String COMMENT = "hasAuthority('COMMENT')";
27+
String VOTE = "hasAuthority('VOTE')";
28+
String EVIDENCE = "hasAuthority('EVIDENCE')";
29+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.github.patternatlas.api.config;
2+
3+
import io.github.patternatlas.api.security.ResourceMethodSecurityExpressionHandler;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.context.ApplicationContext;
6+
import org.springframework.context.annotation.Configuration;
7+
import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler;
8+
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
9+
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
10+
11+
@Configuration
12+
@EnableGlobalMethodSecurity(prePostEnabled = true)
13+
public class ResourceSecurityConfig extends GlobalMethodSecurityConfiguration {
14+
15+
@Autowired
16+
private ApplicationContext applicationContext;
17+
18+
@Override
19+
protected MethodSecurityExpressionHandler createExpressionHandler() {
20+
ResourceMethodSecurityExpressionHandler handler = new ResourceMethodSecurityExpressionHandler();
21+
handler.setApplicationContext(applicationContext);
22+
return handler;
23+
}
24+
}

src/main/java/io/github/patternatlas/api/config/ResourceServerConfig.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
package io.github.patternatlas.api.config;
22

3+
import org.springframework.boot.autoconfigure.security.oauth2.resource.JwtAccessTokenConverterConfigurer;
34
import org.springframework.boot.web.servlet.FilterRegistrationBean;
45
import org.springframework.context.annotation.Bean;
56
import org.springframework.context.annotation.Configuration;
67
import org.springframework.core.Ordered;
8+
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
79
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
810
import org.springframework.security.config.http.SessionCreationPolicy;
911
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
1012
import org.springframework.security.crypto.password.PasswordEncoder;
1113
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
1214
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
1315
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
16+
import org.springframework.security.oauth2.provider.OAuth2Authentication;
17+
import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter;
18+
import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
19+
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
20+
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
1421
import org.springframework.web.cors.CorsConfiguration;
1522
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
1623
import org.springframework.web.filter.CorsFilter;
1724

25+
import java.util.Map;
26+
1827
@Configuration
1928
@EnableResourceServer
20-
// START::Comment for local development with authorization
21-
//@EnableGlobalMethodSecurity(prePostEnabled = true)
22-
// END::Comment for local development with authorization
2329
class ResourceServerConfig extends ResourceServerConfigurerAdapter {
2430

2531
@Override
@@ -29,17 +35,7 @@ public void configure(HttpSecurity http) throws Exception {
2935
.antMatchers("/**")
3036
.and()
3137
.authorizeRequests()
32-
.antMatchers("/swagger-ui/**").permitAll()
33-
// START::Comment for local development with authorization
34-
// .antMatchers(HttpMethod.GET, "/**").permitAll()
35-
// .antMatchers(HttpMethod.POST, "/**").access("#oauth2.hasScope('write')")
36-
// .antMatchers(HttpMethod.PUT, "/**").access("#oauth2.hasScope('write')")
37-
// .antMatchers(HttpMethod.DELETE, "/**").hasAuthority("ADMIN")
38-
// .anyRequest().authenticated()
39-
//END::Comment for local development with authorization
40-
// START::Uncomment for local development without authorization
4138
.anyRequest().permitAll()
42-
// END::Uncomment for local development without authorization
4339
.and()
4440
.sessionManagement()
4541
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
@@ -69,4 +65,5 @@ public FilterRegistrationBean customCorsFilter() {
6965
bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
7066
return bean;
7167
}
68+
7269
}

0 commit comments

Comments
 (0)