Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-enterprise-base
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
base_platform_enterprise
gic-enterprise-base
Commits
ba9e6c1d
Commit
ba9e6c1d
authored
Nov 05, 2020
by
guojuxing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
运维后台淡点登录到gic后台sdk
parent
161e9940
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
314 additions
and
0 deletions
+314
-0
pom.xml
gic-enterprise-sso/pom.xml
+135
-0
LoginGicSsoUtils.java
...sso/src/main/java/com/gic/sso/utils/LoginGicSsoUtils.java
+161
-0
dubbo-gic-enterprise-sso-service.xml
...o/src/main/resources/dubbo-gic-enterprise-sso-service.xml
+18
-0
No files found.
gic-enterprise-sso/pom.xml
0 → 100644
View file @
ba9e6c1d
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<groupId>
com.gic
</groupId>
<artifactId>
gic-pom-base
</artifactId>
<version>
4.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.gic
</groupId>
<artifactId>
gic-enterprise-sso
</artifactId>
<version>
${libraryVersion}
</version>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<maven.compiler.source>
1.8
</maven.compiler.source>
<maven.compiler.target>
1.8
</maven.compiler.target>
<libraryVersion>
4.0-SNAPSHOT
</libraryVersion>
</properties>
<distributionManagement>
<repository>
<!-- 和 Maven setting 保持一致 -->
<id>
nexus-snapshots
</id>
<name>
nexus distribution snapshot repository
</name>
<!-- 这里使用 /content/repositories/snapshots/ -->
<url>
http://182.254.134.223:8081/nexus/content/repositories/snapshots/
</url>
<!--<url>http://stream.banli.mobi:8081/content/repositories/snapshots/</url>-->
</repository>
<snapshotRepository>
<!-- 和 Maven setting 保持一致 -->
<id>
nexus-snapshots
</id>
<name>
nexus distribution snapshot repository
</name>
<!-- 这里使用 /content/repositories/snapshots/ -->
<url>
http://182.254.134.223:8081/nexus/content/repositories/Snapshots-1/
</url>
<!--<url>http://stream.banli.mobi:8081/content/repositories/snapshots/</url>-->
</snapshotRepository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>
com.gic
</groupId>
<artifactId>
gic-base-api
</artifactId>
<version>
${gic-base-api}
</version>
</dependency>
<dependency>
<groupId>
com.gic
</groupId>
<artifactId>
gic-commons
</artifactId>
<version>
${gic-commons}
</version>
</dependency>
<dependency>
<groupId>
com.gic
</groupId>
<artifactId>
gic-enterprise-base-api
</artifactId>
<version>
${gic-enterprise-base-api}
</version>
</dependency>
<dependency>
<groupId>
com.gic
</groupId>
<artifactId>
gic-platform-enterprise-api
</artifactId>
<version>
${gic-platform-enterprise-api}
</version>
</dependency>
<dependency>
<groupId>
com.gic
</groupId>
<artifactId>
gic-platform-auth-api
</artifactId>
<version>
${gic-platform-auth-api}
</version>
</dependency>
<dependency>
<groupId>
com.gic
</groupId>
<artifactId>
gic-platform-config
</artifactId>
<version>
${gic-platform-config}
</version>
</dependency>
<dependency>
<groupId>
com.gic.authcenter
</groupId>
<artifactId>
gic-authcenter-security-core
</artifactId>
<version>
${gic-authcenter-security-core}
</version>
<exclusions>
<exclusion>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-logging
</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<finalName>
${project.artifactId}
</finalName>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<configuration>
<encoding>
${project.build.sourceEncoding}
</encoding>
<source>
${maven.compiler.source}
</source>
<target>
${maven.compiler.target}
</target>
</configuration>
</plugin>
<plugin>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
flatten-maven-plugin
</artifactId>
<version>
1.1.0
</version>
<configuration>
<flattenMode>
defaults
</flattenMode>
</configuration>
<executions>
<!-- enable flattening -->
<execution>
<id>
flatten
</id>
<phase>
process-resources
</phase>
<goals>
<goal>
flatten
</goal>
</goals>
</execution>
<!-- ensure proper cleanup -->
<execution>
<id>
flatten.clean
</id>
<phase>
clean
</phase>
<goals>
<goal>
clean
</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-surefire-plugin
</artifactId>
<version>
2.18.1
</version>
<configuration>
<skipTests>
true
</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
gic-enterprise-sso/src/main/java/com/gic/sso/utils/LoginGicSsoUtils.java
0 → 100644
View file @
ba9e6c1d
package
com
.
gic
.
sso
.
utils
;
import
com.ctrip.framework.apollo.Config
;
import
com.ctrip.framework.apollo.ConfigService
;
import
com.gic.api.base.commons.ServiceResponse
;
import
com.gic.auth.dto.MenuDTO
;
import
com.gic.auth.dto.UserDTO
;
import
com.gic.auth.service.MenuApiService
;
import
com.gic.auth.service.UserApiService
;
import
com.gic.authcenter.security.core.dto.UserDetailsVO
;
import
com.gic.authcenter.security.core.util.UserUtils
;
import
com.gic.commons.util.EntityUtil
;
import
com.gic.commons.webapi.reponse.RestResponse
;
import
com.gic.enterprise.base.EnterpriseInfo
;
import
com.gic.enterprise.base.MenuInfo
;
import
com.gic.enterprise.base.UserInfo
;
import
com.gic.enterprise.constants.Constants
;
import
com.gic.enterprise.dto.EnterpriseDTO
;
import
com.gic.enterprise.service.EnterpriseApiService
;
import
com.gic.enterprise.utils.UserDetail
;
import
com.gic.enterprise.utils.UserDetailUtils
;
import
com.gic.redis.data.util.RedisUtil
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PostConstruct
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
/**
* 运维单点登录到gic后台
* @ClassName: LoginGicSsoUtils
* @Description:
* @author guojuxing
* @date 2020/11/5 2:37 PM
*/
@Component
public
class
LoginGicSsoUtils
{
private
static
Logger
LOGGER
=
LogManager
.
getLogger
(
LoginGicSsoUtils
.
class
);
private
static
LoginGicSsoUtils
loginGicSsoUtils
;
@Autowired
private
MenuApiService
menuApiService
;
@Autowired
private
UserApiService
userApiService
;
@Autowired
private
EnterpriseApiService
enterpriseApiService
;
@PostConstruct
public
void
init
()
{
loginGicSsoUtils
=
this
;
loginGicSsoUtils
.
menuApiService
=
menuApiService
;
loginGicSsoUtils
.
userApiService
=
userApiService
;
loginGicSsoUtils
.
enterpriseApiService
=
enterpriseApiService
;
}
private
static
final
String
MENU_LOCAL_CACHE_KEY
=
"auth:menu:list:all"
;
/**
* 单点登录到gic
* @param enterpriseId gic商户ID
* @param redirectUrl gic后台的页面地址,前端提供,默认首页
* @return 返回跳转链接,前端直接跳转,到gic后台。如果返回null,说明错误
*/
public
static
String
sso
(
Integer
enterpriseId
,
String
redirectUrl
)
{
long
startTime
=
System
.
currentTimeMillis
();
String
nameSpace
=
"COMMON.4.0-gic-properties"
;
Config
config
=
ConfigService
.
getConfig
(
nameSpace
);
String
url
=
config
.
getProperty
(
"service_host"
,
""
).
replace
(
"/gic"
,
""
);
if
(
StringUtils
.
isBlank
(
redirectUrl
))
{
redirectUrl
=
url
+
"/damo-system"
;
// redirectUrl = "https://four.gicdev.com/cost-center/billing-center/overview";
}
String
token
;
UserDetailsVO
userDetailsVO
=
UserUtils
.
getUser
();
String
phone
=
userDetailsVO
.
getUserMobile
();
//运营人员国内,默认数据
ServiceResponse
<
UserDTO
>
userResult
=
loginGicSsoUtils
.
userApiService
.
getUserByPhoneNumber
(
Constants
.
NATION_CODE
,
phone
,
enterpriseId
);
if
(
userResult
.
isSuccess
())
{
//获取运营实施信息
UserDTO
user
=
userResult
.
getResult
();
if
(
user
==
null
)
{
//新建运营实施账号
UserDTO
temp
=
new
UserDTO
();
temp
.
setEnterpriseId
(
enterpriseId
);
temp
.
setPhoneNumber
(
phone
);
temp
.
setUserName
(
userDetailsVO
.
getRealName
());
temp
.
setPhoneAreaCode
(
Constants
.
NATION_CODE
);
temp
.
setSuperAdmin
(
1
);
temp
.
setLoginType
(
1
);
ServiceResponse
<
Integer
>
saveResult
=
loginGicSsoUtils
.
userApiService
.
saveOperationUser
(
temp
);
user
=
temp
;
user
.
setUserId
(
saveResult
.
getResult
());
}
else
{
//更新运营人名称
if
(!
user
.
getUserName
().
equals
(
userDetailsVO
.
getRealName
()))
{
loginGicSsoUtils
.
userApiService
.
updateOperationUser
(
user
.
getUserId
(),
userDetailsVO
.
getRealName
());
}
}
//gic用户信息塞入
UserDetail
userDetail
=
new
UserDetail
();
//设置登录用户信息
userDetail
.
setUserId
(
user
.
getUserId
());
userDetail
.
setUserInfo
(
EntityUtil
.
changeEntityNew
(
UserInfo
.
class
,
user
));
//设置企业资料
ServiceResponse
<
EnterpriseDTO
>
enterprise
=
loginGicSsoUtils
.
enterpriseApiService
.
getEnterpriseById
(
enterpriseId
);
if
(
enterprise
.
isSuccess
())
{
EnterpriseDTO
enterpriseDTO
=
enterprise
.
getResult
();
if
(
enterpriseDTO
!=
null
)
{
userDetail
.
setEnterpriseInfo
(
EntityUtil
.
changeEntityNew
(
EnterpriseInfo
.
class
,
enterpriseDTO
));
}
//设置权限
ServiceResponse
<
List
<
MenuDTO
>>
menuResult
=
loginGicSsoUtils
.
menuApiService
.
listUserMenu
(
user
.
getUserId
(),
enterpriseDTO
.
getVersionCode
());
if
(
menuResult
.
isSuccess
())
{
List
<
MenuDTO
>
menuList
=
menuResult
.
getResult
();
Set
<
Integer
>
menuIdSet
=
new
HashSet
<>(
2
);
if
(
CollectionUtils
.
isNotEmpty
(
menuList
))
{
menuIdSet
=
menuList
.
stream
().
filter
(
e
->
StringUtils
.
isNotBlank
(
e
.
getMenuUrl
()))
.
map
(
e
->
e
.
getMenuId
()).
collect
(
Collectors
.
toSet
());
}
//塞用户权限菜单值
userDetail
.
setMenuIdSet
(
menuIdSet
);
//塞本地缓存
setAllMenuToLocaleCache
();
}
}
//塞缓存
token
=
UserDetailUtils
.
setUserDetail
(
userDetail
);
LOGGER
.
info
(
"单点登录所花时间:{}"
,
System
.
currentTimeMillis
()
-
startTime
);
String
ssoLoginUrl
=
url
+
"/gic-auth-web/login-for-operation"
;
return
ssoLoginUrl
+
"?token="
+
token
+
"&redirectUrl="
+
redirectUrl
;
}
return
null
;
}
/**
* gic平台的菜单数据塞本地缓存
*/
private
static
void
setAllMenuToLocaleCache
()
{
ServiceResponse
<
List
<
MenuDTO
>>
response
=
loginGicSsoUtils
.
menuApiService
.
getAllMenu
();
if
(
response
.
isSuccess
())
{
List
<
MenuDTO
>
list
=
response
.
getResult
();
//gic平台的菜单数据塞本地缓存
RedisUtil
.
delLocalCache
(
MENU_LOCAL_CACHE_KEY
);
RedisUtil
.
setLocalCache
(
MENU_LOCAL_CACHE_KEY
,
EntityUtil
.
changeEntityListNew
(
MenuInfo
.
class
,
list
),
null
);
}
}
}
gic-enterprise-sso/src/main/resources/dubbo-gic-enterprise-sso-service.xml
0 → 100644
View file @
ba9e6c1d
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo=
"http://code.alibabatech.com/schema/dubbo"
xmlns:context=
"http://www.springframework.org/schema/context"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"
>
<context:component-scan
base-package=
"com.gic.sso.*"
/>
<!--<dubbo:reference interface="com.gic.enterprise.service.EnterpriseApiService" id="enterpriseApiService" timeout="6000"/>-->
<!--<dubbo:reference interface="com.gic.auth.service.UserApiService" id="userApiService" timeout="6000"/>-->
<!--<dubbo:reference interface="com.gic.auth.service.MenuApiService" id="menuApiService" timeout="6000"/>-->
</beans>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment