This repository has been archived on 2022-07-05. You can view files and clone it, but cannot push or open issues/pull-requests.
steleks_backend/users/src/main/java/ba/steleks/security/SecurityConfig.java

51 lines
1.9 KiB
Java
Raw Normal View History

2017-05-27 18:31:24 +00:00
package ba.steleks.security;/**
* Created by ensar on 16/05/17.
*/
import ba.steleks.repository.UsersJpaRepository;
import ba.steleks.security.token.TokenStore;
2017-05-27 18:31:24 +00:00
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
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.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
@Configuration
@EnableWebSecurity
@ComponentScan("org.baeldung.security")
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
2017-05-29 07:27:53 +00:00
public UserDetailsService provideUserDetailsService() {
return new SteleksUsersDetailsService();
2017-05-27 18:31:24 +00:00
}
@Autowired
2017-05-29 07:27:53 +00:00
private UserDetailsService userDetailsService;
2017-05-27 18:31:24 +00:00
@Autowired
private TokenStore tokenStore;
@Autowired
private UsersJpaRepository usersJpaRepository;
2017-05-27 18:31:24 +00:00
@Override
protected void configure(
AuthenticationManagerBuilder auth) throws Exception {
2017-05-29 07:27:53 +00:00
auth.userDetailsService(userDetailsService);
2017-05-27 18:31:24 +00:00
}
@Override
protected void configure(HttpSecurity http) throws Exception {
2017-05-29 07:27:53 +00:00
http.csrf().disable().authorizeRequests()
2017-06-01 22:12:09 +00:00
.antMatchers("/accesstoken", "/accesstoken/**", "/").permitAll()
2017-05-29 07:27:53 +00:00
.anyRequest().authenticated()
.and()
.addFilterBefore(new AuthenticationFilter(tokenStore, usersJpaRepository), CustomUrlUsernamePasswordAuthenticationFilter.class);
2017-05-27 18:31:24 +00:00
}
2017-05-30 19:06:30 +00:00
2017-05-27 18:31:24 +00:00
}