Skip to content

Commit 252aefd

Browse files
author
Grzegorz Siewruk
committed
Profile for no authentication
1 parent 42abca7 commit 252aefd

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package pl.orange.bst.mixer;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.context.annotation.Profile;
7+
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
8+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
9+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
10+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
11+
import org.springframework.security.core.authority.AuthorityUtils;
12+
import org.springframework.security.core.userdetails.User;
13+
import org.springframework.security.core.userdetails.UserDetails;
14+
import org.springframework.security.core.userdetails.UserDetailsService;
15+
import org.springframework.security.core.userdetails.UsernameNotFoundException;
16+
17+
import java.util.List;
18+
import java.util.stream.Collectors;
19+
import java.util.stream.Stream;
20+
21+
@Configuration
22+
@EnableWebSecurity
23+
@EnableGlobalMethodSecurity(prePostEnabled = true)
24+
@Profile("noauth")
25+
public class NoAuthSecurityConfig extends WebSecurityConfigurerAdapter {
26+
27+
28+
@Override
29+
protected void configure(HttpSecurity http) throws Exception {
30+
http.csrf().disable();
31+
http
32+
.authorizeRequests()
33+
.antMatchers("/**").permitAll();
34+
}
35+
}

src/main/java/pl/orange/bst/mixer/Config.java renamed to src/main/java/pl/orange/bst/mixer/SecurityConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.springframework.boot.autoconfigure.SpringBootApplication;
99
import org.springframework.context.annotation.Bean;
1010
import org.springframework.context.annotation.Configuration;
11+
import org.springframework.context.annotation.Profile;
1112
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
1213
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
1314
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
@@ -26,7 +27,8 @@
2627
@Configuration
2728
@EnableWebSecurity
2829
@EnableGlobalMethodSecurity(prePostEnabled = true)
29-
public class Config extends WebSecurityConfigurerAdapter {
30+
@Profile("!noauth")
31+
public class SecurityConfig extends WebSecurityConfigurerAdapter {
3032

3133
@Value("${allowed.users}")
3234
private String commonNames;

src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ server.ssl.keyStoreType: PKCS12
55
server.ssl.key-alias=mixer
66
server.ssl.trust-store=etc/pki/trust.jks
77
server.ssl.trust-store-password=changeit
8-
server.ssl.client-auth=need
8+
server.ssl.client-auth=want
99
openvasmd.socket=/usr/local/var/run/openvasmd.sock
1010
allowed.users=localhost,127.0.0.1

0 commit comments

Comments
 (0)