-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathWebSecurityConfig.java
60 lines (50 loc) · 2.07 KB
/
WebSecurityConfig.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package ac.uk.bristol.cs.santa.grotto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
/**
* Created by csxds on 30/11/2017.
*/
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
// make static resources available
.antMatchers("/css/**", "/images/**", "/webjars/**").permitAll()
// allow browsing index
.antMatchers("/", "/terms", "/contact").permitAll()
.anyRequest().authenticated()
.and()
// configure login
.formLogin()
.loginPage("/login")
.failureUrl("/login-error.html")
.permitAll()
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/")
.permitAll();
}
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers("/resources/**"); // #3
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// create some dummy users
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
}