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
e4f80335
Commit
e4f80335
authored
Aug 05, 2024
by
chenzy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改】环境JDK21,language19,springboot版本升级
parent
e36ae21d
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
93 additions
and
74 deletions
+93
-74
pom.xml
pom.xml
+24
-20
LoginManagement.java
src/main/java/com/keymobile/login/api/LoginManagement.java
+14
-11
LogoutProcessHandler.java
...n/java/com/keymobile/login/conf/LogoutProcessHandler.java
+5
-5
RESTAuthenticationEntryPoint.java
...om/keymobile/login/conf/RESTAuthenticationEntryPoint.java
+3
-3
RESTAuthenticationFailureHandler.java
...eymobile/login/conf/RESTAuthenticationFailureHandler.java
+3
-3
RESTAuthenticationSuccessHandler.java
...eymobile/login/conf/RESTAuthenticationSuccessHandler.java
+6
-6
RESTLogoutSuccessHandler.java
...va/com/keymobile/login/conf/RESTLogoutSuccessHandler.java
+3
-4
SecurityConfig.java
src/main/java/com/keymobile/login/conf/SecurityConfig.java
+11
-22
UserDetailsServiceImpl.java
...a/com/keymobile/login/service/UserDetailsServiceImpl.java
+24
-0
No files found.
pom.xml
View file @
e4f80335
...
...
@@ -11,15 +11,15 @@
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
2.0.4.RELEASE
</version>
<relativePath/>
<version>
3.0.13
</version>
<relativePath
/>
</parent>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.reporting.outputEncoding>
UTF-8
</project.reporting.outputEncoding>
<!--<java.version>1.8</java.version>-->
<spring-cloud.version>
Finchley.RELEASE
</spring-cloud.version>
<spring-cloud.version>
2022.0.3
</spring-cloud.version>
</properties>
<!-- <repositories>-->
<!-- <repository>-->
...
...
@@ -32,6 +32,10 @@
<dependencies>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-bootstrap
</artifactId>
</dependency>
<dependency>
<groupId>
commons-io
</groupId>
...
...
@@ -52,10 +56,10 @@
<version>
1.2
</version>
</dependency>
<dependency>
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
</dependency>
-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
@@ -67,22 +71,22 @@
<artifactId>
commons-lang3
</artifactId>
<version>
3.7
</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.springfox</groupId>-->
<!-- <artifactId>springfox-swagger2</artifactId>-->
<!-- <version>2.5.0</version>-->
<!-- </dependency>-->
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
<version>
2.5.0
</version>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
<version>
2.2.2
</version>
<groupId>
org.springdoc
</groupId>
<artifactId>
springdoc-openapi-starter-webmvc-ui
</artifactId>
<version>
2.0.3
</version>
</dependency>
<!--引入oauth2-->
<dependency
>
<groupId>
com.fasterxml.jackson.core
</groupId
>
<artifactId>
jackson-core
</artifactId
>
<version>
2.10.2
</version
>
</dependency
>
<!-- <dependency>--
>
<!-- <groupId>com.fasterxml.jackson.core</groupId>--
>
<!-- <artifactId>jackson-core</artifactId>--
>
<!-- <version>2.10.2</version>--
>
<!-- </dependency>--
>
<dependency>
<groupId>
com.auth0
</groupId>
<artifactId>
java-jwt
</artifactId>
...
...
@@ -160,13 +164,13 @@
<dependency>
<groupId>
com.keymobile.auth
</groupId>
<artifactId>
security
</artifactId>
<version>
3.0.12-release
</version>
<version>
mr-1.0.0-beta
</version>
</dependency>
<dependency>
<groupId>
com.keymobile
</groupId>
<artifactId>
config
</artifactId>
<version>
1.1.2-release
</version>
<version>
mr-1.0.9-beta
</version>
</dependency>
<dependency>
...
...
src/main/java/com/keymobile/login/api/LoginManagement.java
View file @
e4f80335
...
...
@@ -3,9 +3,13 @@ package com.keymobile.login.api;
import
com.auth0.jwt.JWT
;
import
com.auth0.jwt.interfaces.Claim
;
import
com.auth0.jwt.interfaces.DecodedJWT
;
import
com.keymobile.auth.common.security.CustomizedUserDetailService
;
import
com.keymobile.login.oauth2.Oauth2Properties
;
import
com.keymobile.login.service.AuthService
;
import
com.keymobile.login.service.UserDetailsServiceImpl
;
import
jakarta.annotation.PostConstruct
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
import
jakarta.servlet.http.HttpSession
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -17,14 +21,14 @@ import org.springframework.security.web.authentication.WebAuthenticationDetails;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.client.RestTemplate
;
import
javax.annotation.PostConstruct
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
...
...
@@ -41,8 +45,7 @@ public class LoginManagement {
private
Oauth2Properties
oauth2Properties
;
@Autowired
private
CustomizedUserDetailService
customizedUserDetailService
;
private
UserDetailsServiceImpl
userDetailsService
;
@Autowired
private
AuthService
authService
;
...
...
@@ -50,7 +53,7 @@ public class LoginManagement {
@PostConstruct
public
void
init
()
{
restTemplate
=
new
RestTemplateBuilder
().
basicAuth
oriz
ation
(
oauth2Properties
.
getClientId
(),
oauth2Properties
.
getClientSecret
()).
build
();
restTemplate
=
new
RestTemplateBuilder
().
basicAuth
entic
ation
(
oauth2Properties
.
getClientId
(),
oauth2Properties
.
getClientSecret
()).
build
();
}
@RequestMapping
(
value
=
"sessionInfo"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
GET
})
...
...
@@ -138,7 +141,7 @@ public class LoginManagement {
toAdd
.
put
(
"password"
,
"37fa265330ad83eaa879efb1e2db6380896cf639"
);
authService
.
addUser
(
toAdd
);
}
UserDetails
userDetails
=
customizedUserDetail
Service
.
loadUserByUsername
(
userDetailByTokenInfo
.
get
(
"unique_name"
));
UserDetails
userDetails
=
userDetails
Service
.
loadUserByUsername
(
userDetailByTokenInfo
.
get
(
"unique_name"
));
UsernamePasswordAuthenticationToken
authentication
=
new
UsernamePasswordAuthenticationToken
(
userDetails
,
userDetails
.
getPassword
(),
userDetails
.
getAuthorities
());
authentication
.
setDetails
(
new
WebAuthenticationDetails
(
request
));
...
...
src/main/java/com/keymobile/login/conf/LogoutProcessHandler.java
View file @
e4f80335
...
...
@@ -2,6 +2,10 @@ package com.keymobile.login.conf;
import
com.keymobile.login.api.Constants
;
import
com.keymobile.login.oauth2.Oauth2Properties
;
import
jakarta.annotation.PostConstruct
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
import
jakarta.servlet.http.HttpSession
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -13,10 +17,6 @@ import org.springframework.security.web.authentication.logout.LogoutHandler;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.client.RestTemplate
;
import
javax.annotation.PostConstruct
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -33,7 +33,7 @@ public class LogoutProcessHandler implements LogoutHandler {
@PostConstruct
public
void
init
()
{
restTemplate
=
new
RestTemplateBuilder
().
basicAuth
oriz
ation
(
oauth2Properties
.
getClientId
(),
oauth2Properties
.
getClientSecret
()).
build
();
restTemplate
=
new
RestTemplateBuilder
().
basicAuth
entic
ation
(
oauth2Properties
.
getClientId
(),
oauth2Properties
.
getClientSecret
()).
build
();
MappingJackson2HttpMessageConverter
mappingJackson2HttpMessageConverter
=
new
MappingJackson2HttpMessageConverter
();
mappingJackson2HttpMessageConverter
.
setSupportedMediaTypes
(
Arrays
.
asList
(
MediaType
.
TEXT_HTML
,
...
...
src/main/java/com/keymobile/login/conf/RESTAuthenticationEntryPoint.java
View file @
e4f80335
package
com
.
keymobile
.
login
.
conf
;
import
jakarta.servlet.ServletException
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
import
org.springframework.security.core.AuthenticationException
;
import
org.springframework.security.web.AuthenticationEntryPoint
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
@Component
...
...
src/main/java/com/keymobile/login/conf/RESTAuthenticationFailureHandler.java
View file @
e4f80335
package
com
.
keymobile
.
login
.
conf
;
import
jakarta.servlet.ServletException
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
import
org.springframework.security.core.AuthenticationException
;
import
org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
@Component
...
...
src/main/java/com/keymobile/login/conf/RESTAuthenticationSuccessHandler.java
View file @
e4f80335
package
com
.
keymobile
.
login
.
conf
;
import
jakarta.servlet.ServletException
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
@Component
public
class
RESTAuthenticationSuccessHandler
extends
SimpleUrlAuthenticationSuccessHandler
{
@Value
(
"${security.allowRootLogin:true}"
)
private
boolean
rootAllowLogin
=
true
;
...
...
@@ -24,11 +24,11 @@ public class RESTAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuc
clearAuthenticationAttributes
(
request
);
String
returnStatus
=
"ok"
;
//check if allow root login
UserDetails
userDetails
=
(
UserDetails
)
authentication
.
getPrincipal
();
String
userNameWithIdAttached
=
userDetails
.
getUsername
();
if
(
userNameWithIdAttached
.
split
(
":"
)[
0
].
equalsIgnoreCase
(
"root"
)
&&
!
rootAllowLogin
)
&&
!
rootAllowLogin
)
returnStatus
=
"root not allow login"
;
PrintWriter
writer
=
response
.
getWriter
();
writer
.
write
(
returnStatus
);
...
...
src/main/java/com/keymobile/login/conf/RESTLogoutSuccessHandler.java
View file @
e4f80335
package
com
.
keymobile
.
login
.
conf
;
import
com.keymobile.login.oauth2.Oauth2Properties
;
import
jakarta.servlet.ServletException
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.web.authentication.logout.LogoutSuccessHandler
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
@Component
...
...
src/main/java/com/keymobile/login/conf/SecurityConfig.java
View file @
e4f80335
package
com
.
keymobile
.
login
.
conf
;
import
com.keymobile.auth.common.security.CustomizedUserDetailService
;
import
com.keymobile.login.api.Constants
;
import
com.keymobile.login.oauth2.Oauth2Properties
;
import
com.keymobile.login.service.UserDetailsServiceImpl
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.crypto.password.NoOpPasswordEncoder
;
import
org.springframework.security.web.authentication.logout.LogoutHandler
;
import
org.springframework.web.client.RestTemplate
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.springframework.security.web.SecurityFilterChain
;
@Configuration
@ComponentScan
(
"com.keymobile.auth.common.security"
)
public
class
SecurityConfig
extends
WebSecurityConfigurerAdapter
{
public
class
SecurityConfig
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
SecurityConfig
.
class
);
@Autowired
private
CustomizedUserDetailService
customUserDetail
Service
;
private
UserDetailsServiceImpl
userDetails
Service
;
@Autowired
private
RESTAuthenticationEntryPoint
authenticationEntryPoint
;
@Autowired
...
...
@@ -45,15 +33,15 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public
void
configure
(
AuthenticationManagerBuilder
auth
)
throws
Exception
{
auth
.
userDetailsService
(
customUserDetail
Service
).
passwordEncoder
(
NoOpPasswordEncoder
.
getInstance
());
auth
.
userDetailsService
(
userDetails
Service
).
passwordEncoder
(
NoOpPasswordEncoder
.
getInstance
());
}
@
Override
p
rotected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
@
Bean
p
ublic
SecurityFilterChain
securityFilterChain
(
HttpSecurity
http
)
throws
Exception
{
// http.authorizeRequests().anyRequest().authenticated();
http
.
authorizeRequests
()
.
an
tMatchers
(
"/login"
,
"/error"
,
"/signin"
,
"/signout"
,
"/oauth/**"
).
permitAll
()
.
authorize
Http
Requests
()
.
reques
tMatchers
(
"/login"
,
"/error"
,
"/signin"
,
"/signout"
,
"/oauth/**"
).
permitAll
()
.
anyRequest
().
authenticated
();
http
.
csrf
().
disable
();
...
...
@@ -64,6 +52,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
http
.
formLogin
().
loginProcessingUrl
(
"/signin"
);
http
.
logout
().
logoutUrl
(
"/signout"
);
http
.
logout
().
logoutSuccessHandler
(
logoutSuccessHandler
);
return
http
.
build
();
}
...
...
src/main/java/com/keymobile/login/service/UserDetailsServiceImpl.java
0 → 100644
View file @
e4f80335
package
com
.
keymobile
.
login
.
service
;
import
jakarta.annotation.PostConstruct
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl
;
import
org.springframework.stereotype.Repository
;
import
javax.sql.DataSource
;
@Repository
public
class
UserDetailsServiceImpl
extends
JdbcDaoImpl
implements
UserDetailsService
{
@Autowired
private
DataSource
dataSource
;
/**
* 初始化时,设置给父类
*/
@PostConstruct
private
void
initialize
()
{
setDataSource
(
dataSource
);
}
}
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