增加多租户功能(应用隔离)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.central;
|
||||
|
||||
import com.central.common.annotation.EnableLoginArgResolver;
|
||||
import com.central.common.ribbon.annotation.EnableFeignInterceptor;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
@@ -11,9 +11,9 @@ import org.springframework.session.data.redis.config.annotation.web.http.EnableR
|
||||
* @author zlt
|
||||
*/
|
||||
@EnableFeignClients
|
||||
@EnableFeignInterceptor
|
||||
@EnableDiscoveryClient
|
||||
@EnableRedisHttpSession
|
||||
@EnableLoginArgResolver
|
||||
@SpringBootApplication
|
||||
public class UaaServerApp {
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.central.oauth.config;
|
||||
|
||||
import com.central.common.constant.SecurityConstants;
|
||||
import com.google.code.kaptcha.impl.DefaultKaptcha;
|
||||
import com.google.code.kaptcha.util.Config;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* @date 2018-12-21 21:12:18
|
||||
*/
|
||||
@Configuration
|
||||
public class KaptchaConfig {
|
||||
private static final String KAPTCHA_BORDER = "kaptcha.border";
|
||||
private static final String KAPTCHA_TEXTPRODUCER_FONT_COLOR = "kaptcha.textproducer.font.color";
|
||||
private static final String KAPTCHA_TEXTPRODUCER_CHAR_SPACE = "kaptcha.textproducer.char.space";
|
||||
private static final String KAPTCHA_IMAGE_WIDTH = "kaptcha.image.width";
|
||||
private static final String KAPTCHA_IMAGE_HEIGHT = "kaptcha.image.height";
|
||||
private static final String KAPTCHA_TEXTPRODUCER_CHAR_LENGTH = "kaptcha.textproducer.char.length";
|
||||
private static final Object KAPTCHA_IMAGE_FONT_SIZE = "kaptcha.textproducer.font.size";
|
||||
|
||||
@Bean
|
||||
public DefaultKaptcha producer() {
|
||||
Properties properties = new Properties();
|
||||
properties.put(KAPTCHA_BORDER, SecurityConstants.DEFAULT_IMAGE_BORDER);
|
||||
properties.put(KAPTCHA_TEXTPRODUCER_FONT_COLOR, SecurityConstants.DEFAULT_COLOR_FONT);
|
||||
properties.put(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, SecurityConstants.DEFAULT_CHAR_SPACE);
|
||||
properties.put(KAPTCHA_IMAGE_WIDTH, SecurityConstants.DEFAULT_IMAGE_WIDTH);
|
||||
properties.put(KAPTCHA_IMAGE_HEIGHT, SecurityConstants.DEFAULT_IMAGE_HEIGHT);
|
||||
properties.put(KAPTCHA_IMAGE_FONT_SIZE, SecurityConstants.DEFAULT_IMAGE_FONT_SIZE);
|
||||
properties.put(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, SecurityConstants.DEFAULT_IMAGE_LENGTH);
|
||||
Config config = new Config(properties);
|
||||
DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
|
||||
defaultKaptcha.setConfig(config);
|
||||
return defaultKaptcha;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.central.oauth.config;
|
||||
|
||||
import com.central.common.config.DefaultWebMvcConfig;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* @date 2019/8/5
|
||||
*/
|
||||
@Configuration
|
||||
public class WebMvcConfig extends DefaultWebMvcConfig {
|
||||
}
|
||||
@@ -40,9 +40,9 @@ public class ClientController {
|
||||
|
||||
@GetMapping("/all")
|
||||
@ApiOperation(value = "所有应用")
|
||||
public List<Client> allClient() {
|
||||
public Result<List<Client>> allClient() {
|
||||
PageResult<Client> page = clientService.listClent(Maps.newHashMap(), false);
|
||||
return page.getData();
|
||||
return Result.succeed(page.getData());
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.central.oauth.controller;
|
||||
|
||||
import com.central.common.constant.SecurityConstants;
|
||||
import com.central.common.utils.ResponseUtil;
|
||||
import com.central.common.utils.TenantContextHolder;
|
||||
import com.central.oauth2.common.token.MobileAuthenticationToken;
|
||||
import com.central.oauth2.common.token.OpenIdAuthenticationToken;
|
||||
import com.central.oauth2.common.util.AuthUtils;
|
||||
@@ -90,6 +91,8 @@ public class OAuth2Controller {
|
||||
String clientSecret = clientInfos[1];
|
||||
|
||||
ClientDetails clientDetails = getClient(clientId, clientSecret);
|
||||
//保存租户id
|
||||
TenantContextHolder.setTenant(clientId);
|
||||
TokenRequest tokenRequest = new TokenRequest(MapUtils.EMPTY_MAP, clientId, clientDetails.getScope(), "customer");
|
||||
OAuth2Request oAuth2Request = tokenRequest.createOAuth2Request(clientDetails);
|
||||
Authentication authentication = authenticationManager.authenticate(token);
|
||||
|
||||
@@ -23,9 +23,9 @@ public class TokensController {
|
||||
@Autowired
|
||||
private ITokensService tokensService;
|
||||
|
||||
@GetMapping("/list")
|
||||
@GetMapping("")
|
||||
@ApiOperation(value = "token列表")
|
||||
public PageResult<TokenVo> list(@RequestParam Map<String, Object> params, @LoginClient String clientId) {
|
||||
return tokensService.listTokens(params, clientId);
|
||||
public PageResult<TokenVo> list(@RequestParam Map<String, Object> params, String tenantId) {
|
||||
return tokensService.listTokens(params, tenantId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,15 +41,13 @@
|
||||
<if test="params.searchKey != null and params.searchKey != ''">
|
||||
and client_id like concat('%', #{params.searchKey}, '%')
|
||||
</if>
|
||||
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<select id="findList" resultType="com.central.oauth.model.Client">
|
||||
select id , client_id, client_name , resource_ids ,
|
||||
client_secret ,
|
||||
client_secret_str ,
|
||||
web_server_redirect_uri from oauth_client_details t
|
||||
select id, client_id, client_name, resource_ids
|
||||
, client_secret, client_secret_str, web_server_redirect_uri
|
||||
from oauth_client_details
|
||||
<include refid="where"/>
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user