| | |
| | | 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; |
| | | import org.springframework.security.crypto.password.NoOpPasswordEncoder; |
| | | import org.springframework.security.oauth2.provider.ClientDetailsService; |
| | | import org.springframework.security.oauth2.provider.approval.ApprovalStore; |
| | | import org.springframework.security.oauth2.provider.approval.TokenApprovalStore; |
| | | import org.springframework.security.oauth2.provider.approval.TokenStoreUserApprovalHandler; |
| | | import org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory; |
| | | import org.springframework.security.oauth2.provider.token.TokenStore; |
| | | import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore; |
| | | import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore; |
| | | |
| | | @Configuration |
| | |
| | | .withUser("bill").password("abc123").roles("ADMIN").and() |
| | | .withUser("bob").password("abc123").roles("USER"); |
| | | |
| | | // auth.userDetailsService(userDetailsService).passwordEncoder(new Md5PasswordEncoder()); |
| | | auth.userDetailsService(userDetailsService).passwordEncoder(NoOpPasswordEncoder.getInstance()); |
| | | } |
| | | |
| | | @Override |
| | | protected void configure(HttpSecurity http) throws Exception { |
| | | http |
| | | .anonymous().disable() |
| | | .authorizeRequests() |
| | | .antMatchers("/oauth/token").permitAll(); |
| | | http.csrf().disable(); //TODO 暂时关闭CSRF |
| | | http.anonymous().disable() |
| | | .authorizeRequests() |
| | | .antMatchers("/oauth/token").permitAll(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Bean |
| | | public TokenStore tokenStore() { |
| | | //return new InMemoryTokenStore(); |
| | | return new RedisTokenStore(redisConnection); |
| | | return new InMemoryTokenStore(); |
| | | //return new RedisTokenStore(redisConnection); |
| | | } |
| | | |
| | | @Bean |