-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto configurations conditional on web application
Fixes #405
- Loading branch information
1 parent
b454348
commit 9b7d800
Showing
22 changed files
with
372 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,37 +2,29 @@ | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.zalando</groupId> | ||
<artifactId>problem-spring-parent</artifactId> | ||
<version>0.26.0-SNAPSHOT</version> | ||
<packaging>pom</packaging> | ||
|
||
<name>Problem: Spring Parent</name> | ||
<url>https://github.com/zalando/problem-spring-web</url> | ||
|
||
<organization> | ||
<name>Zalando SE</name> | ||
</organization> | ||
|
||
<inceptionYear>2015</inceptionYear> | ||
|
||
<licenses> | ||
<license> | ||
<name>MIT License</name> | ||
<url>https://opensource.org/licenses/MIT</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<modules> | ||
<module>problem-violations</module> | ||
<module>problem-spring-common</module> | ||
<module>problem-spring-web</module> | ||
<module>problem-spring-web-starter</module> | ||
<module>problem-spring-web-autoconfigure</module> | ||
</modules> | ||
|
||
<developers> | ||
<developer> | ||
<name>Lukas Niemeier</name> | ||
|
@@ -47,13 +39,11 @@ | |
<organizationUrl>https://tech.zalando.com/</organizationUrl> | ||
</developer> | ||
</developers> | ||
|
||
<scm> | ||
<url>https://github.com/zalando/problem-spring-web</url> | ||
<connection>scm:git:[email protected]:zalando/problem-spring-web.git</connection> | ||
<developerConnection>scm:git:[email protected]:zalando/problem-spring-web.git</developerConnection> | ||
</scm> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
|
@@ -68,7 +58,6 @@ | |
<spring-boot.version>2.2.1.RELEASE</spring-boot.version> | ||
<junit-jupiter.version>5.5.2</junit-jupiter.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apiguardian</groupId> | ||
|
@@ -267,7 +256,6 @@ | |
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
|
@@ -351,6 +339,7 @@ | |
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.2</version> | ||
<configuration> | ||
<failIfNoTests>true</failIfNoTests> | ||
<parallel>classesAndMethods</parallel> | ||
<threadCount>1</threadCount> | ||
<perCoreThreadCount>true</perCoreThreadCount> | ||
|
@@ -416,7 +405,6 @@ | |
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<distributionManagement> | ||
<snapshotRepository> | ||
<id>ossrh</id> | ||
|
@@ -427,7 +415,6 @@ | |
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> | ||
</repository> | ||
</distributionManagement> | ||
|
||
<profiles> | ||
<profile> | ||
<id>webflux</id> | ||
|
@@ -500,5 +487,4 @@ | |
</build> | ||
</profile> | ||
</profiles> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
...re/src/main/java/org/zalando/problem/spring/web/autoconfigure/BasicExceptionHandling.java
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
...nfigure/src/main/java/org/zalando/problem/spring/web/autoconfigure/ExceptionHandling.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.zalando.problem.spring.web.autoconfigure; | ||
|
||
import org.apiguardian.api.API; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.zalando.problem.spring.web.advice.ProblemHandling; | ||
|
||
import static org.apiguardian.api.API.Status.INTERNAL; | ||
|
||
@API(status = INTERNAL) | ||
@ControllerAdvice | ||
final class ExceptionHandling implements ProblemHandling { | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
.../src/main/java/org/zalando/problem/spring/web/autoconfigure/ProblemAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.zalando.problem.spring.web.autoconfigure; | ||
|
||
import org.apiguardian.api.API; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.WebSecurityConfigurer; | ||
import org.zalando.problem.spring.web.advice.AdviceTrait; | ||
|
||
import static org.apiguardian.api.API.Status.INTERNAL; | ||
|
||
@API(status = INTERNAL) | ||
@Configuration | ||
@ConditionalOnWebApplication | ||
@ConditionalOnClass(WebSecurityConfigurer.class) | ||
public class ProblemAutoConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean(AdviceTrait.class) | ||
public AdviceTrait exceptionHandling() { | ||
return new ExceptionHandling(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...g/zalando/problem/spring/web/autoconfigure/security/ProblemSecurityAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.zalando.problem.spring.web.autoconfigure.security; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.apiguardian.api.API; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.AutoConfigureAfter; | ||
import org.springframework.boot.autoconfigure.AutoConfigureBefore; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; | ||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.security.config.annotation.web.WebSecurityConfigurer; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration; | ||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
import org.zalando.problem.spring.web.advice.AdviceTrait; | ||
import org.zalando.problem.spring.web.advice.security.SecurityProblemSupport; | ||
import org.zalando.problem.spring.web.autoconfigure.ProblemAutoConfiguration; | ||
|
||
import static org.apiguardian.api.API.Status.INTERNAL; | ||
|
||
@API(status = INTERNAL) | ||
@AllArgsConstructor(onConstructor = @__(@Autowired)) | ||
@Configuration | ||
@ConditionalOnWebApplication | ||
@ConditionalOnClass(WebSecurityConfigurer.class) | ||
@ConditionalOnBean(WebSecurityConfiguration.class) | ||
@Import(SecurityProblemSupport.class) | ||
//subtract random, uncommon number to reduce chances of collision with a user-selected order | ||
@Order(Ordered.LOWEST_PRECEDENCE - 21) | ||
@AutoConfigureAfter(SecurityAutoConfiguration.class) | ||
@AutoConfigureBefore(ProblemAutoConfiguration.class) | ||
public class ProblemSecurityAutoConfiguration extends WebSecurityConfigurerAdapter { | ||
|
||
private final SecurityProblemSupport support; | ||
|
||
@Override | ||
public void configure(final HttpSecurity http) throws Exception { | ||
http.exceptionHandling() | ||
.authenticationEntryPoint(support) | ||
.accessDeniedHandler(support); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean(AdviceTrait.class) | ||
public AdviceTrait securityExceptionHandling() { | ||
return new SecurityExceptionHandling(); | ||
} | ||
|
||
} |
Oops, something went wrong.