Untitled

mail@pastecode.io avatar
unknown
java
7 months ago
1.1 kB
3
Indexable
Never
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/admin/**").hasRole(ROLE_ADMIN)
                .antMatchers("/client/**").hasRole(ROLE_CLIENT)
                .antMatchers("/expert/**").hasRole(ROLE_EXPERT)
                .and()
                .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
                .logout()
                .logoutSuccessUrl("/")
                .permitAll();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .withUser("admin").password("password").roles(ROLE_ADMIN)
                .and()
                .withUser("client").password("password").roles(ROLE_CLIENT)
                .and()
                .withUser("expert").password("password").roles(ROLE_EXPERT);
    }
}