Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
BYOD
Project
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
tutingyin
BYOD
Commits
41635fed
Commit
41635fed
authored
May 14, 2024
by
tutingyin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: 客户端登录认证适配PC
parent
4e65c777
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
99 additions
and
1075 deletions
+99
-1075
UserAuthenticationFailureHandler.java
...authentication/user/UserAuthenticationFailureHandler.java
+4
-11
ImeiUserDetailsServiceImpl.java
.../authentication/user/imei/ImeiUserDetailsServiceImpl.java
+0
-88
OaidAuthenticationException.java
...authentication/user/oaid/OaidAuthenticationException.java
+0
-16
OaidAuthenticationFilter.java
...dm/authentication/user/oaid/OaidAuthenticationFilter.java
+0
-101
OaidAuthenticationProvider.java
.../authentication/user/oaid/OaidAuthenticationProvider.java
+0
-42
OaidAuthenticationToken.java
...mdm/authentication/user/oaid/OaidAuthenticationToken.java
+0
-65
OaidUserDetailsServiceImpl.java
.../authentication/user/oaid/OaidUserDetailsServiceImpl.java
+0
-77
UsernameAuthenticationFilter.java
.../authentication/user/qr/UsernameAuthenticationFilter.java
+11
-40
UsernameAuthenticationProvider.java
...uthentication/user/qr/UsernameAuthenticationProvider.java
+8
-43
UsernameAuthenticationToken.java
...m/authentication/user/qr/UsernameAuthenticationToken.java
+9
-22
UsernameDetailsServiceImpl.java
...dm/authentication/user/qr/UsernameDetailsServiceImpl.java
+3
-2
SerialAuthenticationException.java
...entication/user/serial/SerialAuthenticationException.java
+5
-4
SerialAuthenticationFilter.java
...uthentication/user/serial/SerialAuthenticationFilter.java
+19
-18
SerialAuthenticationProvider.java
...hentication/user/serial/SerialAuthenticationProvider.java
+10
-9
SerialAuthenticationToken.java
...authentication/user/serial/SerialAuthenticationToken.java
+6
-5
SerialUserDetailsServiceImpl.java
...hentication/user/serial/SerialUserDetailsServiceImpl.java
+13
-13
SMSCodeLoginException.java
...kr/mdm/authentication/user/sms/SMSCodeLoginException.java
+0
-12
SmsAuthenticationFilter.java
.../mdm/authentication/user/sms/SmsAuthenticationFilter.java
+0
-151
SmsAuthenticationProvider.java
...dm/authentication/user/sms/SmsAuthenticationProvider.java
+0
-0
SmsAuthenticationToken.java
...r/mdm/authentication/user/sms/SmsAuthenticationToken.java
+0
-70
SmsDetailsServiceImpl.java
...kr/mdm/authentication/user/sms/SmsDetailsServiceImpl.java
+0
-54
UuidAuthenticationException.java
...authentication/user/uuid/UuidAuthenticationException.java
+0
-16
UuidAuthenticationFilter.java
...dm/authentication/user/uuid/UuidAuthenticationFilter.java
+0
-100
UuidAuthenticationProvider.java
.../authentication/user/uuid/UuidAuthenticationProvider.java
+0
-42
UuidAuthenticationToken.java
...mdm/authentication/user/uuid/UuidAuthenticationToken.java
+0
-65
AntiReplayUtil.java
...cation/src/main/java/com/skr/mdm/util/AntiReplayUtil.java
+8
-7
RegisterEquipmentUtil.java
...src/main/java/com/skr/mdm/util/RegisterEquipmentUtil.java
+3
-2
No files found.
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/UserAuthenticationFailureHandler.java
View file @
41635fed
package
com
.
skr
.
mdm
.
authentication
.
user
;
package
com
.
skr
.
mdm
.
authentication
.
user
;
import
com.skr.mdm.authentication.user.imei.ImeiAuthenticationException
;
import
com.skr.mdm.authentication.user.serial.SerialAuthenticationException
;
import
com.skr.mdm.authentication.user.oaid.OaidAuthenticationException
;
import
com.skr.mdm.authentication.user.qr.NumberLimitException
;
import
com.skr.mdm.authentication.user.qr.NumberLimitException
;
import
com.skr.mdm.authentication.user.uuid.UuidAuthenticationException
;
import
com.skr.mdm.enums.ResultCodeEnum
;
import
com.skr.mdm.enums.ResultCodeEnum
;
import
com.skr.mdm.result.ResponseResult
;
import
com.skr.mdm.result.ResponseResult
;
import
com.skr.mdm.util.ResponseUtil
;
import
com.skr.mdm.util.ResponseUtil
;
...
@@ -28,15 +26,9 @@ public class UserAuthenticationFailureHandler implements AuthenticationFailureHa
...
@@ -28,15 +26,9 @@ public class UserAuthenticationFailureHandler implements AuthenticationFailureHa
public
void
onAuthenticationFailure
(
HttpServletRequest
request
,
HttpServletResponse
response
,
AuthenticationException
exception
)
throws
IOException
,
ServletException
{
public
void
onAuthenticationFailure
(
HttpServletRequest
request
,
HttpServletResponse
response
,
AuthenticationException
exception
)
throws
IOException
,
ServletException
{
ResponseResult
result
=
ResponseResult
.
failure
(
ResultCodeEnum
.
LOGIN_FAILURE
);
ResponseResult
result
=
ResponseResult
.
failure
(
ResultCodeEnum
.
LOGIN_FAILURE
);
if
(
exception
instanceof
Imei
AuthenticationException
)
{
if
(
exception
instanceof
Serial
AuthenticationException
)
{
result
=
ResponseResult
.
failure
(
ResultCodeEnum
.
IMEI_NONE
);
result
=
ResponseResult
.
failure
(
ResultCodeEnum
.
IMEI_NONE
);
}
}
if
(
exception
instanceof
OaidAuthenticationException
)
{
result
=
ResponseResult
.
failure
(
ResultCodeEnum
.
OAID_NONE
);
}
if
(
exception
instanceof
UuidAuthenticationException
)
{
result
=
ResponseResult
.
failure
(
ResultCodeEnum
.
UUID_NONE
);
}
if
(
exception
instanceof
NumberLimitException
)
{
if
(
exception
instanceof
NumberLimitException
)
{
result
=
ResponseResult
.
failure
(
ResultCodeEnum
.
NUMBER_OVER
);
result
=
ResponseResult
.
failure
(
ResultCodeEnum
.
NUMBER_OVER
);
}
}
...
@@ -48,4 +40,4 @@ public class UserAuthenticationFailureHandler implements AuthenticationFailureHa
...
@@ -48,4 +40,4 @@ public class UserAuthenticationFailureHandler implements AuthenticationFailureHa
}
}
\ No newline at end of file
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/imei/ImeiUserDetailsServiceImpl.java
deleted
100644 → 0
View file @
4e65c777
package
com
.
skr
.
mdm
.
authentication
.
user
.
imei
;
import
cn.hutool.core.collection.ListUtil
;
import
com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper
;
import
com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper
;
import
com.skr.mdm.bean.dto.UserLoginCallbackDTO
;
import
com.skr.mdm.dao.DeviceEquipmentDao
;
import
com.skr.mdm.dto.LoginUserDTO
;
import
com.skr.mdm.entity.DeviceEquipmentDO
;
import
com.skr.mdm.enums.DeleteStateEnum
;
import
com.skr.mdm.enums.EquipmentStateEnum
;
import
com.skr.mdm.rabbitmq.RabbitMQProvider
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
/**
* @author nfq
* @date 2020/7/15 10:58
*/
@Service
public
class
ImeiUserDetailsServiceImpl
implements
UserDetailsService
{
private
static
final
String
SPLIT
=
"-"
;
private
Integer
companyId
;
@Autowired
private
DeviceEquipmentDao
equipmentDao
;
@Autowired
private
RabbitMQProvider
rabbitMQProvider
;
@Override
public
UserDetails
loadUserByUsername
(
String
imei
)
throws
UsernameNotFoundException
{
if
(
StringUtils
.
isBlank
(
imei
)
||
companyId
==
null
)
{
throw
new
ImeiAuthenticationException
(
"imei为空:"
+
imei
+
"companyId:"
+
companyId
);
}
String
firstImei
=
imei
;
String
endImei
=
null
;
if
(
imei
.
contains
(
SPLIT
))
{
String
[]
split
=
StringUtils
.
split
(
firstImei
,
SPLIT
);
firstImei
=
split
[
0
];
endImei
=
split
[
1
];
}
DeviceEquipmentDO
deviceEquipmentDO
=
new
LambdaQueryChainWrapper
<>(
equipmentDao
)
.
eq
(
DeviceEquipmentDO:
:
getCompanyId
,
companyId
)
.
eq
(
DeviceEquipmentDO:
:
getImei
,
firstImei
)
.
eq
(
DeviceEquipmentDO:
:
getIsDelete
,
DeleteStateEnum
.
NON_DELETE
.
getState
())
.
one
();
if
(
deviceEquipmentDO
==
null
&&
StringUtils
.
isNotBlank
(
endImei
))
{
deviceEquipmentDO
=
new
LambdaQueryChainWrapper
<>(
equipmentDao
)
.
eq
(
DeviceEquipmentDO:
:
getCompanyId
,
companyId
)
.
eq
(
DeviceEquipmentDO:
:
getImei
,
endImei
)
.
eq
(
DeviceEquipmentDO:
:
getIsDelete
,
DeleteStateEnum
.
NON_DELETE
.
getState
())
.
one
();
}
if
(
deviceEquipmentDO
==
null
)
{
throw
new
ImeiAuthenticationException
(
"imei不存在:"
+
imei
+
"companyId:"
+
companyId
);
}
// 激活时间
if
(
EquipmentStateEnum
.
INACTIVATED
.
getState
().
equals
(
deviceEquipmentDO
.
getEquipmentState
()))
{
LambdaUpdateChainWrapper
<
DeviceEquipmentDO
>
updateChainWrapper
=
new
LambdaUpdateChainWrapper
<>(
equipmentDao
);
updateChainWrapper
.
set
(
DeviceEquipmentDO:
:
getActivationTime
,
new
Date
())
.
eq
(
DeviceEquipmentDO:
:
getId
,
deviceEquipmentDO
.
getId
())
.
update
();
// 异步拉取全局指令
UserLoginCallbackDTO
userLoginCallbackDTO
=
UserLoginCallbackDTO
.
builder
()
.
deviceIdList
(
ListUtil
.
toList
(
deviceEquipmentDO
.
getId
()))
.
departmentId
(
deviceEquipmentDO
.
getDepartmentId
())
.
companyId
(
deviceEquipmentDO
.
getCompanyId
())
.
build
();
rabbitMQProvider
.
publishRegisterEventWithDelayed
(
userLoginCallbackDTO
);
}
LoginUserDTO
loginUserDTO
=
new
LoginUserDTO
();
BeanUtils
.
copyProperties
(
deviceEquipmentDO
,
loginUserDTO
);
return
loginUserDTO
;
}
public
void
setCompanyId
(
Integer
companyId
)
{
this
.
companyId
=
companyId
;
}
}
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/oaid/OaidAuthenticationException.java
deleted
100644 → 0
View file @
4e65c777
package
com
.
skr
.
mdm
.
authentication
.
user
.
oaid
;
import
org.springframework.security.core.AuthenticationException
;
/**
* @author nfq
* @date 2021/1/29 15:22
*/
public
class
OaidAuthenticationException
extends
AuthenticationException
{
private
static
final
long
serialVersionUID
=
7614868747227090707L
;
public
OaidAuthenticationException
(
String
msg
)
{
super
(
msg
);
}
}
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/oaid/OaidAuthenticationFilter.java
deleted
100644 → 0
View file @
4e65c777
package
com
.
skr
.
mdm
.
authentication
.
user
.
oaid
;
import
cn.hutool.crypto.SmUtil
;
import
cn.hutool.crypto.asymmetric.KeyType
;
import
cn.hutool.crypto.asymmetric.SM2
;
import
cn.hutool.crypto.symmetric.SM4
;
import
com.skr.mdm.enums.MdmEncryptEnum
;
import
com.skr.mdm.util.SmUtils
;
import
io.swagger.models.HttpMethod
;
import
org.springframework.lang.Nullable
;
import
org.springframework.security.authentication.AuthenticationServiceException
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.AuthenticationException
;
import
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
;
import
org.springframework.security.web.util.matcher.AntPathRequestMatcher
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
/**
* @author nfq
* @date 2021/1/29 15:05
*/
public
class
OaidAuthenticationFilter
extends
AbstractAuthenticationProcessingFilter
{
public
static
final
String
SPRING_SECURITY_FORM_OAID_KEY
=
"oaid"
;
public
static
final
String
COMPANY_ID
=
"companyId"
;
public
static
final
String
SECRET_KEY
=
"secretKey"
;
private
final
String
oaidParameter
=
SPRING_SECURITY_FORM_OAID_KEY
;
private
final
String
companyIdParameter
=
COMPANY_ID
;
private
final
String
secretKeyParameter
=
SECRET_KEY
;
private
final
boolean
postOnly
=
true
;
private
SM4
sm4
=
null
;
private
String
mdmEncrypt
;
public
OaidAuthenticationFilter
()
{
super
(
new
AntPathRequestMatcher
(
"/oaid/login"
,
"POST"
));
}
@Override
public
Authentication
attemptAuthentication
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
AuthenticationException
,
IOException
,
ServletException
{
if
(
postOnly
&&
!
request
.
getMethod
().
equals
(
HttpMethod
.
POST
.
name
()))
{
throw
new
AuthenticationServiceException
(
"Authentication method not supported:"
+
request
.
getMethod
());
}
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
obtainSecretKey
(
request
);
}
String
oaid
=
obtainOaid
(
request
);
String
companyId
=
obtainCompanyId
(
request
);
if
(
oaid
==
null
)
{
oaid
=
""
;
}
oaid
=
oaid
.
trim
();
OaidAuthenticationToken
oaidAuthenticationToken
=
new
OaidAuthenticationToken
(
oaid
,
companyId
);
setDetails
(
request
,
oaidAuthenticationToken
);
return
this
.
getAuthenticationManager
().
authenticate
(
oaidAuthenticationToken
);
}
@Nullable
protected
String
obtainOaid
(
HttpServletRequest
request
)
{
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
return
sm4
.
decryptStr
(
request
.
getParameter
(
oaidParameter
));
}
return
request
.
getParameter
(
oaidParameter
);
}
@Nullable
protected
String
obtainCompanyId
(
HttpServletRequest
request
)
{
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
return
sm4
.
decryptStr
(
request
.
getParameter
(
companyIdParameter
));
}
return
request
.
getParameter
(
companyIdParameter
);
}
@Nullable
protected
String
obtainSecretKey
(
HttpServletRequest
request
)
{
String
secretKey
=
request
.
getHeader
(
secretKeyParameter
);
SM2
sm2
=
SmUtils
.
sm2Sign
();
byte
[]
secretKeyBytes
=
sm2
.
decrypt
(
secretKey
,
KeyType
.
PrivateKey
);
sm4
=
SmUtil
.
sm4
(
secretKeyBytes
);
return
request
.
getHeader
(
secretKeyParameter
);
}
protected
void
setDetails
(
HttpServletRequest
request
,
OaidAuthenticationToken
oaidAuthenticationToken
)
{
oaidAuthenticationToken
.
setDetails
(
authenticationDetailsSource
.
buildDetails
(
request
));
}
public
void
setMdmEncrypt
(
String
mdmEncrypt
)
{
this
.
mdmEncrypt
=
mdmEncrypt
;
}
}
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/oaid/OaidAuthenticationProvider.java
deleted
100644 → 0
View file @
4e65c777
package
com
.
skr
.
mdm
.
authentication
.
user
.
oaid
;
import
org.springframework.security.authentication.AuthenticationProvider
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.AuthenticationException
;
import
org.springframework.security.core.userdetails.UserDetails
;
/**
* @author nfq
* @date 2021/1/29 15:14
*/
public
class
OaidAuthenticationProvider
implements
AuthenticationProvider
{
private
OaidUserDetailsServiceImpl
userDetailsService
;
@Override
public
Authentication
authenticate
(
Authentication
authentication
)
throws
AuthenticationException
{
OaidAuthenticationToken
authenticationToken
=
(
OaidAuthenticationToken
)
authentication
;
String
principal
=
(
String
)
authenticationToken
.
getPrincipal
();
String
companyId
=
(
String
)
authenticationToken
.
getCompanyId
();
userDetailsService
.
setCompanyId
(
Integer
.
valueOf
(
companyId
));
// 校验oaid
UserDetails
userDetails
=
userDetailsService
.
loadUserByUsername
(
principal
);
if
(
userDetails
==
null
)
{
throw
new
OaidAuthenticationException
(
"UserDetailsService returned null, which is an interface contract violation"
);
}
OaidAuthenticationToken
authenticationResult
=
new
OaidAuthenticationToken
(
userDetails
.
getAuthorities
(),
userDetails
,
companyId
);
authenticationResult
.
setDetails
(
authentication
.
getDetails
());
return
authenticationResult
;
}
@Override
public
boolean
supports
(
Class
<?>
authentication
)
{
return
(
OaidAuthenticationToken
.
class
.
isAssignableFrom
(
authentication
));
}
public
void
setUserDetailsService
(
OaidUserDetailsServiceImpl
userDetailsService
)
{
this
.
userDetailsService
=
userDetailsService
;
}
}
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/oaid/OaidAuthenticationToken.java
deleted
100644 → 0
View file @
4e65c777
package
com
.
skr
.
mdm
.
authentication
.
user
.
oaid
;
import
org.springframework.security.authentication.AbstractAuthenticationToken
;
import
org.springframework.security.core.GrantedAuthority
;
import
java.util.Collection
;
/**
* @author nfq
* @date 2021/1/29 15:06
*/
public
class
OaidAuthenticationToken
extends
AbstractAuthenticationToken
{
private
static
final
long
serialVersionUID
=
2637723175472434118L
;
/**
* oaid
*/
private
final
Object
principal
;
private
final
Object
companyId
;
public
OaidAuthenticationToken
(
Object
principal
,
Object
companyId
)
{
super
(
null
);
this
.
principal
=
principal
;
this
.
companyId
=
companyId
;
setAuthenticated
(
false
);
}
/**
* Creates a token with the supplied array of authorities.
*
* @param authorities the collection of <tt>GrantedAuthority</tt>s for the principal
* represented by this authentication object.
* @param principal
*/
public
OaidAuthenticationToken
(
Collection
<?
extends
GrantedAuthority
>
authorities
,
Object
principal
,
Object
companyId
)
{
super
(
authorities
);
this
.
principal
=
principal
;
this
.
companyId
=
companyId
;
super
.
setAuthenticated
(
true
);
}
@Override
public
void
setAuthenticated
(
boolean
authenticated
)
{
super
.
setAuthenticated
(
authenticated
);
}
@Override
public
Object
getCredentials
()
{
return
null
;
}
@Override
public
Object
getPrincipal
()
{
return
this
.
principal
;
}
@Override
public
void
eraseCredentials
()
{
super
.
eraseCredentials
();
}
public
Object
getCompanyId
()
{
return
companyId
;
}
}
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/oaid/OaidUserDetailsServiceImpl.java
deleted
100644 → 0
View file @
4e65c777
package
com
.
skr
.
mdm
.
authentication
.
user
.
oaid
;
import
cn.hutool.core.collection.ListUtil
;
import
com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper
;
import
com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper
;
import
com.skr.mdm.bean.dto.UserLoginCallbackDTO
;
import
com.skr.mdm.dao.DeviceEquipmentDao
;
import
com.skr.mdm.dto.LoginUserDTO
;
import
com.skr.mdm.entity.DeviceEquipmentDO
;
import
com.skr.mdm.enums.DeleteStateEnum
;
import
com.skr.mdm.enums.EquipmentStateEnum
;
import
com.skr.mdm.rabbitmq.RabbitMQProvider
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
/**
* @author nfq
* @date 2021/1/29 15:15
*/
@Service
public
class
OaidUserDetailsServiceImpl
implements
UserDetailsService
{
private
Integer
companyId
;
@Autowired
private
DeviceEquipmentDao
equipmentDao
;
@Autowired
private
RabbitMQProvider
rabbitMQProvider
;
@Override
public
UserDetails
loadUserByUsername
(
String
oaid
)
throws
UsernameNotFoundException
{
if
(
StringUtils
.
isBlank
(
oaid
)
||
companyId
==
null
)
{
throw
new
OaidAuthenticationException
(
"oaid为空:"
+
oaid
+
"companyId:"
+
companyId
);
}
if
(
oaid
.
contains
(
"0000000000"
))
{
throw
new
OaidAuthenticationException
(
"非法的oaid:"
+
oaid
);
}
DeviceEquipmentDO
deviceEquipmentDO
=
new
LambdaQueryChainWrapper
<>(
equipmentDao
)
.
eq
(
DeviceEquipmentDO:
:
getOaid
,
oaid
)
.
eq
(
DeviceEquipmentDO:
:
getCompanyId
,
companyId
)
.
eq
(
DeviceEquipmentDO:
:
getIsDelete
,
DeleteStateEnum
.
NON_DELETE
.
getState
())
.
one
();
if
(
deviceEquipmentDO
==
null
)
{
throw
new
OaidAuthenticationException
(
"oaid不存在:"
+
oaid
+
"companyId:"
+
companyId
);
}
// 激活时间
if
(
EquipmentStateEnum
.
INACTIVATED
.
getState
().
equals
(
deviceEquipmentDO
.
getEquipmentState
()))
{
LambdaUpdateChainWrapper
<
DeviceEquipmentDO
>
updateChainWrapper
=
new
LambdaUpdateChainWrapper
<>(
equipmentDao
);
updateChainWrapper
.
set
(
DeviceEquipmentDO:
:
getActivationTime
,
new
Date
())
.
eq
(
DeviceEquipmentDO:
:
getId
,
deviceEquipmentDO
.
getId
())
.
update
();
// 异步拉取全局指令
UserLoginCallbackDTO
userLoginCallbackDTO
=
UserLoginCallbackDTO
.
builder
()
.
deviceIdList
(
ListUtil
.
toList
(
deviceEquipmentDO
.
getId
()))
.
companyId
(
deviceEquipmentDO
.
getCompanyId
())
.
departmentId
(
deviceEquipmentDO
.
getDepartmentId
())
.
build
();
rabbitMQProvider
.
publishRegisterEventWithDelayed
(
userLoginCallbackDTO
);
}
LoginUserDTO
loginUserDTO
=
new
LoginUserDTO
();
BeanUtils
.
copyProperties
(
deviceEquipmentDO
,
loginUserDTO
);
return
loginUserDTO
;
}
public
void
setCompanyId
(
Integer
companyId
)
{
this
.
companyId
=
companyId
;
}
}
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/qr/UsernameAuthenticationFilter.java
View file @
41635fed
...
@@ -27,9 +27,7 @@ public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessi
...
@@ -27,9 +27,7 @@ public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessi
public
static
final
String
SPRING_SECURITY_FORM_USERNAME_KEY
=
"username"
;
public
static
final
String
SPRING_SECURITY_FORM_USERNAME_KEY
=
"username"
;
public
static
final
String
SPRING_SECURITY_FORM_PASSWORD_KEY
=
"password"
;
public
static
final
String
SPRING_SECURITY_FORM_PASSWORD_KEY
=
"password"
;
public
static
final
String
IMEI
=
"imei"
;
public
static
final
String
SERIAL
=
"serial"
;
public
static
final
String
OAID
=
"oaid"
;
public
static
final
String
UUID
=
"uuid"
;
public
static
final
String
LOGIN_METHOD
=
"loginMethod"
;
public
static
final
String
LOGIN_METHOD
=
"loginMethod"
;
public
static
final
String
COMPANY_ID
=
"companyId"
;
public
static
final
String
COMPANY_ID
=
"companyId"
;
...
@@ -38,9 +36,7 @@ public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessi
...
@@ -38,9 +36,7 @@ public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessi
private
String
usernameParameter
=
SPRING_SECURITY_FORM_USERNAME_KEY
;
private
String
usernameParameter
=
SPRING_SECURITY_FORM_USERNAME_KEY
;
private
String
passwordParameter
=
SPRING_SECURITY_FORM_PASSWORD_KEY
;
private
String
passwordParameter
=
SPRING_SECURITY_FORM_PASSWORD_KEY
;
private
String
imeiParameter
=
IMEI
;
private
String
serialParameter
=
SERIAL
;
private
final
String
oaidParameter
=
OAID
;
private
final
String
uuidParameter
=
UUID
;
private
String
loginMethodParameter
=
LOGIN_METHOD
;
private
String
loginMethodParameter
=
LOGIN_METHOD
;
private
final
String
companyIdParameter
=
COMPANY_ID
;
private
final
String
companyIdParameter
=
COMPANY_ID
;
private
final
String
secretKeyParameter
=
SECRET_KEY
;
private
final
String
secretKeyParameter
=
SECRET_KEY
;
...
@@ -66,9 +62,7 @@ public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessi
...
@@ -66,9 +62,7 @@ public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessi
}
}
String
username
=
obtainUsername
(
request
);
String
username
=
obtainUsername
(
request
);
String
password
=
obtainPassword
(
request
);
String
password
=
obtainPassword
(
request
);
String
imei
=
obtainImei
(
request
);
String
serialNumber
=
obtainSerialNumber
(
request
);
String
oaid
=
obtainOaid
(
request
);
String
uuid
=
obtainUuid
(
request
);
String
loginMethod
=
obtainLoginMethod
(
request
);
String
loginMethod
=
obtainLoginMethod
(
request
);
String
companyId
=
obtainCompanyId
(
request
);
String
companyId
=
obtainCompanyId
(
request
);
...
@@ -80,16 +74,8 @@ public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessi
...
@@ -80,16 +74,8 @@ public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessi
password
=
""
;
password
=
""
;
}
}
if
(
imei
==
null
)
{
if
(
serialNumber
==
null
)
{
imei
=
""
;
serialNumber
=
""
;
}
if
(
oaid
==
null
)
{
oaid
=
""
;
}
if
(
uuid
==
null
)
{
uuid
=
""
;
}
}
if
(
loginMethod
==
null
)
{
if
(
loginMethod
==
null
)
{
...
@@ -101,7 +87,7 @@ public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessi
...
@@ -101,7 +87,7 @@ public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessi
}
}
username
=
username
.
trim
();
username
=
username
.
trim
();
UsernameAuthenticationToken
authRequest
=
new
UsernameAuthenticationToken
(
username
,
password
,
imei
,
oaid
,
uuid
,
loginMethod
,
companyId
);
UsernameAuthenticationToken
authRequest
=
new
UsernameAuthenticationToken
(
username
,
password
,
serialNumber
,
loginMethod
,
companyId
);
// Allow subclasses to set the "details" property
// Allow subclasses to set the "details" property
setDetails
(
request
,
authRequest
);
setDetails
(
request
,
authRequest
);
...
@@ -135,27 +121,11 @@ public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessi
...
@@ -135,27 +121,11 @@ public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessi
}
}
@Nullable
@Nullable
protected
String
obtainImei
(
HttpServletRequest
request
)
{
protected
String
obtainSerialNumber
(
HttpServletRequest
request
)
{
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
return
sm4
.
decryptStr
(
request
.
getParameter
(
imeiParameter
));
}
return
request
.
getParameter
(
imeiParameter
);
}
@Nullable
protected
String
obtainOaid
(
HttpServletRequest
request
)
{
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
return
sm4
.
decryptStr
(
request
.
getParameter
(
oaidParameter
));
}
return
request
.
getParameter
(
oaidParameter
);
}
@Nullable
protected
String
obtainUuid
(
HttpServletRequest
request
)
{
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
return
sm4
.
decryptStr
(
request
.
getParameter
(
uuid
Parameter
));
return
sm4
.
decryptStr
(
request
.
getParameter
(
serial
Parameter
));
}
}
return
request
.
getParameter
(
uuid
Parameter
);
return
request
.
getParameter
(
serial
Parameter
);
}
}
@Nullable
@Nullable
...
@@ -182,4 +152,4 @@ public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessi
...
@@ -182,4 +152,4 @@ public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessi
public
void
setMdmEncrypt
(
String
mdmEncrypt
)
{
public
void
setMdmEncrypt
(
String
mdmEncrypt
)
{
this
.
mdmEncrypt
=
mdmEncrypt
;
this
.
mdmEncrypt
=
mdmEncrypt
;
}
}
}
}
\ No newline at end of file
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/qr/UsernameAuthenticationProvider.java
View file @
41635fed
...
@@ -59,9 +59,7 @@ public class UsernameAuthenticationProvider implements AuthenticationProvider {
...
@@ -59,9 +59,7 @@ public class UsernameAuthenticationProvider implements AuthenticationProvider {
.
userName
(
equipmentDO
.
getUserName
())
.
userName
(
equipmentDO
.
getUserName
())
.
departmentName
(
equipmentDO
.
getDepartmentName
())
.
departmentName
(
equipmentDO
.
getDepartmentName
())
.
companyName
(
companyDO
.
getCompanyName
())
.
companyName
(
companyDO
.
getCompanyName
())
.
imei
(
equipmentDO
.
getImei
())
.
serialNum
(
equipmentDO
.
getSerialNumber
())
.
oaid
(
equipmentDO
.
getOaid
())
.
uuid
(
equipmentDO
.
getUuid
())
.
build
();
.
build
();
RegisterEquipmentUtil
.
registerGaodeTerminal
(
gaodeTerminalQO
,
equipmentDO
);
RegisterEquipmentUtil
.
registerGaodeTerminal
(
gaodeTerminalQO
,
equipmentDO
);
}
}
...
@@ -73,9 +71,7 @@ public class UsernameAuthenticationProvider implements AuthenticationProvider {
...
@@ -73,9 +71,7 @@ public class UsernameAuthenticationProvider implements AuthenticationProvider {
UsernameAuthenticationToken
authenticationToken
=
(
UsernameAuthenticationToken
)
authentication
;
UsernameAuthenticationToken
authenticationToken
=
(
UsernameAuthenticationToken
)
authentication
;
String
principal
=
(
String
)
authenticationToken
.
getPrincipal
();
String
principal
=
(
String
)
authenticationToken
.
getPrincipal
();
Object
credentials
=
authenticationToken
.
getCredentials
();
Object
credentials
=
authenticationToken
.
getCredentials
();
String
imei
=
(
String
)
authenticationToken
.
getImei
();
String
serialNumber
=
(
String
)
authenticationToken
.
getSerialNum
();
String
oaid
=
(
String
)
authenticationToken
.
getOaid
();
String
uuid
=
(
String
)
authenticationToken
.
getUuid
();
String
loginMethod
=
(
String
)
authenticationToken
.
getLoginMethod
();
String
loginMethod
=
(
String
)
authenticationToken
.
getLoginMethod
();
String
companyId
=
(
String
)
authenticationToken
.
getCompanyId
();
String
companyId
=
(
String
)
authenticationToken
.
getCompanyId
();
...
@@ -83,44 +79,15 @@ public class UsernameAuthenticationProvider implements AuthenticationProvider {
...
@@ -83,44 +79,15 @@ public class UsernameAuthenticationProvider implements AuthenticationProvider {
String
loginType
=
""
;
String
loginType
=
""
;
// 检查imei oaid UUID是否注册
// 检查imei oaid UUID是否注册
DeviceEquipmentDO
equipmentDO
=
null
;
DeviceEquipmentDO
equipmentDO
=
null
;
if
(
StringUtils
.
isNotBlank
(
imei
))
{
if
(
StringUtils
.
isNotBlank
(
serialNumber
))
{
loginType
=
"imei:"
+
imei
;
loginType
=
"serialNumber:"
+
serialNumber
;
String
endImei
=
null
;
if
(
imei
.
contains
(
"-"
))
{
String
[]
split
=
StringUtils
.
split
(
imei
,
"-"
);
imei
=
split
[
0
];
endImei
=
split
[
1
];
}
equipmentDO
=
new
LambdaQueryChainWrapper
<>(
equipmentDao
)
.
eq
(
DeviceEquipmentDO:
:
getImei
,
imei
)
.
eq
(
DeviceEquipmentDO:
:
getIsDelete
,
DeleteStateEnum
.
NON_DELETE
.
getState
())
.
eq
(
DeviceEquipmentDO:
:
getCompanyId
,
Integer
.
valueOf
(
companyId
))
.
one
();
if
(
equipmentDO
==
null
&&
StringUtils
.
isNotBlank
(
endImei
))
{
equipmentDO
=
new
LambdaQueryChainWrapper
<>(
equipmentDao
)
.
eq
(
DeviceEquipmentDO:
:
getCompanyId
,
companyId
)
.
eq
(
DeviceEquipmentDO:
:
getImei
,
endImei
)
.
eq
(
DeviceEquipmentDO:
:
getIsDelete
,
DeleteStateEnum
.
NON_DELETE
.
getState
())
.
one
();
}
}
if
(
Objects
.
isNull
(
equipmentDO
)
&&
StringUtils
.
isNotBlank
(
oaid
))
{
loginType
=
"oaid:"
+
oaid
;
equipmentDO
=
new
LambdaQueryChainWrapper
<>(
equipmentDao
)
.
eq
(
DeviceEquipmentDO:
:
getOaid
,
oaid
)
.
eq
(
DeviceEquipmentDO:
:
getIsDelete
,
DeleteStateEnum
.
NON_DELETE
.
getState
())
.
eq
(
DeviceEquipmentDO:
:
getCompanyId
,
Integer
.
valueOf
(
companyId
))
.
one
();
}
if
(
Objects
.
isNull
(
equipmentDO
)
&&
StringUtils
.
isNotBlank
(
uuid
))
{
loginType
=
"uuid:"
+
uuid
;
equipmentDO
=
new
LambdaQueryChainWrapper
<>(
equipmentDao
)
equipmentDO
=
new
LambdaQueryChainWrapper
<>(
equipmentDao
)
.
eq
(
DeviceEquipmentDO:
:
get
Uuid
,
uuid
)
.
eq
(
DeviceEquipmentDO:
:
get
SerialNumber
,
serialNumber
)
.
eq
(
DeviceEquipmentDO:
:
getIsDelete
,
DeleteStateEnum
.
NON_DELETE
.
getState
())
.
eq
(
DeviceEquipmentDO:
:
getIsDelete
,
DeleteStateEnum
.
NON_DELETE
.
getState
())
.
eq
(
DeviceEquipmentDO:
:
getCompanyId
,
Integer
.
valueOf
(
companyId
))
.
eq
(
DeviceEquipmentDO:
:
getCompanyId
,
Integer
.
valueOf
(
companyId
))
.
one
();
.
one
();
}
}
//
imei oaid uuid有一个唯一标识即可
//
serialNum 唯一标识
if
(
equipmentDO
==
null
)
{
if
(
equipmentDO
==
null
)
{
// 校验用户名
// 校验用户名
userDetailsService
.
setCompanyId
(
Integer
.
valueOf
(
companyId
));
userDetailsService
.
setCompanyId
(
Integer
.
valueOf
(
companyId
));
...
@@ -149,9 +116,7 @@ public class UsernameAuthenticationProvider implements AuthenticationProvider {
...
@@ -149,9 +116,7 @@ public class UsernameAuthenticationProvider implements AuthenticationProvider {
equipmentDO
.
setDepartmentName
(
loginUserDTO
.
getDepartmentName
());
equipmentDO
.
setDepartmentName
(
loginUserDTO
.
getDepartmentName
());
equipmentDO
.
setCompanyId
(
loginUserDTO
.
getCompanyId
());
equipmentDO
.
setCompanyId
(
loginUserDTO
.
getCompanyId
());
equipmentDO
.
setEquipmentType
(
EquipmentTypeEnum
.
CELL_PHONE
.
getType
());
equipmentDO
.
setEquipmentType
(
EquipmentTypeEnum
.
CELL_PHONE
.
getType
());
equipmentDO
.
setImei
(
imei
);
equipmentDO
.
setSerialNumber
(
serialNumber
);
equipmentDO
.
setOaid
(
oaid
);
equipmentDO
.
setUuid
(
uuid
);
equipmentDO
.
setActivationTime
(
new
Date
());
equipmentDO
.
setActivationTime
(
new
Date
());
String
equipmentName
=
getEquipmentName
(
loginUserDTO
.
getUserId
(),
equipmentDO
.
getUserName
(),
Integer
.
valueOf
(
companyId
));
String
equipmentName
=
getEquipmentName
(
loginUserDTO
.
getUserId
(),
equipmentDO
.
getUserName
(),
Integer
.
valueOf
(
companyId
));
equipmentDO
.
setEquipmentName
(
equipmentName
);
equipmentDO
.
setEquipmentName
(
equipmentName
);
...
@@ -167,7 +132,7 @@ public class UsernameAuthenticationProvider implements AuthenticationProvider {
...
@@ -167,7 +132,7 @@ public class UsernameAuthenticationProvider implements AuthenticationProvider {
pushUserLoginEvent
(
equipmentDO
,
loginUserDTO
);
pushUserLoginEvent
(
equipmentDO
,
loginUserDTO
);
}
}
UsernameAuthenticationToken
authenticationResult
=
new
UsernameAuthenticationToken
(
userDetails
.
getAuthorities
(),
userDetails
,
imei
,
oaid
,
uuid
,
companyId
);
UsernameAuthenticationToken
authenticationResult
=
new
UsernameAuthenticationToken
(
userDetails
.
getAuthorities
(),
userDetails
,
serialNumber
,
companyId
);
authenticationResult
.
setDetails
(
authentication
.
getDetails
());
authenticationResult
.
setDetails
(
authentication
.
getDetails
());
return
authenticationResult
;
return
authenticationResult
;
}
}
...
...
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/qr/UsernameAuthenticationToken.java
View file @
41635fed
...
@@ -15,30 +15,24 @@ public class UsernameAuthenticationToken extends AbstractAuthenticationToken {
...
@@ -15,30 +15,24 @@ public class UsernameAuthenticationToken extends AbstractAuthenticationToken {
private
final
Object
principal
;
private
final
Object
principal
;
private
Object
credentials
;
private
Object
credentials
;
private
final
Object
imei
;
private
final
Object
serialNum
;
private
final
Object
oaid
;
private
final
Object
uuid
;
private
Object
loginMethod
;
private
Object
loginMethod
;
private
final
Object
companyId
;
private
final
Object
companyId
;
public
UsernameAuthenticationToken
(
Object
principal
,
Object
credentials
,
Object
imei
,
Object
oaid
,
Object
uuid
,
Object
loginMethod
,
Object
companyId
)
{
public
UsernameAuthenticationToken
(
Object
principal
,
Object
credentials
,
Object
serialNum
,
Object
loginMethod
,
Object
companyId
)
{
super
(
null
);
super
(
null
);
this
.
principal
=
principal
;
this
.
principal
=
principal
;
this
.
credentials
=
credentials
;
this
.
credentials
=
credentials
;
this
.
imei
=
imei
;
this
.
serialNum
=
serialNum
;
this
.
oaid
=
oaid
;
this
.
uuid
=
uuid
;
this
.
loginMethod
=
loginMethod
;
this
.
loginMethod
=
loginMethod
;
this
.
companyId
=
companyId
;
this
.
companyId
=
companyId
;
setAuthenticated
(
false
);
setAuthenticated
(
false
);
}
}
public
UsernameAuthenticationToken
(
Collection
<?
extends
GrantedAuthority
>
authorities
,
Object
principal
,
Object
imei
,
Object
oaid
,
Object
uuid
,
Object
companyId
)
{
public
UsernameAuthenticationToken
(
Collection
<?
extends
GrantedAuthority
>
authorities
,
Object
principal
,
Object
serialNum
,
Object
companyId
)
{
super
(
authorities
);
super
(
authorities
);
this
.
principal
=
principal
;
this
.
principal
=
principal
;
this
.
imei
=
imei
;
this
.
serialNum
=
serialNum
;
this
.
oaid
=
oaid
;
this
.
uuid
=
uuid
;
this
.
companyId
=
companyId
;
this
.
companyId
=
companyId
;
super
.
setAuthenticated
(
true
);
super
.
setAuthenticated
(
true
);
}
}
...
@@ -58,23 +52,15 @@ public class UsernameAuthenticationToken extends AbstractAuthenticationToken {
...
@@ -58,23 +52,15 @@ public class UsernameAuthenticationToken extends AbstractAuthenticationToken {
super
.
setAuthenticated
(
isAuthenticated
);
super
.
setAuthenticated
(
isAuthenticated
);
}
}
public
Object
get
Imei
()
{
public
Object
get
SerialNum
()
{
return
this
.
imei
;
return
this
.
serialNum
;
}
}
public
Object
getLoginMethod
()
{
public
Object
getLoginMethod
()
{
return
loginMethod
;
return
loginMethod
;
}
}
public
Object
getOaid
()
{
return
oaid
;
}
public
Object
getUuid
()
{
return
uuid
;
}
public
Object
getCompanyId
()
{
public
Object
getCompanyId
()
{
return
companyId
;
return
companyId
;
}
}
}
}
\ No newline at end of file
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/qr/UsernameDetailsServiceImpl.java
View file @
41635fed
...
@@ -31,7 +31,7 @@ public class UsernameDetailsServiceImpl implements UserDetailsService {
...
@@ -31,7 +31,7 @@ public class UsernameDetailsServiceImpl implements UserDetailsService {
throw
new
UsernameNotFoundException
(
"username为空:"
+
username
+
"companyId:"
+
companyId
);
throw
new
UsernameNotFoundException
(
"username为空:"
+
username
+
"companyId:"
+
companyId
);
}
}
AuUserDO
userDO
=
new
LambdaQueryChainWrapper
<>(
userDao
)
AuUserDO
userDO
=
new
LambdaQueryChainWrapper
<>(
userDao
)
.
eq
(
AuUserDO:
:
get
PhoneNumber
,
username
)
.
eq
(
AuUserDO:
:
get
UserName
,
username
)
.
eq
(
AuUserDO:
:
getIsDelete
,
DeleteStateEnum
.
NON_DELETE
.
getState
())
.
eq
(
AuUserDO:
:
getIsDelete
,
DeleteStateEnum
.
NON_DELETE
.
getState
())
.
eq
(
AuUserDO:
:
getCompanyId
,
companyId
)
.
eq
(
AuUserDO:
:
getCompanyId
,
companyId
)
.
one
();
.
one
();
...
@@ -50,4 +50,4 @@ public class UsernameDetailsServiceImpl implements UserDetailsService {
...
@@ -50,4 +50,4 @@ public class UsernameDetailsServiceImpl implements UserDetailsService {
public
void
setCompanyId
(
Integer
companyId
)
{
public
void
setCompanyId
(
Integer
companyId
)
{
this
.
companyId
=
companyId
;
this
.
companyId
=
companyId
;
}
}
}
}
\ No newline at end of file
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/
imei/Imei
AuthenticationException.java
→
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/
serial/Serial
AuthenticationException.java
View file @
41635fed
package
com
.
skr
.
mdm
.
authentication
.
user
.
imei
;
package
com
.
skr
.
mdm
.
authentication
.
user
.
serial
;
import
org.springframework.security.core.AuthenticationException
;
import
org.springframework.security.core.AuthenticationException
;
...
@@ -6,12 +6,12 @@ import org.springframework.security.core.AuthenticationException;
...
@@ -6,12 +6,12 @@ import org.springframework.security.core.AuthenticationException;
* @author nfq
* @author nfq
* @date 2020/7/16 14:47
* @date 2020/7/16 14:47
*/
*/
public
class
Imei
AuthenticationException
extends
AuthenticationException
{
public
class
Serial
AuthenticationException
extends
AuthenticationException
{
private
static
final
long
serialVersionUID
=
-
3323794937564446615L
;
private
static
final
long
serialVersionUID
=
-
3323794937564446615L
;
public
Imei
AuthenticationException
(
String
msg
)
{
public
Serial
AuthenticationException
(
String
msg
)
{
super
(
msg
);
super
(
msg
);
}
}
}
}
\ No newline at end of file
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/
imei/Imei
AuthenticationFilter.java
→
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/
serial/Serial
AuthenticationFilter.java
View file @
41635fed
package
com
.
skr
.
mdm
.
authentication
.
user
.
imei
;
package
com
.
skr
.
mdm
.
authentication
.
user
.
serial
;
import
cn.hutool.crypto.SmUtil
;
import
cn.hutool.crypto.SmUtil
;
import
cn.hutool.crypto.asymmetric.KeyType
;
import
cn.hutool.crypto.asymmetric.KeyType
;
...
@@ -23,14 +23,14 @@ import java.io.IOException;
...
@@ -23,14 +23,14 @@ import java.io.IOException;
* @author nfq
* @author nfq
* @date 2020/7/15 10:10
* @date 2020/7/15 10:10
*/
*/
public
class
Imei
AuthenticationFilter
extends
AbstractAuthenticationProcessingFilter
{
public
class
Serial
AuthenticationFilter
extends
AbstractAuthenticationProcessingFilter
{
public
static
final
String
SPRING_SECURITY_FORM_IMEI_KEY
=
"
imei
"
;
public
static
final
String
SPRING_SECURITY_FORM_IMEI_KEY
=
"
serialNum
"
;
public
static
final
String
COMPANY_ID
=
"companyId"
;
public
static
final
String
COMPANY_ID
=
"companyId"
;
public
static
final
String
SECRET_KEY
=
"secretKey"
;
public
static
final
String
SECRET_KEY
=
"secretKey"
;
private
final
String
imei
Parameter
=
SPRING_SECURITY_FORM_IMEI_KEY
;
private
final
String
serialNum
Parameter
=
SPRING_SECURITY_FORM_IMEI_KEY
;
private
final
String
companyIdParameter
=
COMPANY_ID
;
private
final
String
companyIdParameter
=
COMPANY_ID
;
private
final
String
secretKeyParameter
=
SECRET_KEY
;
private
final
String
secretKeyParameter
=
SECRET_KEY
;
...
@@ -41,8 +41,8 @@ public class ImeiAuthenticationFilter extends AbstractAuthenticationProcessingFi
...
@@ -41,8 +41,8 @@ public class ImeiAuthenticationFilter extends AbstractAuthenticationProcessingFi
private
String
mdmEncrypt
;
private
String
mdmEncrypt
;
public
Imei
AuthenticationFilter
()
{
public
Serial
AuthenticationFilter
()
{
super
(
new
AntPathRequestMatcher
(
"/
imei
/login"
,
"POST"
));
super
(
new
AntPathRequestMatcher
(
"/
serial
/login"
,
"POST"
));
}
}
@Override
@Override
...
@@ -55,27 +55,27 @@ public class ImeiAuthenticationFilter extends AbstractAuthenticationProcessingFi
...
@@ -55,27 +55,27 @@ public class ImeiAuthenticationFilter extends AbstractAuthenticationProcessingFi
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
obtainSecretKey
(
request
);
obtainSecretKey
(
request
);
}
}
String
imei
=
obtainImei
(
request
);
String
serialNumber
=
obtainImei
(
request
);
String
companyId
=
obtainCompanyId
(
request
);
String
companyId
=
obtainCompanyId
(
request
);
if
(
imei
==
null
)
{
if
(
serialNumber
==
null
)
{
imei
=
""
;
serialNumber
=
""
;
}
}
imei
=
imei
.
trim
();
serialNumber
=
serialNumber
.
trim
();
ImeiAuthenticationToken
imeiAuthenticationToken
=
new
ImeiAuthenticationToken
(
imei
,
companyId
);
SerialAuthenticationToken
serialAuthenticationToken
=
new
SerialAuthenticationToken
(
serialNumber
,
companyId
);
setDetails
(
request
,
imei
AuthenticationToken
);
setDetails
(
request
,
serial
AuthenticationToken
);
return
this
.
getAuthenticationManager
().
authenticate
(
imei
AuthenticationToken
);
return
this
.
getAuthenticationManager
().
authenticate
(
serial
AuthenticationToken
);
}
}
@Nullable
@Nullable
protected
String
obtainImei
(
HttpServletRequest
request
)
{
protected
String
obtainImei
(
HttpServletRequest
request
)
{
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
return
sm4
.
decryptStr
(
request
.
getParameter
(
imei
Parameter
));
return
sm4
.
decryptStr
(
request
.
getParameter
(
serialNum
Parameter
));
}
}
return
request
.
getParameter
(
imei
Parameter
);
return
request
.
getParameter
(
serialNum
Parameter
);
}
}
@Nullable
@Nullable
...
@@ -95,11 +95,11 @@ public class ImeiAuthenticationFilter extends AbstractAuthenticationProcessingFi
...
@@ -95,11 +95,11 @@ public class ImeiAuthenticationFilter extends AbstractAuthenticationProcessingFi
return
request
.
getHeader
(
secretKeyParameter
);
return
request
.
getHeader
(
secretKeyParameter
);
}
}
protected
void
setDetails
(
HttpServletRequest
request
,
ImeiAuthenticationToken
imei
AuthenticationToken
)
{
protected
void
setDetails
(
HttpServletRequest
request
,
SerialAuthenticationToken
serial
AuthenticationToken
)
{
imei
AuthenticationToken
.
setDetails
(
authenticationDetailsSource
.
buildDetails
(
request
));
serial
AuthenticationToken
.
setDetails
(
authenticationDetailsSource
.
buildDetails
(
request
));
}
}
public
void
setMdmEncrypt
(
String
mdmEncrypt
)
{
public
void
setMdmEncrypt
(
String
mdmEncrypt
)
{
this
.
mdmEncrypt
=
mdmEncrypt
;
this
.
mdmEncrypt
=
mdmEncrypt
;
}
}
}
}
\ No newline at end of file
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/
imei/Imei
AuthenticationProvider.java
→
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/
serial/Serial
AuthenticationProvider.java
View file @
41635fed
package
com
.
skr
.
mdm
.
authentication
.
user
.
imei
;
package
com
.
skr
.
mdm
.
authentication
.
user
.
serial
;
import
org.springframework.security.authentication.AuthenticationProvider
;
import
org.springframework.security.authentication.AuthenticationProvider
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.Authentication
;
...
@@ -9,35 +9,35 @@ import org.springframework.security.core.userdetails.UserDetails;
...
@@ -9,35 +9,35 @@ import org.springframework.security.core.userdetails.UserDetails;
* @author nfq
* @author nfq
* @date 2020/7/15 10:39
* @date 2020/7/15 10:39
*/
*/
public
class
Imei
AuthenticationProvider
implements
AuthenticationProvider
{
public
class
Serial
AuthenticationProvider
implements
AuthenticationProvider
{
private
Imei
UserDetailsServiceImpl
userDetailsService
;
private
Serial
UserDetailsServiceImpl
userDetailsService
;
@Override
@Override
public
Authentication
authenticate
(
Authentication
authentication
)
throws
AuthenticationException
{
public
Authentication
authenticate
(
Authentication
authentication
)
throws
AuthenticationException
{
ImeiAuthenticationToken
authenticationToken
=
(
Imei
AuthenticationToken
)
authentication
;
SerialAuthenticationToken
authenticationToken
=
(
Serial
AuthenticationToken
)
authentication
;
String
principal
=
(
String
)
authenticationToken
.
getPrincipal
();
String
principal
=
(
String
)
authenticationToken
.
getPrincipal
();
String
companyId
=
(
String
)
authenticationToken
.
getCompanyId
();
String
companyId
=
(
String
)
authenticationToken
.
getCompanyId
();
userDetailsService
.
setCompanyId
(
Integer
.
valueOf
(
companyId
));
userDetailsService
.
setCompanyId
(
Integer
.
valueOf
(
companyId
));
// 校验imei
// 校验imei
UserDetails
userDetails
=
userDetailsService
.
loadUserByUsername
(
principal
);
UserDetails
userDetails
=
userDetailsService
.
loadUserByUsername
(
principal
);
if
(
userDetails
==
null
)
{
if
(
userDetails
==
null
)
{
throw
new
Imei
AuthenticationException
(
throw
new
Serial
AuthenticationException
(
"UserDetailsService returned null, which is an interface contract violation"
);
"UserDetailsService returned null, which is an interface contract violation"
);
}
}
ImeiAuthenticationToken
authenticationResult
=
new
Imei
AuthenticationToken
(
userDetails
.
getAuthorities
(),
userDetails
,
companyId
);
SerialAuthenticationToken
authenticationResult
=
new
Serial
AuthenticationToken
(
userDetails
.
getAuthorities
(),
userDetails
,
companyId
);
authenticationResult
.
setDetails
(
authentication
.
getDetails
());
authenticationResult
.
setDetails
(
authentication
.
getDetails
());
return
authenticationResult
;
return
authenticationResult
;
}
}
@Override
@Override
public
boolean
supports
(
Class
<?>
authentication
)
{
public
boolean
supports
(
Class
<?>
authentication
)
{
return
(
Imei
AuthenticationToken
.
class
.
isAssignableFrom
(
authentication
));
return
(
Serial
AuthenticationToken
.
class
.
isAssignableFrom
(
authentication
));
}
}
public
void
setUserDetailsService
(
Imei
UserDetailsServiceImpl
userDetailsService
)
{
public
void
setUserDetailsService
(
Serial
UserDetailsServiceImpl
userDetailsService
)
{
this
.
userDetailsService
=
userDetailsService
;
this
.
userDetailsService
=
userDetailsService
;
}
}
}
}
\ No newline at end of file
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/
imei/Imei
AuthenticationToken.java
→
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/
serial/Serial
AuthenticationToken.java
View file @
41635fed
package
com
.
skr
.
mdm
.
authentication
.
user
.
imei
;
package
com
.
skr
.
mdm
.
authentication
.
user
.
serial
;
import
org.springframework.security.authentication.AbstractAuthenticationToken
;
import
org.springframework.security.authentication.AbstractAuthenticationToken
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.GrantedAuthority
;
...
@@ -9,7 +9,7 @@ import java.util.Collection;
...
@@ -9,7 +9,7 @@ import java.util.Collection;
* @author nfq
* @author nfq
* @date 2020/7/15 10:12
* @date 2020/7/15 10:12
*/
*/
public
class
Imei
AuthenticationToken
extends
AbstractAuthenticationToken
{
public
class
Serial
AuthenticationToken
extends
AbstractAuthenticationToken
{
private
static
final
long
serialVersionUID
=
-
8791155317019718470L
;
private
static
final
long
serialVersionUID
=
-
8791155317019718470L
;
/**
/**
...
@@ -18,7 +18,7 @@ public class ImeiAuthenticationToken extends AbstractAuthenticationToken {
...
@@ -18,7 +18,7 @@ public class ImeiAuthenticationToken extends AbstractAuthenticationToken {
private
final
Object
principal
;
private
final
Object
principal
;
private
final
Object
companyId
;
private
final
Object
companyId
;
public
Imei
AuthenticationToken
(
Object
principal
,
Object
companyId
)
{
public
Serial
AuthenticationToken
(
Object
principal
,
Object
companyId
)
{
super
(
null
);
super
(
null
);
this
.
principal
=
principal
;
this
.
principal
=
principal
;
this
.
companyId
=
companyId
;
this
.
companyId
=
companyId
;
...
@@ -32,7 +32,7 @@ public class ImeiAuthenticationToken extends AbstractAuthenticationToken {
...
@@ -32,7 +32,7 @@ public class ImeiAuthenticationToken extends AbstractAuthenticationToken {
* represented by this authentication object.
* represented by this authentication object.
* @param principal
* @param principal
*/
*/
public
Imei
AuthenticationToken
(
Collection
<?
extends
GrantedAuthority
>
authorities
,
Object
principal
,
Object
companyId
)
{
public
Serial
AuthenticationToken
(
Collection
<?
extends
GrantedAuthority
>
authorities
,
Object
principal
,
Object
companyId
)
{
super
(
authorities
);
super
(
authorities
);
this
.
principal
=
principal
;
this
.
principal
=
principal
;
this
.
companyId
=
companyId
;
this
.
companyId
=
companyId
;
...
@@ -62,4 +62,4 @@ public class ImeiAuthenticationToken extends AbstractAuthenticationToken {
...
@@ -62,4 +62,4 @@ public class ImeiAuthenticationToken extends AbstractAuthenticationToken {
public
Object
getCompanyId
()
{
public
Object
getCompanyId
()
{
return
companyId
;
return
companyId
;
}
}
}
}
\ No newline at end of file
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/
uuid/Uuid
UserDetailsServiceImpl.java
→
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/
serial/Serial
UserDetailsServiceImpl.java
View file @
41635fed
package
com
.
skr
.
mdm
.
authentication
.
user
.
uuid
;
package
com
.
skr
.
mdm
.
authentication
.
user
.
serial
;
import
cn.hutool.core.collection.ListUtil
;
import
cn.hutool.core.collection.ListUtil
;
import
com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper
;
import
com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper
;
...
@@ -22,10 +22,11 @@ import java.util.Date;
...
@@ -22,10 +22,11 @@ import java.util.Date;
/**
/**
* @author nfq
* @author nfq
* @date 202
1/1/29 15:15
* @date 202
0/7/15 10:58
*/
*/
@Service
@Service
public
class
UuidUserDetailsServiceImpl
implements
UserDetailsService
{
public
class
SerialUserDetailsServiceImpl
implements
UserDetailsService
{
private
Integer
companyId
;
private
Integer
companyId
;
...
@@ -35,40 +36,38 @@ public class UuidUserDetailsServiceImpl implements UserDetailsService {
...
@@ -35,40 +36,38 @@ public class UuidUserDetailsServiceImpl implements UserDetailsService {
private
RabbitMQProvider
rabbitMQProvider
;
private
RabbitMQProvider
rabbitMQProvider
;
@Override
@Override
public
UserDetails
loadUserByUsername
(
String
uuid
)
throws
UsernameNotFoundException
{
public
UserDetails
loadUserByUsername
(
String
serialNum
)
throws
UsernameNotFoundException
{
if
(
StringUtils
.
isBlank
(
uuid
)
||
companyId
==
null
)
{
if
(
StringUtils
.
isBlank
(
serialNum
)
||
companyId
==
null
)
{
throw
new
UuidAuthenticationException
(
"uuid为空:"
+
uuid
+
"companyId:"
+
companyId
);
throw
new
SerialAuthenticationException
(
"序列号为空:"
+
serialNum
+
"companyId:"
+
companyId
);
}
}
DeviceEquipmentDO
deviceEquipmentDO
=
new
LambdaQueryChainWrapper
<>(
equipmentDao
)
DeviceEquipmentDO
deviceEquipmentDO
=
new
LambdaQueryChainWrapper
<>(
equipmentDao
)
.
eq
(
DeviceEquipmentDO:
:
getUuid
,
uuid
)
.
eq
(
DeviceEquipmentDO:
:
getCompanyId
,
companyId
)
.
eq
(
DeviceEquipmentDO:
:
getCompanyId
,
companyId
)
.
eq
(
DeviceEquipmentDO:
:
getSerialNumber
,
serialNum
)
.
eq
(
DeviceEquipmentDO:
:
getIsDelete
,
DeleteStateEnum
.
NON_DELETE
.
getState
())
.
eq
(
DeviceEquipmentDO:
:
getIsDelete
,
DeleteStateEnum
.
NON_DELETE
.
getState
())
.
one
();
.
one
();
if
(
deviceEquipmentDO
==
null
)
{
if
(
deviceEquipmentDO
==
null
)
{
throw
new
UuidAuthenticationException
(
"uuid不存在:"
+
uuid
+
"companyId:"
+
companyId
);
throw
new
SerialAuthenticationException
(
"序列号不存在:"
+
serialNum
+
"companyId:"
+
companyId
);
}
}
// 激活时间
// 激活时间
if
(
EquipmentStateEnum
.
INACTIVATED
.
getState
().
equals
(
deviceEquipmentDO
.
getEquipmentState
()))
{
if
(
EquipmentStateEnum
.
INACTIVATED
.
getState
().
equals
(
deviceEquipmentDO
.
getEquipmentState
()))
{
LambdaUpdateChainWrapper
<
DeviceEquipmentDO
>
updateChainWrapper
=
new
LambdaUpdateChainWrapper
<>(
equipmentDao
);
LambdaUpdateChainWrapper
<
DeviceEquipmentDO
>
updateChainWrapper
=
new
LambdaUpdateChainWrapper
<>(
equipmentDao
);
updateChainWrapper
updateChainWrapper
.
set
(
DeviceEquipmentDO:
:
getActivationTime
,
new
Date
())
.
set
(
DeviceEquipmentDO:
:
getActivationTime
,
new
Date
())
.
eq
(
DeviceEquipmentDO:
:
getId
,
deviceEquipmentDO
.
getId
())
.
eq
(
DeviceEquipmentDO:
:
getId
,
deviceEquipmentDO
.
getId
())
.
update
();
.
update
();
// 异步拉取全局指令
// 异步拉取全局指令
UserLoginCallbackDTO
userLoginCallbackDTO
=
UserLoginCallbackDTO
.
builder
()
UserLoginCallbackDTO
userLoginCallbackDTO
=
UserLoginCallbackDTO
.
builder
()
.
deviceIdList
(
ListUtil
.
toList
(
deviceEquipmentDO
.
getId
()))
.
deviceIdList
(
ListUtil
.
toList
(
deviceEquipmentDO
.
getId
()))
.
companyId
(
deviceEquipmentDO
.
getCompanyId
())
.
departmentId
(
deviceEquipmentDO
.
getDepartmentId
())
.
departmentId
(
deviceEquipmentDO
.
getDepartmentId
())
.
companyId
(
deviceEquipmentDO
.
getCompanyId
())
.
build
();
.
build
();
rabbitMQProvider
.
publishRegisterEventWithDelayed
(
userLoginCallbackDTO
);
rabbitMQProvider
.
publishRegisterEventWithDelayed
(
userLoginCallbackDTO
);
}
}
LoginUserDTO
loginUserDTO
=
new
LoginUserDTO
();
LoginUserDTO
loginUserDTO
=
new
LoginUserDTO
();
BeanUtils
.
copyProperties
(
deviceEquipmentDO
,
loginUserDTO
);
BeanUtils
.
copyProperties
(
deviceEquipmentDO
,
loginUserDTO
);
return
loginUserDTO
;
return
loginUserDTO
;
}
}
public
void
setCompanyId
(
Integer
companyId
)
{
public
void
setCompanyId
(
Integer
companyId
)
{
this
.
companyId
=
companyId
;
this
.
companyId
=
companyId
;
}
}
}
}
\ No newline at end of file
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/sms/SMSCodeLoginException.java
deleted
100644 → 0
View file @
4e65c777
package
com
.
skr
.
mdm
.
authentication
.
user
.
sms
;
import
org.springframework.security.core.AuthenticationException
;
public
class
SMSCodeLoginException
extends
AuthenticationException
{
private
static
final
long
serialVersionUID
=
6731162291714457528L
;
public
SMSCodeLoginException
(
String
msg
)
{
super
(
msg
);
}
}
\ No newline at end of file
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/sms/SmsAuthenticationFilter.java
deleted
100644 → 0
View file @
4e65c777
package
com
.
skr
.
mdm
.
authentication
.
user
.
sms
;
import
cn.hutool.crypto.SmUtil
;
import
cn.hutool.crypto.asymmetric.KeyType
;
import
cn.hutool.crypto.asymmetric.SM2
;
import
cn.hutool.crypto.symmetric.SM4
;
import
com.skr.mdm.enums.MdmEncryptEnum
;
import
com.skr.mdm.util.SmUtils
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.lang.Nullable
;
import
org.springframework.security.authentication.AuthenticationServiceException
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.AuthenticationException
;
import
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
;
import
org.springframework.security.web.util.matcher.AntPathRequestMatcher
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
public
class
SmsAuthenticationFilter
extends
AbstractAuthenticationProcessingFilter
{
public
static
final
String
SPRING_SECURITY_FORM_SMS_CODE_KEY
=
"SMSCode"
;
public
static
final
String
PHONE
=
"phone"
;
public
static
final
String
COMPANY_ID
=
"companyId"
;
public
static
final
String
IMEI
=
"imei"
;
public
static
final
String
OAID
=
"oaid"
;
public
static
final
String
UUID
=
"uuid"
;
public
static
final
String
SECRET_KEY
=
"secretKey"
;
private
SM4
sm4
=
null
;
private
String
mdmEncrypt
;
public
SmsAuthenticationFilter
()
{
super
(
new
AntPathRequestMatcher
(
"/sms/login"
,
HttpMethod
.
POST
.
name
()));
}
@Override
public
Authentication
attemptAuthentication
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
AuthenticationException
,
IOException
,
ServletException
{
if
(
Boolean
.
TRUE
&&
!
request
.
getMethod
().
equals
(
HttpMethod
.
POST
.
name
()))
{
throw
new
AuthenticationServiceException
(
"Authentication method not supported: "
+
request
.
getMethod
());
}
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
obtainSecretKey
(
request
);
}
String
smsCode
=
obtainSmsCode
(
request
);
String
phone
=
obtainPhone
(
request
);
String
imei
=
obtainImei
(
request
);
String
oaid
=
obtainOaid
(
request
);
String
uuid
=
obtainUuid
(
request
);
String
companyId
=
obtainCompanyId
(
request
);
if
(
phone
==
null
)
{
phone
=
""
;
}
if
(
smsCode
==
null
)
{
smsCode
=
""
;
}
if
(
imei
==
null
)
{
imei
=
""
;
}
if
(
oaid
==
null
)
{
oaid
=
""
;
}
if
(
uuid
==
null
)
{
uuid
=
""
;
}
SmsAuthenticationToken
authRequest
=
new
SmsAuthenticationToken
(
phone
,
smsCode
,
imei
,
oaid
,
uuid
,
companyId
);
setDetails
(
request
,
authRequest
);
return
this
.
getAuthenticationManager
().
authenticate
(
authRequest
);
}
@Nullable
protected
String
obtainSmsCode
(
HttpServletRequest
request
)
{
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
return
sm4
.
decryptStr
(
request
.
getParameter
(
SPRING_SECURITY_FORM_SMS_CODE_KEY
));
}
return
request
.
getParameter
(
SPRING_SECURITY_FORM_SMS_CODE_KEY
);
}
@Nullable
protected
String
obtainPhone
(
HttpServletRequest
request
)
{
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
return
sm4
.
decryptStr
(
request
.
getParameter
(
PHONE
));
}
return
request
.
getParameter
(
PHONE
);
}
@Nullable
protected
String
obtainCompanyId
(
HttpServletRequest
request
)
{
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
return
sm4
.
decryptStr
(
request
.
getParameter
(
COMPANY_ID
));
}
return
request
.
getParameter
(
COMPANY_ID
);
}
@Nullable
protected
String
obtainImei
(
HttpServletRequest
request
)
{
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
return
sm4
.
decryptStr
(
request
.
getParameter
(
IMEI
));
}
return
request
.
getParameter
(
IMEI
);
}
@Nullable
protected
String
obtainOaid
(
HttpServletRequest
request
)
{
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
return
sm4
.
decryptStr
(
request
.
getParameter
(
OAID
));
}
return
request
.
getParameter
(
OAID
);
}
@Nullable
protected
String
obtainUuid
(
HttpServletRequest
request
)
{
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
return
sm4
.
decryptStr
(
request
.
getParameter
(
UUID
));
}
return
request
.
getParameter
(
UUID
);
}
@Nullable
protected
String
obtainSecretKey
(
HttpServletRequest
request
)
{
String
secretKey
=
request
.
getHeader
(
SECRET_KEY
);
SM2
sm2
=
SmUtils
.
sm2Sign
();
byte
[]
secretKeyBytes
=
sm2
.
decrypt
(
secretKey
,
KeyType
.
PrivateKey
);
sm4
=
SmUtil
.
sm4
(
secretKeyBytes
);
return
request
.
getHeader
(
SECRET_KEY
);
}
protected
void
setDetails
(
HttpServletRequest
request
,
SmsAuthenticationToken
authRequest
)
{
authRequest
.
setDetails
(
authenticationDetailsSource
.
buildDetails
(
request
));
}
public
void
setMdmEncrypt
(
String
mdmEncrypt
)
{
this
.
mdmEncrypt
=
mdmEncrypt
;
}
}
\ No newline at end of file
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/sms/SmsAuthenticationProvider.java
deleted
100644 → 0
View file @
4e65c777
This diff is collapsed.
Click to expand it.
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/sms/SmsAuthenticationToken.java
deleted
100644 → 0
View file @
4e65c777
package
com
.
skr
.
mdm
.
authentication
.
user
.
sms
;
import
org.springframework.security.authentication.AbstractAuthenticationToken
;
import
org.springframework.security.core.GrantedAuthority
;
import
java.util.Collection
;
public
class
SmsAuthenticationToken
extends
AbstractAuthenticationToken
{
private
static
final
long
serialVersionUID
=
-
3578288222289154241L
;
private
final
Object
principal
;
private
Object
credentials
;
private
final
Object
imei
;
private
final
Object
oaid
;
private
final
Object
uuid
;
private
final
Object
companyId
;
public
SmsAuthenticationToken
(
Object
principal
,
Object
credentials
,
Object
imei
,
Object
oaid
,
Object
uuid
,
Object
companyId
)
{
super
(
null
);
this
.
principal
=
principal
;
this
.
credentials
=
credentials
;
this
.
imei
=
imei
;
this
.
oaid
=
oaid
;
this
.
uuid
=
uuid
;
this
.
companyId
=
companyId
;
setAuthenticated
(
false
);
}
public
SmsAuthenticationToken
(
Collection
<?
extends
GrantedAuthority
>
authorities
,
Object
principal
,
Object
imei
,
Object
oaid
,
Object
uuid
,
Object
companyId
)
{
super
(
authorities
);
this
.
principal
=
principal
;
this
.
imei
=
imei
;
this
.
oaid
=
oaid
;
this
.
uuid
=
uuid
;
this
.
companyId
=
companyId
;
super
.
setAuthenticated
(
true
);
}
@Override
public
Object
getCredentials
()
{
return
this
.
credentials
;
}
@Override
public
Object
getPrincipal
()
{
return
this
.
principal
;
}
@Override
public
void
setAuthenticated
(
boolean
isAuthenticated
)
throws
IllegalArgumentException
{
super
.
setAuthenticated
(
isAuthenticated
);
}
public
Object
getImei
()
{
return
this
.
imei
;
}
public
Object
getOaid
()
{
return
oaid
;
}
public
Object
getUuid
()
{
return
uuid
;
}
public
Object
getCompanyId
()
{
return
companyId
;
}
}
\ No newline at end of file
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/sms/SmsDetailsServiceImpl.java
deleted
100644 → 0
View file @
4e65c777
package
com
.
skr
.
mdm
.
authentication
.
user
.
sms
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.skr.mdm.dao.AuUserDao
;
import
com.skr.mdm.dto.LoginUserDTO
;
import
com.skr.mdm.entity.AuUserDO
;
import
com.skr.mdm.enums.DeleteStateEnum
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
import
org.springframework.stereotype.Service
;
@Service
public
class
SmsDetailsServiceImpl
implements
UserDetailsService
{
private
Integer
companyId
;
@Autowired
private
AuUserDao
auUserDao
;
@Override
public
UserDetails
loadUserByUsername
(
String
phone
)
throws
UsernameNotFoundException
{
if
(
companyId
==
null
)
{
throw
new
UsernameNotFoundException
(
"companyId为null:"
+
companyId
);
}
LambdaQueryWrapper
<
AuUserDO
>
lambdaQueryWrapper
=
Wrappers
.
lambdaQuery
();
lambdaQueryWrapper
.
eq
(
AuUserDO:
:
getPhoneNumber
,
phone
)
.
eq
(
AuUserDO:
:
getIsDelete
,
DeleteStateEnum
.
NON_DELETE
.
getState
())
.
eq
(
AuUserDO:
:
getCompanyId
,
companyId
);
AuUserDO
userDO
=
auUserDao
.
selectOne
(
lambdaQueryWrapper
);
if
(
userDO
==
null
)
{
throw
new
UsernameNotFoundException
(
"用户手机号不存在:"
+
phone
+
"companyId:"
+
companyId
);
}
LoginUserDTO
loginUserDTO
=
new
LoginUserDTO
();
BeanUtils
.
copyProperties
(
userDO
,
loginUserDTO
);
loginUserDTO
.
setUserId
(
userDO
.
getId
());
loginUserDTO
.
setDepartmentId
(
userDO
.
getDepartmentId
());
loginUserDTO
.
setDepartmentName
(
userDO
.
getDepartmentName
());
loginUserDTO
.
setPassword
(
userDO
.
getPassword
());
return
loginUserDTO
;
}
public
void
setCompanyId
(
Integer
companyId
)
{
this
.
companyId
=
companyId
;
}
}
\ No newline at end of file
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/uuid/UuidAuthenticationException.java
deleted
100644 → 0
View file @
4e65c777
package
com
.
skr
.
mdm
.
authentication
.
user
.
uuid
;
import
org.springframework.security.core.AuthenticationException
;
/**
* @author nfq
* @date 2021/1/29 15:22
*/
public
class
UuidAuthenticationException
extends
AuthenticationException
{
private
static
final
long
serialVersionUID
=
-
5602561092590320699L
;
public
UuidAuthenticationException
(
String
msg
)
{
super
(
msg
);
}
}
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/uuid/UuidAuthenticationFilter.java
deleted
100644 → 0
View file @
4e65c777
package
com
.
skr
.
mdm
.
authentication
.
user
.
uuid
;
import
cn.hutool.crypto.SmUtil
;
import
cn.hutool.crypto.asymmetric.KeyType
;
import
cn.hutool.crypto.asymmetric.SM2
;
import
cn.hutool.crypto.symmetric.SM4
;
import
com.skr.mdm.enums.MdmEncryptEnum
;
import
com.skr.mdm.util.SmUtils
;
import
io.swagger.models.HttpMethod
;
import
org.springframework.lang.Nullable
;
import
org.springframework.security.authentication.AuthenticationServiceException
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.AuthenticationException
;
import
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
;
import
org.springframework.security.web.util.matcher.AntPathRequestMatcher
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
/**
* @author nfq
* @date 2021/1/29 15:05
*/
public
class
UuidAuthenticationFilter
extends
AbstractAuthenticationProcessingFilter
{
public
static
final
String
SPRING_SECURITY_FORM_UUID_KEY
=
"uuid"
;
public
static
final
String
COMPANY_ID
=
"companyId"
;
public
static
final
String
SECRET_KEY
=
"secretKey"
;
private
final
String
uuidParameter
=
SPRING_SECURITY_FORM_UUID_KEY
;
private
final
String
companyIdParameter
=
COMPANY_ID
;
private
final
String
secretKeyParameter
=
SECRET_KEY
;
private
final
boolean
postOnly
=
true
;
private
SM4
sm4
=
null
;
private
String
mdmEncrypt
;
public
UuidAuthenticationFilter
()
{
super
(
new
AntPathRequestMatcher
(
"/uuid/login"
,
"POST"
));
}
@Override
public
Authentication
attemptAuthentication
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
AuthenticationException
,
IOException
,
ServletException
{
if
(
postOnly
&&
!
request
.
getMethod
().
equals
(
HttpMethod
.
POST
.
name
()))
{
throw
new
AuthenticationServiceException
(
"Authentication method not supported:"
+
request
.
getMethod
());
}
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
obtainSecretKey
(
request
);
}
String
uuid
=
obtainUuid
(
request
);
String
companyId
=
obtainCompanyId
(
request
);
if
(
uuid
==
null
)
{
uuid
=
""
;
}
uuid
=
uuid
.
trim
();
UuidAuthenticationToken
oaidAuthenticationToken
=
new
UuidAuthenticationToken
(
uuid
,
companyId
);
setDetails
(
request
,
oaidAuthenticationToken
);
return
this
.
getAuthenticationManager
().
authenticate
(
oaidAuthenticationToken
);
}
@Nullable
protected
String
obtainUuid
(
HttpServletRequest
request
)
{
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
return
sm4
.
decryptStr
(
request
.
getParameter
(
uuidParameter
));
}
return
request
.
getParameter
(
uuidParameter
);
}
@Nullable
protected
String
obtainCompanyId
(
HttpServletRequest
request
)
{
if
(
MdmEncryptEnum
.
SM
.
getMdmEncrypt
().
equals
(
mdmEncrypt
))
{
return
sm4
.
decryptStr
(
request
.
getParameter
(
companyIdParameter
));
}
return
request
.
getParameter
(
companyIdParameter
);
}
@Nullable
protected
String
obtainSecretKey
(
HttpServletRequest
request
)
{
String
secretKey
=
request
.
getHeader
(
secretKeyParameter
);
SM2
sm2
=
SmUtils
.
sm2Sign
();
byte
[]
secretKeyBytes
=
sm2
.
decrypt
(
secretKey
,
KeyType
.
PrivateKey
);
sm4
=
SmUtil
.
sm4
(
secretKeyBytes
);
return
request
.
getHeader
(
secretKeyParameter
);
}
protected
void
setDetails
(
HttpServletRequest
request
,
UuidAuthenticationToken
oaidAuthenticationToken
)
{
oaidAuthenticationToken
.
setDetails
(
authenticationDetailsSource
.
buildDetails
(
request
));
}
public
void
setMdmEncrypt
(
String
mdmEncrypt
)
{
this
.
mdmEncrypt
=
mdmEncrypt
;
}
}
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/uuid/UuidAuthenticationProvider.java
deleted
100644 → 0
View file @
4e65c777
package
com
.
skr
.
mdm
.
authentication
.
user
.
uuid
;
import
org.springframework.security.authentication.AuthenticationProvider
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.AuthenticationException
;
import
org.springframework.security.core.userdetails.UserDetails
;
/**
* @author nfq
* @date 2021/1/29 15:14
*/
public
class
UuidAuthenticationProvider
implements
AuthenticationProvider
{
private
UuidUserDetailsServiceImpl
userDetailsService
;
@Override
public
Authentication
authenticate
(
Authentication
authentication
)
throws
AuthenticationException
{
UuidAuthenticationToken
authenticationToken
=
(
UuidAuthenticationToken
)
authentication
;
String
principal
=
(
String
)
authenticationToken
.
getPrincipal
();
String
companyId
=
(
String
)
authenticationToken
.
getCompanyId
();
userDetailsService
.
setCompanyId
(
Integer
.
valueOf
(
companyId
));
// 校验uuid
UserDetails
userDetails
=
userDetailsService
.
loadUserByUsername
(
principal
);
if
(
userDetails
==
null
)
{
throw
new
UuidAuthenticationException
(
"UserDetailsService returned null, which is an interface contract violation"
);
}
UuidAuthenticationToken
authenticationResult
=
new
UuidAuthenticationToken
(
userDetails
.
getAuthorities
(),
userDetails
,
companyId
);
authenticationResult
.
setDetails
(
authentication
.
getDetails
());
return
authenticationResult
;
}
@Override
public
boolean
supports
(
Class
<?>
authentication
)
{
return
(
UuidAuthenticationToken
.
class
.
isAssignableFrom
(
authentication
));
}
public
void
setUserDetailsService
(
UuidUserDetailsServiceImpl
userDetailsService
)
{
this
.
userDetailsService
=
userDetailsService
;
}
}
mdm_authentication/src/main/java/com/skr/mdm/authentication/user/uuid/UuidAuthenticationToken.java
deleted
100644 → 0
View file @
4e65c777
package
com
.
skr
.
mdm
.
authentication
.
user
.
uuid
;
import
org.springframework.security.authentication.AbstractAuthenticationToken
;
import
org.springframework.security.core.GrantedAuthority
;
import
java.util.Collection
;
/**
* @author nfq
* @date 2021/1/29 15:06
*/
public
class
UuidAuthenticationToken
extends
AbstractAuthenticationToken
{
private
static
final
long
serialVersionUID
=
-
7421570826625845499L
;
/**
* uuid
*/
private
final
Object
principal
;
private
final
Object
companyId
;
public
UuidAuthenticationToken
(
Object
principal
,
Object
companyId
)
{
super
(
null
);
this
.
principal
=
principal
;
this
.
companyId
=
companyId
;
setAuthenticated
(
false
);
}
/**
* Creates a token with the supplied array of authorities.
*
* @param authorities the collection of <tt>GrantedAuthority</tt>s for the principal
* represented by this authentication object.
* @param principal
*/
public
UuidAuthenticationToken
(
Collection
<?
extends
GrantedAuthority
>
authorities
,
Object
principal
,
Object
companyId
)
{
super
(
authorities
);
this
.
principal
=
principal
;
this
.
companyId
=
companyId
;
super
.
setAuthenticated
(
true
);
}
@Override
public
void
setAuthenticated
(
boolean
authenticated
)
{
super
.
setAuthenticated
(
authenticated
);
}
@Override
public
Object
getCredentials
()
{
return
null
;
}
@Override
public
Object
getPrincipal
()
{
return
this
.
principal
;
}
@Override
public
void
eraseCredentials
()
{
super
.
eraseCredentials
();
}
public
Object
getCompanyId
()
{
return
companyId
;
}
}
mdm_authentication/src/main/java/com/skr/mdm/util/AntiReplayUtil.java
View file @
41635fed
...
@@ -30,7 +30,7 @@ public class AntiReplayUtil {
...
@@ -30,7 +30,7 @@ public class AntiReplayUtil {
private
final
String
nonceParameter
=
RequestHeaderConstants
.
REQUEST_HEADER_NONCE
;
private
final
String
nonceParameter
=
RequestHeaderConstants
.
REQUEST_HEADER_NONCE
;
private
final
String
timestampHeaderParameter
=
RequestHeaderConstants
.
REQUEST_HEADER_TIMESTAMP
;
private
final
String
timestampHeaderParameter
=
RequestHeaderConstants
.
REQUEST_HEADER_TIMESTAMP
;
private
final
String
signParameter
=
RequestHeaderConstants
.
REQUEST_HEADER_SIGN
;
private
final
String
signParameter
=
RequestHeaderConstants
.
REQUEST_HEADER_SIGN
;
private
final
String
android
Parameter
=
RequestHeaderConstants
.
REQUEST_HEADER_USER_AGENT
;
private
final
String
pc
Parameter
=
RequestHeaderConstants
.
REQUEST_HEADER_USER_AGENT
;
private
final
String
csrfToken
=
RequestHeaderConstants
.
REQUEST_HEADER_CSRF_TOKEN
;
private
final
String
csrfToken
=
RequestHeaderConstants
.
REQUEST_HEADER_CSRF_TOKEN
;
@Value
(
"${request.expire.seconds}"
)
@Value
(
"${request.expire.seconds}"
)
private
Long
requestExpire
;
private
Long
requestExpire
;
...
@@ -53,15 +53,15 @@ public class AntiReplayUtil {
...
@@ -53,15 +53,15 @@ public class AntiReplayUtil {
String
nonce
=
request
.
getHeader
(
this
.
nonceParameter
);
String
nonce
=
request
.
getHeader
(
this
.
nonceParameter
);
String
timestampParameter
=
request
.
getHeader
(
this
.
timestampHeaderParameter
);
String
timestampParameter
=
request
.
getHeader
(
this
.
timestampHeaderParameter
);
String
sign
=
request
.
getHeader
(
this
.
signParameter
);
String
sign
=
request
.
getHeader
(
this
.
signParameter
);
String
android
=
request
.
getHeader
(
this
.
android
Parameter
);
String
pc
=
request
.
getHeader
(
this
.
pc
Parameter
);
boolean
checkParam
=
StringUtils
.
isBlank
(
nonce
)
||
StringUtils
.
isBlank
(
timestampParameter
)
||
boolean
checkParam
=
StringUtils
.
isBlank
(
nonce
)
||
StringUtils
.
isBlank
(
timestampParameter
)
||
StringUtils
.
isBlank
(
sign
)
||
StringUtils
.
isBlank
(
android
);
StringUtils
.
isBlank
(
sign
)
||
StringUtils
.
isBlank
(
pc
);
if
(
checkParam
)
{
if
(
checkParam
)
{
log
.
warn
(
"请求头内容不完整 timestampParameter:{} sign:{} nonce:{},
android:{} 请求地址:{}"
,
timestampParameter
,
sign
,
nonce
,
android
,
request
.
getRequestURI
());
log
.
warn
(
"请求头内容不完整 timestampParameter:{} sign:{} nonce:{},
pc:{} 请求地址:{}"
,
timestampParameter
,
sign
,
nonce
,
pc
,
request
.
getRequestURI
());
throw
new
IllegalUserRequestException
();
throw
new
IllegalUserRequestException
();
}
}
if
(!
StringUtils
.
equalsIgnoreCase
(
"
android"
,
android
))
{
if
(!
StringUtils
.
equalsIgnoreCase
(
"
pc"
,
pc
))
{
log
.
warn
(
"非安卓请求:{} 请求地址:{}"
,
android
,
request
.
getRequestURI
());
log
.
warn
(
"非安卓请求:{} 请求地址:{}"
,
pc
,
request
.
getRequestURI
());
throw
new
IllegalUserRequestException
();
throw
new
IllegalUserRequestException
();
}
}
...
@@ -153,4 +153,4 @@ public class AntiReplayUtil {
...
@@ -153,4 +153,4 @@ public class AntiReplayUtil {
// 随机值放入缓存
// 随机值放入缓存
redisUtils
.
set
(
RedisGetKeyUtil
.
getAdminQuestNonceKey
(
nonce
),
nonce
,
requestExpire
);
redisUtils
.
set
(
RedisGetKeyUtil
.
getAdminQuestNonceKey
(
nonce
),
nonce
,
requestExpire
);
}
}
}
}
\ No newline at end of file
mdm_authentication/src/main/java/com/skr/mdm/util/RegisterEquipmentUtil.java
View file @
41635fed
...
@@ -23,7 +23,7 @@ public class RegisterEquipmentUtil {
...
@@ -23,7 +23,7 @@ public class RegisterEquipmentUtil {
/**
/**
* 生成设备名
* 生成设备名
*
*
* @param equipment
DO
List 用户下的设备集合
* @param equipment
Name
List 用户下的设备集合
* @param userName 用户名
* @param userName 用户名
* @return 设备名
* @return 设备名
*/
*/
...
@@ -75,4 +75,4 @@ public class RegisterEquipmentUtil {
...
@@ -75,4 +75,4 @@ public class RegisterEquipmentUtil {
equipmentDO
.
setTrid
(
trid
);
equipmentDO
.
setTrid
(
trid
);
return
equipmentDO
;
return
equipmentDO
;
}
}
}
}
\ No newline at end of file
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