Commit 4fabc2b0 by fengshuonan

适配oracle ,升级just auth版本

parent 98f1f55c
package cn.stylefeng.guns.base.db.collector; package cn.stylefeng.guns.base.db.collector;
import cn.stylefeng.roses.kernel.model.exception.ServiceException; import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties; import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
import com.baomidou.mybatisplus.autoconfigure.SpringBootVFS; import com.baomidou.mybatisplus.autoconfigure.SpringBootVFS;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.core.config.GlobalConfig; import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator;
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean; import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import lombok.Data; import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -14,10 +18,13 @@ import org.apache.ibatis.session.SqlSessionFactory; ...@@ -14,10 +18,13 @@ import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.util.List;
/** /**
* mybatis的一些配置收集 * mybatis的一些配置收集
...@@ -38,15 +45,22 @@ public class SqlSessionFactoryCreator { ...@@ -38,15 +45,22 @@ public class SqlSessionFactoryCreator {
private final ApplicationContext applicationContext; private final ApplicationContext applicationContext;
private final ResourceLoader resourceLoader;
private final List<ConfigurationCustomizer> configurationCustomizers;
public SqlSessionFactoryCreator(MybatisPlusProperties properties, public SqlSessionFactoryCreator(MybatisPlusProperties properties,
ResourceLoader resourceLoader,
ObjectProvider<Interceptor[]> interceptorsProvider, ObjectProvider<Interceptor[]> interceptorsProvider,
ObjectProvider<DatabaseIdProvider> databaseIdProvider, ObjectProvider<DatabaseIdProvider> databaseIdProvider,
ObjectProvider<List<ConfigurationCustomizer>> configurationCustomizersProvider,
ApplicationContext applicationContext) { ApplicationContext applicationContext) {
this.properties = properties; this.properties = properties;
this.interceptors = interceptorsProvider.getIfAvailable(); this.interceptors = interceptorsProvider.getIfAvailable();
this.databaseIdProvider = databaseIdProvider.getIfAvailable(); this.databaseIdProvider = databaseIdProvider.getIfAvailable();
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
this.resourceLoader = resourceLoader;
this.configurationCustomizers = configurationCustomizersProvider.getIfAvailable();
} }
/** /**
...@@ -57,6 +71,13 @@ public class SqlSessionFactoryCreator { ...@@ -57,6 +71,13 @@ public class SqlSessionFactoryCreator {
MybatisSqlSessionFactoryBean factory = new MybatisSqlSessionFactoryBean(); MybatisSqlSessionFactoryBean factory = new MybatisSqlSessionFactoryBean();
factory.setDataSource(dataSource); factory.setDataSource(dataSource);
factory.setVfs(SpringBootVFS.class); factory.setVfs(SpringBootVFS.class);
if (StringUtils.hasText(this.properties.getConfigLocation())) {
factory.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
}
applyConfiguration(factory);
if (this.properties.getConfigurationProperties() != null) {
factory.setConfigurationProperties(this.properties.getConfigurationProperties());
}
if (!ObjectUtils.isEmpty(this.interceptors)) { if (!ObjectUtils.isEmpty(this.interceptors)) {
factory.setPlugins(this.interceptors); factory.setPlugins(this.interceptors);
} }
...@@ -66,15 +87,39 @@ public class SqlSessionFactoryCreator { ...@@ -66,15 +87,39 @@ public class SqlSessionFactoryCreator {
if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) { if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {
factory.setTypeAliasesPackage(this.properties.getTypeAliasesPackage()); factory.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
} }
// TODO 自定义枚举包
if (StringUtils.hasLength(this.properties.getTypeEnumsPackage())) {
factory.setTypeEnumsPackage(this.properties.getTypeEnumsPackage());
}
if (this.properties.getTypeAliasesSuperType() != null) {
factory.setTypeAliasesSuperType(this.properties.getTypeAliasesSuperType());
}
if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {
factory.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
}
if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) { if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
factory.setMapperLocations(this.properties.resolveMapperLocations()); factory.setMapperLocations(this.properties.resolveMapperLocations());
} }
// TODO 此处必为非 NULL
GlobalConfig globalConfig = this.properties.getGlobalConfig(); GlobalConfig globalConfig = this.properties.getGlobalConfig();
//注入填充器
if (this.applicationContext.getBeanNamesForType(MetaObjectHandler.class, if (this.applicationContext.getBeanNamesForType(MetaObjectHandler.class,
false, false).length > 0) { false, false).length > 0) {
MetaObjectHandler metaObjectHandler = this.applicationContext.getBean(MetaObjectHandler.class); MetaObjectHandler metaObjectHandler = this.applicationContext.getBean(MetaObjectHandler.class);
globalConfig.setMetaObjectHandler(metaObjectHandler); globalConfig.setMetaObjectHandler(metaObjectHandler);
} }
//注入主键生成器
if (this.applicationContext.getBeanNamesForType(IKeyGenerator.class, false,
false).length > 0) {
IKeyGenerator keyGenerator = this.applicationContext.getBean(IKeyGenerator.class);
globalConfig.getDbConfig().setKeyGenerator(keyGenerator);
}
//注入sql注入器
if (this.applicationContext.getBeanNamesForType(ISqlInjector.class, false,
false).length > 0) {
ISqlInjector iSqlInjector = this.applicationContext.getBean(ISqlInjector.class);
globalConfig.setSqlInjector(iSqlInjector);
}
//globalConfig中有缓存sqlSessionFactory,目前还没别的办法 //globalConfig中有缓存sqlSessionFactory,目前还没别的办法
SqlSessionFactory sqlSessionFactory = factory.getObject(); SqlSessionFactory sqlSessionFactory = factory.getObject();
...@@ -88,4 +133,17 @@ public class SqlSessionFactoryCreator { ...@@ -88,4 +133,17 @@ public class SqlSessionFactoryCreator {
} }
} }
private void applyConfiguration(MybatisSqlSessionFactoryBean factory) {
MybatisConfiguration configuration = this.properties.getConfiguration();
if (configuration == null && !StringUtils.hasText(this.properties.getConfigLocation())) {
configuration = new MybatisConfiguration();
}
if (configuration != null && !CollectionUtils.isEmpty(this.configurationCustomizers)) {
for (ConfigurationCustomizer customizer : this.configurationCustomizers) {
customizer.customize(configuration);
}
}
factory.setConfiguration(configuration);
}
} }
...@@ -110,6 +110,7 @@ public class DataBaseInfoDao { ...@@ -110,6 +110,7 @@ public class DataBaseInfoDao {
int i = preparedStatement.executeUpdate(); int i = preparedStatement.executeUpdate();
log.info("删除master的databaseInfo信息!删除" + i + "条!"); log.info("删除master的databaseInfo信息!删除" + i + "条!");
} catch (Exception ex) { } catch (Exception ex) {
log.info("删除master的databaseInfo信息失败!", ex);
throw new DataSourceInitException(DataSourceInitException.ExEnum.QUERY_DATASOURCE_INFO_ERROR); throw new DataSourceInitException(DataSourceInitException.ExEnum.QUERY_DATASOURCE_INFO_ERROR);
} }
} }
......
...@@ -31,13 +31,6 @@ ...@@ -31,13 +31,6 @@
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<!-- 第三方登录-->
<dependency>
<groupId>me.zhyd.oauth</groupId>
<artifactId>JustAuth</artifactId>
<version>1.6.0-beta</version>
</dependency>
<!-- 最新代码生成模块 --> <!-- 最新代码生成模块 -->
<dependency> <dependency>
<groupId>cn.stylefeng</groupId> <groupId>cn.stylefeng</groupId>
...@@ -45,6 +38,12 @@ ...@@ -45,6 +38,12 @@
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<!-- 第三方登录-->
<dependency>
<groupId>me.zhyd.oauth</groupId>
<artifactId>JustAuth</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -54,7 +54,7 @@ public class UserWrapper extends BaseControllerWrapper { ...@@ -54,7 +54,7 @@ public class UserWrapper extends BaseControllerWrapper {
map.put("roleName", ConstantFactory.me().getRoleName((String) map.get("roleId"))); map.put("roleName", ConstantFactory.me().getRoleName((String) map.get("roleId")));
map.put("deptName", ConstantFactory.me().getDeptName(DecimalUtil.getLong(map.get("deptId")))); map.put("deptName", ConstantFactory.me().getDeptName(DecimalUtil.getLong(map.get("deptId"))));
map.put("statusName", ConstantFactory.me().getStatusName((String) map.get("status"))); map.put("statusName", ConstantFactory.me().getStatusName((String) map.get("status")));
map.put("positionName", ConstantFactory.me().getPositionName((Long) map.get("userId"))); map.put("positionName", ConstantFactory.me().getPositionName(DecimalUtil.getLong(map.get("userId"))));
} }
} }
...@@ -6,6 +6,7 @@ import cn.stylefeng.guns.sys.modular.third.service.LoginService; ...@@ -6,6 +6,7 @@ import cn.stylefeng.guns.sys.modular.third.service.LoginService;
import cn.stylefeng.guns.sys.modular.third.service.OauthUserInfoService; import cn.stylefeng.guns.sys.modular.third.service.OauthUserInfoService;
import cn.stylefeng.roses.core.base.controller.BaseController; import cn.stylefeng.roses.core.base.controller.BaseController;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.request.AuthRequest; import me.zhyd.oauth.request.AuthRequest;
...@@ -13,8 +14,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -13,8 +14,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
...@@ -55,11 +54,11 @@ public class OAuthController extends BaseController { ...@@ -55,11 +54,11 @@ public class OAuthController extends BaseController {
* @Date 2019/6/9 16:45 * @Date 2019/6/9 16:45
*/ */
@RequestMapping("/callback/{source}") @RequestMapping("/callback/{source}")
public String callback(@PathVariable("source") String source, @RequestParam("code") String code, RedirectAttributes model) { public String callback(@PathVariable("source") String source, AuthCallback callback) {
//通过回调的code,请求对应的oauth server获取用户基本信息和token //通过回调的code,请求对应的oauth server获取用户基本信息和token
AuthRequest authRequest = OAuthRequestFactory.getAuthRequest(source); AuthRequest authRequest = OAuthRequestFactory.getAuthRequest(source);
AuthResponse authResponse = authRequest.login(code); AuthResponse authResponse = authRequest.login(callback);
AuthUser oauthUser = (AuthUser) authResponse.getData(); AuthUser oauthUser = (AuthUser) authResponse.getData();
log.info("第三方登录回调成功:" + oauthUser); log.info("第三方登录回调成功:" + oauthUser);
......
...@@ -31,6 +31,7 @@ public class OAuthRequestFactory { ...@@ -31,6 +31,7 @@ public class OAuthRequestFactory {
.clientId("") .clientId("")
.clientSecret("") .clientSecret("")
.redirectUri(BASE_URL + "/oauth/callback/dingtalk") .redirectUri(BASE_URL + "/oauth/callback/dingtalk")
.state("state")
.build()); .build());
break; break;
case "baidu": case "baidu":
...@@ -38,6 +39,7 @@ public class OAuthRequestFactory { ...@@ -38,6 +39,7 @@ public class OAuthRequestFactory {
.clientId("") .clientId("")
.clientSecret("") .clientSecret("")
.redirectUri(BASE_URL + "/oauth/callback/baidu") .redirectUri(BASE_URL + "/oauth/callback/baidu")
.state("state")
.build()); .build());
break; break;
case "github": case "github":
...@@ -45,6 +47,7 @@ public class OAuthRequestFactory { ...@@ -45,6 +47,7 @@ public class OAuthRequestFactory {
.clientId("") .clientId("")
.clientSecret("") .clientSecret("")
.redirectUri(BASE_URL + "/oauth/callback/github") .redirectUri(BASE_URL + "/oauth/callback/github")
.state("state")
.build()); .build());
break; break;
case "gitee": case "gitee":
...@@ -52,6 +55,7 @@ public class OAuthRequestFactory { ...@@ -52,6 +55,7 @@ public class OAuthRequestFactory {
.clientId("") .clientId("")
.clientSecret("") .clientSecret("")
.redirectUri(BASE_URL + "/oauth/callback/gitee") .redirectUri(BASE_URL + "/oauth/callback/gitee")
.state("state")
.build()); .build());
break; break;
case "weibo": case "weibo":
...@@ -59,6 +63,7 @@ public class OAuthRequestFactory { ...@@ -59,6 +63,7 @@ public class OAuthRequestFactory {
.clientId("") .clientId("")
.clientSecret("") .clientSecret("")
.redirectUri(BASE_URL + "/oauth/callback/weibo") .redirectUri(BASE_URL + "/oauth/callback/weibo")
.state("state")
.build()); .build());
break; break;
case "coding": case "coding":
...@@ -66,6 +71,7 @@ public class OAuthRequestFactory { ...@@ -66,6 +71,7 @@ public class OAuthRequestFactory {
.clientId("") .clientId("")
.clientSecret("") .clientSecret("")
.redirectUri(BASE_URL + "/oauth/callback/tencentCloud") .redirectUri(BASE_URL + "/oauth/callback/tencentCloud")
.state("state")
.build()); .build());
break; break;
case "tencentCloud": case "tencentCloud":
...@@ -73,6 +79,7 @@ public class OAuthRequestFactory { ...@@ -73,6 +79,7 @@ public class OAuthRequestFactory {
.clientId("") .clientId("")
.clientSecret("") .clientSecret("")
.redirectUri(BASE_URL + "/oauth/callback/tencentCloud") .redirectUri(BASE_URL + "/oauth/callback/tencentCloud")
.state("state")
.build()); .build());
break; break;
case "oschina": case "oschina":
...@@ -80,6 +87,7 @@ public class OAuthRequestFactory { ...@@ -80,6 +87,7 @@ public class OAuthRequestFactory {
.clientId("") .clientId("")
.clientSecret("") .clientSecret("")
.redirectUri(BASE_URL + "/oauth/callback/oschina") .redirectUri(BASE_URL + "/oauth/callback/oschina")
.state("state")
.build()); .build());
break; break;
case "alipay": case "alipay":
...@@ -89,6 +97,7 @@ public class OAuthRequestFactory { ...@@ -89,6 +97,7 @@ public class OAuthRequestFactory {
.clientSecret("") .clientSecret("")
.alipayPublicKey("") .alipayPublicKey("")
.redirectUri(BASE_URL + "/oauth/callback/alipay") .redirectUri(BASE_URL + "/oauth/callback/alipay")
.state("state")
.build()); .build());
break; break;
case "qq": case "qq":
...@@ -96,6 +105,7 @@ public class OAuthRequestFactory { ...@@ -96,6 +105,7 @@ public class OAuthRequestFactory {
.clientId("") .clientId("")
.clientSecret("") .clientSecret("")
.redirectUri(BASE_URL + "/oauth/callback/qq") .redirectUri(BASE_URL + "/oauth/callback/qq")
.state("state")
.build()); .build());
break; break;
case "wechat": case "wechat":
...@@ -103,6 +113,7 @@ public class OAuthRequestFactory { ...@@ -103,6 +113,7 @@ public class OAuthRequestFactory {
.clientId("") .clientId("")
.clientSecret("") .clientSecret("")
.redirectUri(BASE_URL + "/oauth/callback/wechat") .redirectUri(BASE_URL + "/oauth/callback/wechat")
.state("state")
.build()); .build());
break; break;
case "csdn": case "csdn":
...@@ -110,6 +121,7 @@ public class OAuthRequestFactory { ...@@ -110,6 +121,7 @@ public class OAuthRequestFactory {
.clientId("") .clientId("")
.clientSecret("") .clientSecret("")
.redirectUri(BASE_URL + "/oauth/callback/wechat") .redirectUri(BASE_URL + "/oauth/callback/wechat")
.state("state")
.build()); .build());
break; break;
case "taobao": case "taobao":
...@@ -117,6 +129,7 @@ public class OAuthRequestFactory { ...@@ -117,6 +129,7 @@ public class OAuthRequestFactory {
.clientId("") .clientId("")
.clientSecret("") .clientSecret("")
.redirectUri(BASE_URL + "/oauth/callback/taobao") .redirectUri(BASE_URL + "/oauth/callback/taobao")
.state("state")
.build()); .build());
break; break;
case "google": case "google":
...@@ -124,6 +137,7 @@ public class OAuthRequestFactory { ...@@ -124,6 +137,7 @@ public class OAuthRequestFactory {
.clientId("") .clientId("")
.clientSecret("") .clientSecret("")
.redirectUri(BASE_URL + "/oauth/callback/google") .redirectUri(BASE_URL + "/oauth/callback/google")
.state("state")
.build()); .build());
break; break;
case "facebook": case "facebook":
...@@ -131,6 +145,7 @@ public class OAuthRequestFactory { ...@@ -131,6 +145,7 @@ public class OAuthRequestFactory {
.clientId("") .clientId("")
.clientSecret("") .clientSecret("")
.redirectUri(BASE_URL + "/oauth/callback/facebook") .redirectUri(BASE_URL + "/oauth/callback/facebook")
.state("state")
.build()); .build());
break; break;
} }
......
...@@ -41,17 +41,18 @@ ...@@ -41,17 +41,18 @@
<ehcache.core.version>2.6.11</ehcache.core.version> <ehcache.core.version>2.6.11</ehcache.core.version>
<jwt.version>0.9.0</jwt.version> <jwt.version>0.9.0</jwt.version>
<oshi.version>3.9.1</oshi.version> <oshi.version>3.9.1</oshi.version>
<just.auth.version>1.8.1</just.auth.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<!-- 用just auth的jar冲突--> <!-- just auth兼容问题-->
<dependency> <dependency>
<groupId>cn.hutool</groupId> <groupId>com.alibaba</groupId>
<artifactId>hutool-core</artifactId> <artifactId>fastjson</artifactId>
<version>4.1.21</version> <version>1.2.56</version>
</dependency> </dependency>
<!--核心组件--> <!--核心组件-->
...@@ -152,6 +153,13 @@ ...@@ -152,6 +153,13 @@
<version>${oshi.version}</version> <version>${oshi.version}</version>
</dependency> </dependency>
<!-- 第三方登录 -->
<dependency>
<groupId>me.zhyd.oauth</groupId>
<artifactId>JustAuth</artifactId>
<version>${just.auth.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment