-
Notifications
You must be signed in to change notification settings - Fork 1
/
SecurityConfig.java
64 lines (55 loc) · 2.45 KB
/
SecurityConfig.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
61
62
63
64
package security;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationProvider;
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;
/**
* Marek Bohm
*/
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
// @Autowired
// private AuthenticationProviderImpl authProvider;
@Bean
public AuthenticationProvider authProvider(){
return new AuthenticationProviderImpl();
};
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/", "/home/", "/machine/","/login/", "/accessdenied").permitAll()
.antMatchers("/rental/list").hasAnyAuthority("ADMIN", "CUSTOMER", "EMPLOYEE")
.antMatchers("/user/delete", "/revision/**", "/rental/edit/**", "/rental/new", "/rental/delete").hasAuthority("ADMIN")
.antMatchers("/user/", "/revision/**", "/rental/edit/**", "/rental/new", "/rental/delete").hasAuthority("EMPLOYEE")
//.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.failureUrl("/login?error=invalid_attempt")
.usernameParameter("email").passwordParameter("password")
.permitAll()
.and()
.logout()
.permitAll()
.and()
.exceptionHandling().accessDeniedPage("/accessdenied")
.and()
.csrf().disable();
}
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers("/resources/**");
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authProvider());
}
}