· 7 years ago · Oct 04, 2018, 03:44 AM
1package com.aksara.morris.config;
2
3import com.aksara.morris.service.UserService;
4import org.springframework.beans.factory.annotation.Autowired;
5import org.springframework.beans.factory.annotation.Qualifier;
6import org.springframework.context.annotation.Bean;
7import org.springframework.context.annotation.Configuration;
8import org.springframework.security.authentication.AuthenticationManager;
9import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
10import org.springframework.security.config.annotation.web.builders.HttpSecurity;
11import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
12import org.springframework.security.config.http.SessionCreationPolicy;
13import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
14import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
15
16@EnableResourceServer
17@Configuration
18public class ResourceServerConfig extends WebSecurityConfigurerAdapter {
19 @Autowired
20 private UserService userService;
21
22 @Override
23 @Bean
24 public AuthenticationManager authenticationManagerBean() throws Exception {
25 return super.authenticationManagerBean();
26 }
27
28 @Override
29 protected void configure(HttpSecurity http) throws Exception {
30
31 http.requestMatchers()
32 .antMatchers("/login", "/oauth/authorize", "/oauth/token")
33 .and()
34 .authorizeRequests()
35 .anyRequest()
36 .authenticated()
37 .and()
38 .formLogin()
39 .permitAll();
40 }
41
42
43 @Override
44 protected void configure(AuthenticationManagerBuilder auth) throws Exception {
45 /** ============ KALAU PAKE INI ERROR ======================================= **/
46 auth.parentAuthenticationManager(authenticationManagerBean()).userDetailsService(userService).passwordEncoder(new BCryptPasswordEncoder());
47
48
49 /** =>>>>>>>> KALAU PAKE BARIS DIBAWAH INI OK dia mau balikin access token **/
50// auth.parentAuthenticationManager(authenticationManagerBean())
51// .inMemoryAuthentication()
52// .withUser("Peter")
53// .password("{noop}peter")
54// .roles("USER");
55 }
56
57}