Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Jeepay
Commits
0268fb97
Commit
0268fb97
authored
Jun 15, 2021
by
terrfly
Browse files
解决数据库异常 登录提示信息有误的问题;
parent
7ac96de7
Changes
5
Hide whitespace changes
Inline
Side-by-side
jeepay-core/src/main/java/com/jeequan/jeepay/core/exception/JeepayAuthenticationException.java
0 → 100644
View file @
0268fb97
/*
* Copyright (c) 2021-2031, 河北计全科技有限公司 (https://www.jeequan.com & jeequan@126.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.jeequan.jeepay.core.exception
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.springframework.security.authentication.InternalAuthenticationServiceException
;
/*
* Spring Security 框架自定义异常类
*
* @author terrfly
* @site https://www.jeepay.vip
* @date 2021/6/15 11:23
*/
@Getter
@Setter
public
class
JeepayAuthenticationException
extends
InternalAuthenticationServiceException
{
private
BizException
bizException
;
public
JeepayAuthenticationException
(
String
msg
,
Throwable
cause
)
{
super
(
msg
,
cause
);
}
public
JeepayAuthenticationException
(
String
msg
)
{
super
(
msg
);
}
public
static
JeepayAuthenticationException
build
(
String
msg
){
return
build
(
new
BizException
(
msg
));
}
public
static
JeepayAuthenticationException
build
(
BizException
ex
){
JeepayAuthenticationException
result
=
new
JeepayAuthenticationException
(
ex
.
getMessage
());
result
.
setBizException
(
ex
);
return
result
;
}
}
jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/secruity/JeeUserDetailsServiceImpl.java
View file @
0268fb97
...
...
@@ -18,11 +18,11 @@ package com.jeequan.jeepay.mgr.secruity;
import
com.jeequan.jeepay.core.constants.CS
;
import
com.jeequan.jeepay.core.entity.SysUser
;
import
com.jeequan.jeepay.core.entity.SysUserAuth
;
import
com.jeequan.jeepay.core.exception.BizException
;
import
com.jeequan.jeepay.core.exception.JeepayAuthenticationException
;
import
com.jeequan.jeepay.core.model.security.JeeUserDetails
;
import
com.jeequan.jeepay.core.utils.RegKit
;
import
com.jeequan.jeepay.service.impl.SysUserAuthService
;
import
com.jeequan.jeepay.service.impl.SysUserService
;
import
com.jeequan.jeepay.core.utils.RegKit
;
import
com.jeequan.jeepay.core.model.security.JeeUserDetails
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
...
...
@@ -31,7 +31,7 @@ import org.springframework.stereotype.Service;
/*
* 实现UserDetailsService 接口
*
*
* @author terrfly
* @site https://www.jeepay.vip
* @date 2021/6/8 17:13
...
...
@@ -65,7 +65,7 @@ public class JeeUserDetailsServiceImpl implements UserDetailsService {
SysUserAuth
auth
=
sysUserAuthService
.
selectByLogin
(
loginUsernameStr
,
identityType
,
CS
.
SYS_TYPE
.
MGR
);
if
(
auth
==
null
){
//没有该用户信息
throw
new
Biz
Exception
(
"用户名/密码错误!"
);
throw
JeepayAuthentication
Exception
.
build
(
"用户名/密码错误!"
);
}
//用户ID
...
...
@@ -74,11 +74,11 @@ public class JeeUserDetailsServiceImpl implements UserDetailsService {
SysUser
sysUser
=
sysUserService
.
getById
(
userId
);
if
(
sysUser
==
null
)
{
throw
new
Biz
Exception
(
"用户名/密码错误!"
);
throw
JeepayAuthentication
Exception
.
build
(
"用户名/密码错误!"
);
}
if
(
CS
.
PUB_USABLE
!=
sysUser
.
getState
()){
//状态不合法
throw
new
Biz
Exception
(
"用户状态不可登录,请联系管理员!"
);
throw
JeepayAuthentication
Exception
.
build
(
"用户状态不可登录,请联系管理员!"
);
}
return
new
JeeUserDetails
(
sysUser
,
auth
.
getCredential
());
...
...
jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/service/AuthService.java
View file @
0268fb97
...
...
@@ -21,6 +21,7 @@ import com.jeequan.jeepay.core.constants.CS;
import
com.jeequan.jeepay.core.entity.SysUser
;
import
com.jeequan.jeepay.core.exception.BizException
;
import
com.jeequan.jeepay.core.cache.RedisUtil
;
import
com.jeequan.jeepay.core.exception.JeepayAuthenticationException
;
import
com.jeequan.jeepay.core.jwt.JWTPayload
;
import
com.jeequan.jeepay.core.jwt.JWTUtils
;
import
com.jeequan.jeepay.core.model.security.JeeUserDetails
;
...
...
@@ -29,6 +30,7 @@ import com.jeequan.jeepay.service.impl.SysRoleEntRelaService;
import
com.jeequan.jeepay.service.impl.SysRoleService
;
import
com.jeequan.jeepay.service.impl.SysUserService
;
import
com.jeequan.jeepay.service.mapper.SysEntitlementMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.authentication.AuthenticationManager
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
...
...
@@ -36,6 +38,7 @@ import org.springframework.security.core.Authentication;
import
org.springframework.security.core.AuthenticationException
;
import
org.springframework.security.core.authority.SimpleGrantedAuthority
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
...
...
@@ -48,6 +51,7 @@ import java.util.*;
* @site https://www.jeepay.vip
* @date 2021/6/8 17:12
*/
@Slf4j
@Service
public
class
AuthService
{
...
...
@@ -75,8 +79,11 @@ public class AuthService {
Authentication
authentication
=
null
;
try
{
authentication
=
authenticationManager
.
authenticate
(
upToken
);
}
catch
(
JeepayAuthenticationException
jex
)
{
throw
jex
.
getBizException
()
==
null
?
new
BizException
(
jex
.
getMessage
())
:
jex
.
getBizException
();
}
catch
(
AuthenticationException
e
)
{
throw
new
BizException
(
"用户名或密码有误!"
);
log
.
error
(
"AuthenticationException:"
,
e
);
throw
new
BizException
(
"认证服务出现异常, 请重试或联系系统管理员!"
);
}
JeeUserDetails
jeeUserDetails
=
(
JeeUserDetails
)
authentication
.
getPrincipal
();
...
...
jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/secruity/JeeUserDetailsServiceImpl.java
View file @
0268fb97
...
...
@@ -18,11 +18,11 @@ package com.jeequan.jeepay.mch.secruity;
import
com.jeequan.jeepay.core.constants.CS
;
import
com.jeequan.jeepay.core.entity.SysUser
;
import
com.jeequan.jeepay.core.entity.SysUserAuth
;
import
com.jeequan.jeepay.core.exception.BizException
;
import
com.jeequan.jeepay.core.exception.JeepayAuthenticationException
;
import
com.jeequan.jeepay.core.model.security.JeeUserDetails
;
import
com.jeequan.jeepay.core.utils.RegKit
;
import
com.jeequan.jeepay.service.impl.SysUserAuthService
;
import
com.jeequan.jeepay.service.impl.SysUserService
;
import
com.jeequan.jeepay.core.utils.RegKit
;
import
com.jeequan.jeepay.core.model.security.JeeUserDetails
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
...
...
@@ -66,7 +66,7 @@ public class JeeUserDetailsServiceImpl implements UserDetailsService {
SysUserAuth
auth
=
sysUserAuthService
.
selectByLogin
(
loginUsernameStr
,
identityType
,
CS
.
SYS_TYPE
.
MCH
);
if
(
auth
==
null
){
//没有该用户信息
throw
new
Biz
Exception
(
"用户名/密码错误!"
);
throw
JeepayAuthentication
Exception
.
build
(
"用户名/密码错误!"
);
}
//用户ID
...
...
@@ -75,11 +75,11 @@ public class JeeUserDetailsServiceImpl implements UserDetailsService {
SysUser
sysUser
=
sysUserService
.
getById
(
userId
);
if
(
sysUser
==
null
)
{
throw
new
Biz
Exception
(
"用户名/密码错误!"
);
throw
JeepayAuthentication
Exception
.
build
(
"用户名/密码错误!"
);
}
if
(
CS
.
PUB_USABLE
!=
sysUser
.
getState
()){
//状态不合法
throw
new
Biz
Exception
(
"用户状态不可登录,请联系管理员!"
);
throw
JeepayAuthentication
Exception
.
build
(
"用户状态不可登录,请联系管理员!"
);
}
return
new
JeeUserDetails
(
sysUser
,
auth
.
getCredential
());
...
...
jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/service/AuthService.java
View file @
0268fb97
...
...
@@ -22,6 +22,7 @@ import com.jeequan.jeepay.core.constants.CS;
import
com.jeequan.jeepay.core.entity.MchInfo
;
import
com.jeequan.jeepay.core.entity.SysUser
;
import
com.jeequan.jeepay.core.exception.BizException
;
import
com.jeequan.jeepay.core.exception.JeepayAuthenticationException
;
import
com.jeequan.jeepay.core.jwt.JWTPayload
;
import
com.jeequan.jeepay.core.jwt.JWTUtils
;
import
com.jeequan.jeepay.core.model.security.JeeUserDetails
;
...
...
@@ -31,6 +32,7 @@ import com.jeequan.jeepay.service.impl.SysRoleEntRelaService;
import
com.jeequan.jeepay.service.impl.SysRoleService
;
import
com.jeequan.jeepay.service.impl.SysUserService
;
import
com.jeequan.jeepay.service.mapper.SysEntitlementMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.authentication.AuthenticationManager
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
...
...
@@ -50,6 +52,7 @@ import java.util.*;
* @site https://www.jeepay.vip
* @date 2021-04-27 15:50
*/
@Slf4j
@Service
public
class
AuthService
{
...
...
@@ -78,8 +81,11 @@ public class AuthService {
Authentication
authentication
=
null
;
try
{
authentication
=
authenticationManager
.
authenticate
(
upToken
);
}
catch
(
JeepayAuthenticationException
jex
)
{
throw
jex
.
getBizException
()
==
null
?
new
BizException
(
jex
.
getMessage
())
:
jex
.
getBizException
();
}
catch
(
AuthenticationException
e
)
{
throw
new
BizException
(
"用户名或密码有误!"
);
log
.
error
(
"AuthenticationException:"
,
e
);
throw
new
BizException
(
"认证服务出现异常, 请重试或联系系统管理员!"
);
}
JeeUserDetails
jeeUserDetails
=
(
JeeUserDetails
)
authentication
.
getPrincipal
();
...
...
Write
Preview
Supports
Markdown
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