minor cleanup work

This commit is contained in:
eugenp 2016-08-19 16:05:57 +03:00
parent 6e5de2fb36
commit fb5cc7dcf9
5 changed files with 12 additions and 20 deletions

View File

@ -248,11 +248,11 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <!-- <dependency> -->
<groupId>org.hamcrest</groupId> <!-- <groupId>org.hamcrest</groupId> -->
<artifactId>hamcrest-core</artifactId> <!-- <artifactId>hamcrest-core</artifactId> -->
<scope>test</scope> <!-- <scope>test</scope> -->
</dependency> <!-- </dependency> -->
<dependency> <dependency>
<groupId>org.hamcrest</groupId> <groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId> <artifactId>hamcrest-library</artifactId>

View File

@ -1,5 +1,7 @@
package com.baeldung.spring.security.x509; package com.baeldung.spring.security.x509;
import java.security.Principal;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
@ -7,8 +9,6 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import java.security.Principal;
@Controller @Controller
public class UserController { public class UserController {
@PreAuthorize("hasAuthority('ROLE_USER')") @PreAuthorize("hasAuthority('ROLE_USER')")

View File

@ -2,21 +2,15 @@ package com.baeldung.spring.security.x509;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
@SpringBootApplication @SpringBootApplication
@EnableWebSecurity @EnableWebSecurity
public class X509AuthenticationServer extends WebSecurityConfigurerAdapter { public class X509AuthenticationServer extends WebSecurityConfigurerAdapter {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(X509AuthenticationServer.class, args); SpringApplication.run(X509AuthenticationServer.class, args);
} }
} }

View File

@ -1,5 +1,7 @@
package com.baeldung.spring.security.x509; package com.baeldung.spring.security.x509;
import java.security.Principal;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
@ -7,8 +9,6 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import java.security.Principal;
@Controller @Controller
public class UserController { public class UserController {
@PreAuthorize("hasAuthority('ROLE_USER')") @PreAuthorize("hasAuthority('ROLE_USER')")

View File

@ -23,9 +23,7 @@ public class X509AuthenticationServer extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated() http.authorizeRequests().anyRequest().authenticated().and().x509().subjectPrincipalRegex("CN=(.*?)(?:,|$)").userDetailsService(userDetailsService());
.and()
.x509().subjectPrincipalRegex("CN=(.*?)(?:,|$)").userDetailsService(userDetailsService());
} }
@Bean @Bean