Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
loginservice
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
lanmw
loginservice
Commits
197e182c
Commit
197e182c
authored
Nov 29, 2024
by
xieshaohua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
前海电力项目sso初始化
parent
431a5802
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
557 additions
and
1 deletion
+557
-1
pom.xml
pom.xml
+1
-1
LoginApplication.java
src/main/java/com/keymobile/login/LoginApplication.java
+2
-0
ADApi.java
src/main/java/com/keymobile/login/api/ADApi.java
+222
-0
FeignClientConfig.java
...main/java/com/keymobile/login/conf/FeignClientConfig.java
+44
-0
Swagger2Config.java
src/main/java/com/keymobile/login/conf/Swagger2Config.java
+37
-0
LdapException.java
...ain/java/com/keymobile/login/exception/LdapException.java
+21
-0
LdapInfoRepository.java
...a/com/keymobile/login/persistence/LdapInfoRepository.java
+11
-0
LdapInfo.java
.../java/com/keymobile/login/persistence/model/LdapInfo.java
+81
-0
ADService.java
src/main/java/com/keymobile/login/service/ADService.java
+27
-0
AuthRemoteService.java
...n/java/com/keymobile/login/service/AuthRemoteService.java
+21
-0
ADServiceImpl.java
.../java/com/keymobile/login/service/impl/ADServiceImpl.java
+0
-0
AES.java
src/main/java/com/keymobile/login/util/AES.java
+90
-0
No files found.
pom.xml
View file @
197e182c
...
...
@@ -106,7 +106,7 @@
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
5.1.6
</version>
<version>
8.0.28
</version>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
...
...
src/main/java/com/keymobile/login/LoginApplication.java
View file @
197e182c
...
...
@@ -3,11 +3,13 @@ package com.keymobile.login;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.context.annotation.ComponentScan
;
@SpringBootApplication
@EnableDiscoveryClient
@ComponentScan
(
basePackages
=
{
"com.keymobile.login"
,
"com.keymobile.config.logging"
})
@EnableFeignClients
public
class
LoginApplication
{
public
static
void
main
(
String
[]
args
)
{
...
...
src/main/java/com/keymobile/login/api/ADApi.java
0 → 100644
View file @
197e182c
This diff is collapsed.
Click to expand it.
src/main/java/com/keymobile/login/conf/FeignClientConfig.java
0 → 100644
View file @
197e182c
package
com
.
keymobile
.
login
.
conf
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
feign.auth.BasicAuthRequestInterceptor
;
import
feign.codec.Decoder
;
import
org.springframework.beans.factory.ObjectFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.http.HttpMessageConverters
;
import
org.springframework.cloud.openfeign.support.ResponseEntityDecoder
;
import
org.springframework.cloud.openfeign.support.SpringDecoder
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
@Configuration
public
class
FeignClientConfig
{
@Value
(
"${security.authUser}"
)
private
String
authUser
;
@Value
(
"${security.authPwd}"
)
private
String
authPwd
;
@Bean
public
BasicAuthRequestInterceptor
getBasicAuthRequestInterceptor
()
{
return
new
BasicAuthRequestInterceptor
(
authUser
,
authPwd
);
}
@Bean
public
Decoder
feignDecoder
()
{
HttpMessageConverter
jacksonConverter
=
new
MappingJackson2HttpMessageConverter
(
customObjectMapper
());
ObjectFactory
<
HttpMessageConverters
>
objectFactory
=
()
->
new
HttpMessageConverters
(
jacksonConverter
);
return
new
ResponseEntityDecoder
(
new
SpringDecoder
(
objectFactory
));
}
public
ObjectMapper
customObjectMapper
()
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
objectMapper
.
enable
(
DeserializationFeature
.
ACCEPT_SINGLE_VALUE_AS_ARRAY
);
return
objectMapper
;
}
}
\ No newline at end of file
src/main/java/com/keymobile/login/conf/Swagger2Config.java
0 → 100644
View file @
197e182c
package
com
.
keymobile
.
login
.
conf
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.service.ApiInfo
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
@Configuration
@EnableSwagger2
public
class
Swagger2Config
{
@Bean
public
Docket
createRestApi
()
{
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
apiInfo
(
apiInfo
())
.
select
()
.
apis
(
RequestHandlerSelectors
.
basePackage
(
"com.keymobile.login.api"
))
.
paths
(
PathSelectors
.
any
())
.
build
();
}
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
.
title
(
"sso RESTful APIs"
)
.
description
(
"Spring Boot Swagger2"
)
.
termsOfServiceUrl
(
"http://www.keymobile.com.cn/"
)
// .contact("keymobile")
.
version
(
"1.0"
)
.
build
();
}
}
src/main/java/com/keymobile/login/exception/LdapException.java
0 → 100644
View file @
197e182c
package
com
.
keymobile
.
login
.
exception
;
/**
* @author xiesh
* @version 1.0.0
* @date 2024/11/21
* @desc
*/
public
class
LdapException
extends
Exception
{
private
static
final
long
serialVersionUID
=
1L
;
public
LdapException
(
String
errorMsg
)
{
super
(
errorMsg
);
}
public
LdapException
(
String
errorMsg
,
Throwable
cause
)
{
super
(
errorMsg
,
cause
);
}
}
src/main/java/com/keymobile/login/persistence/LdapInfoRepository.java
0 → 100644
View file @
197e182c
package
com
.
keymobile
.
login
.
persistence
;
import
com.keymobile.login.persistence.model.LdapInfo
;
import
org.springframework.data.repository.CrudRepository
;
import
javax.transaction.Transactional
;
@Transactional
public
interface
LdapInfoRepository
extends
CrudRepository
<
LdapInfo
,
String
>
{
}
src/main/java/com/keymobile/login/persistence/model/LdapInfo.java
0 → 100644
View file @
197e182c
package
com
.
keymobile
.
login
.
persistence
.
model
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
/**
* @author xiesh
* @version 1.0.0
* @date 2024/4/26
* @desc
*/
@Entity
@Table
(
name
=
"sso_ldap_info"
)
public
class
LdapInfo
{
@Id
private
String
id
;
@Column
(
name
=
"HOST"
,
nullable
=
false
)
private
String
host
;
@Column
(
name
=
"PORT"
,
nullable
=
false
)
private
String
port
;
@Column
(
name
=
"USER_NAME"
,
nullable
=
false
)
private
String
username
;
@Column
(
name
=
"PASSWORD"
,
nullable
=
false
)
private
String
password
;
@Column
(
name
=
"DN"
,
nullable
=
false
)
private
String
dn
;
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getHost
()
{
return
host
;
}
public
void
setHost
(
String
host
)
{
this
.
host
=
host
;
}
public
String
getPort
()
{
return
port
;
}
public
void
setPort
(
String
port
)
{
this
.
port
=
port
;
}
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
String
getDn
()
{
return
dn
;
}
public
void
setDn
(
String
dn
)
{
this
.
dn
=
dn
;
}
}
src/main/java/com/keymobile/login/service/ADService.java
0 → 100644
View file @
197e182c
package
com
.
keymobile
.
login
.
service
;
import
com.keymobile.login.persistence.model.LdapInfo
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
javax.servlet.http.HttpServletRequest
;
/**
* @author xiesh
* @version 1.0.0
* @date 2024/11/20
* @desc ad域服务
*/
public
interface
ADService
{
LdapInfo
saveLdapInfo
(
LdapInfo
ldapInfo
);
LdapInfo
getLdapInfo
();
void
deleteLdapInfo
();
String
ldapAuthentication
(
String
username
,
String
password
);
String
login
(
HttpServletRequest
request
,
String
username
,
String
password
)
;
}
src/main/java/com/keymobile/login/service/AuthRemoteService.java
0 → 100644
View file @
197e182c
package
com
.
keymobile
.
login
.
service
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
import
java.util.Map
;
@FeignClient
(
value
=
"authService"
)
public
interface
AuthRemoteService
{
@RequestMapping
(
value
=
"/users/findByName"
)
List
<
Map
<
String
,
Object
>>
getUserByName
(
@RequestParam
(
value
=
"match"
)
String
match
);
@PostMapping
(
value
=
"/users"
)
Map
<
String
,
Object
>
addUser
(
@RequestBody
Map
<
String
,
Object
>
user
);
@PostMapping
(
value
=
"/users/{userId}"
)
Map
<
String
,
Object
>
updateUser
(
@PathVariable
(
value
=
"userId"
)
Long
userId
,
@RequestBody
Map
<
String
,
Object
>
user
);
}
src/main/java/com/keymobile/login/service/impl/ADServiceImpl.java
0 → 100644
View file @
197e182c
This diff is collapsed.
Click to expand it.
src/main/java/com/keymobile/login/util/AES.java
0 → 100644
View file @
197e182c
package
com
.
keymobile
.
login
.
util
;
import
org.apache.commons.lang.StringUtils
;
import
sun.misc.BASE64Decoder
;
import
sun.misc.BASE64Encoder
;
import
javax.crypto.Cipher
;
import
javax.crypto.spec.SecretKeySpec
;
public
class
AES
{
//编码方式
public
static
final
String
CODE_TYPE
=
"UTF-8"
;
//填充类型
public
static
final
String
AES_TYPE
=
"AES/ECB/PKCS5Padding"
;
//私钥
private
static
String
AES_KEY
=
"4444111133332222"
;
//AES固定格式为128/192/256 bits.即:16/24/32bytes。DES固定格式为128bits,即8bytes。
/**
* 加密
*
* @param cleartext
* @return
*/
public
static
String
encrypt
(
String
cleartext
)
{
//加密方式: AES128(CBC/PKCS5Padding) + Base64, 私钥:1111222233334444
try
{
if
(
StringUtils
.
isNotBlank
(
cleartext
)){
//IvParameterSpec zeroIv = new IvParameterSpec(VIPARA.getBytes());
//两个参数,第一个为私钥字节数组, 第二个为加密方式 AES或者DES
SecretKeySpec
key
=
new
SecretKeySpec
(
AES_KEY
.
getBytes
(),
"AES"
);
//实例化加密类,参数为加密方式,要写全
Cipher
cipher
=
Cipher
.
getInstance
(
AES_TYPE
);
//PKCS5Padding比PKCS7Padding效率高,PKCS7Padding可支持IOS加解密
//初始化,此方法可以采用三种方式,按加密算法要求来添加。(1)无第三个参数(2)第三个参数为SecureRandom random = new SecureRandom();中random对象,随机数。(AES不可采用这种方法)(3)采用此代码中的IVParameterSpec
//加密时使用:ENCRYPT_MODE; 解密时使用:DECRYPT_MODE;
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
key
);
//CBC类型的可以在第三个参数传递偏移量zeroIv,ECB没有偏移量
//加密操作,返回加密后的字节数组,然后需要编码。主要编解码方式有Base64, HEX, UUE,7bit等等。此处看服务器需要什么编码方式
byte
[]
encryptedData
=
cipher
.
doFinal
(
cleartext
.
getBytes
(
CODE_TYPE
));
return
new
BASE64Encoder
().
encode
(
encryptedData
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
/**
* 解密
*
* @param encrypted
* @return
*/
public
static
String
decrypt
(
String
encrypted
)
{
try
{
if
(
StringUtils
.
isNotBlank
(
encrypted
)){
byte
[]
byteMi
=
new
BASE64Decoder
().
decodeBuffer
(
encrypted
);
//IvParameterSpec zeroIv = new IvParameterSpec(VIPARA.getBytes());
SecretKeySpec
key
=
new
SecretKeySpec
(
AES_KEY
.
getBytes
(),
"AES"
);
Cipher
cipher
=
Cipher
.
getInstance
(
AES_TYPE
);
//与加密时不同MODE:Cipher.DECRYPT_MODE
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
key
);
//CBC类型的可以在第三个参数传递偏移量zeroIv,ECB没有偏移量
byte
[]
decryptedData
=
cipher
.
doFinal
(
byteMi
);
return
new
String
(
decryptedData
,
CODE_TYPE
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
public
static
void
setAesKey
(
String
aesKey
){
AES_KEY
=
aesKey
;
}
/**
* 测试
*
* @param args
* @throws Exception
*/
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
pass
=
new
String
(
"Szse@pwd0528"
);
setAesKey
(
"4444111133332222"
);
System
.
out
.
println
(
"加密内容:"
+
encrypt
(
pass
));
String
content
=
new
String
(
encrypt
(
pass
));
System
.
out
.
println
(
"解密内容:"
+
decrypt
(
content
));
}
}
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