oauth2-取消资源服务器配置
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
package com.accompany.oauth2.config;
|
||||
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import com.accompany.oauth2.constant.GrantTypeEnum;
|
||||
import com.accompany.oauth2.exception.CustomOAuth2WebResponseExceptionTranslator;
|
||||
import com.accompany.oauth2.jwt.JwtTicketConverter;
|
||||
import com.accompany.oauth2.jwt.JwtTokenConverter;
|
||||
import com.accompany.oauth2.service.account.SuperAdminGrantService;
|
||||
import com.accompany.oauth2.support.password.PasswordTokenGranter;
|
||||
import com.accompany.oauth2.support.verify.VerifyCodeTokenGranter;
|
||||
import com.accompany.oauth2.ticket.RedisTicketStore;
|
||||
import com.accompany.oauth2.ticket.TicketServices;
|
||||
import com.accompany.oauth2.ticket.TicketStore;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -13,6 +18,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
|
||||
@@ -54,6 +60,10 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
|
||||
SuperAdminGrantService superAdminGrantService;
|
||||
@Autowired
|
||||
OAuthConfig oAuthConfig;
|
||||
@Autowired
|
||||
TokenStore tokenStore;
|
||||
@Autowired
|
||||
JedisService jedisService;
|
||||
|
||||
@Override
|
||||
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
|
||||
@@ -73,6 +83,28 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
|
||||
.refreshTokenValiditySeconds(3196800);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TicketServices ticketService(UserDetailsService userDetailsService) {
|
||||
TicketServices ticketService = new TicketServices();
|
||||
ticketService.setTokenStore(tokenStore);
|
||||
ticketService.setUserDetailsService(userDetailsService);
|
||||
ticketService.setTicketStore(ticketStore());
|
||||
ticketService.setTicketEnhancer(jwtTicketConverter());
|
||||
return ticketService;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TicketStore ticketStore() {
|
||||
RedisTicketStore ticketStore = new RedisTicketStore();
|
||||
ticketStore.setJedisService(jedisService);
|
||||
return ticketStore;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JwtTicketConverter jwtTicketConverter() {
|
||||
return new JwtTicketConverter(oAuthConfig.getJwtSignKey());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TokenStore tokenStore() {
|
||||
return new JwtTokenStore(tokenEnhancer());
|
||||
|
@@ -1,69 +0,0 @@
|
||||
package com.accompany.oauth2.config;
|
||||
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import com.accompany.oauth2.jwt.JwtTicketConverter;
|
||||
import com.accompany.oauth2.ticket.RedisTicketStore;
|
||||
import com.accompany.oauth2.ticket.TicketServices;
|
||||
import com.accompany.oauth2.ticket.TicketStore;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
|
||||
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
|
||||
import org.springframework.security.oauth2.provider.token.TokenStore;
|
||||
|
||||
/**
|
||||
* Created by PaperCut on 2018/8/15.
|
||||
* 资源服务器配置
|
||||
*/
|
||||
@Configuration
|
||||
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
|
||||
|
||||
@Autowired
|
||||
TokenStore tokenStore;
|
||||
@Autowired
|
||||
TokenEnhancer jwtTokenEnhancer;
|
||||
@Autowired
|
||||
JedisService jedisService;
|
||||
@Autowired
|
||||
OAuthConfig oAuthConfig;
|
||||
|
||||
@Override
|
||||
public void configure(ResourceServerSecurityConfigurer resources) {
|
||||
resources.resourceId(null).stateless(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(HttpSecurity http) throws Exception {
|
||||
http.authorizeRequests()
|
||||
.antMatchers("/oauth/**").permitAll()
|
||||
.antMatchers("/ticket/**").permitAll()
|
||||
.antMatchers("/acc/**").permitAll()
|
||||
.antMatchers("/**").authenticated();//配置order访问控制,必须认证过后才可以访问
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TicketServices ticketService(UserDetailsService userDetailsService) {
|
||||
TicketServices ticketService = new TicketServices();
|
||||
ticketService.setTokenStore(tokenStore);
|
||||
ticketService.setUserDetailsService(userDetailsService);
|
||||
ticketService.setTicketStore(ticketStore());
|
||||
ticketService.setTicketEnhancer(jwtTicketConverter());
|
||||
return ticketService;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TicketStore ticketStore() {
|
||||
RedisTicketStore ticketStore = new RedisTicketStore();
|
||||
ticketStore.setJedisService(jedisService);
|
||||
return ticketStore;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JwtTicketConverter jwtTicketConverter() {
|
||||
return new JwtTicketConverter(oAuthConfig.getJwtSignKey());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user