-
Notifications
You must be signed in to change notification settings - Fork 13
/
SpringSecurityConfig.java
40 lines (32 loc) · 1.4 KB
/
SpringSecurityConfig.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
package org.apache.juneau.petstore.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
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.configuration.WebSecurityConfigurerAdapter;
/**
* TODO - Needs documentation
*/
@Configuration
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter{
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user").password("{noop}password").roles("USER")
.and()
.withUser("admin").password("{noop}password").roles("USER", "ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.httpBasic()
.and()
.authorizeRequests()
// .antMatchers(HttpMethod.POST, "/petstore/pet").hasRole("ADMIN")
.antMatchers(HttpMethod.PUT, "/petstore/pet/**").hasRole("ADMIN")
.antMatchers(HttpMethod.DELETE, "/petstore/pet/**").hasRole("ADMIN")
.and()
.csrf().disable()
.formLogin().disable();
}
}