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
33944ab7
Commit
33944ab7
authored
Mar 30, 2021
by
huangkp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
单点登录支持ad认证和平台用户认证
parent
8fb67f02
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
20 deletions
+34
-20
RESTAuthenticationSuccessHandler.java
...eymobile/proxy/conf/RESTAuthenticationSuccessHandler.java
+1
-3
SecurityConfig.java
src/main/java/com/keymobile/proxy/conf/SecurityConfig.java
+33
-17
No files found.
src/main/java/com/keymobile/proxy/conf/RESTAuthenticationSuccessHandler.java
View file @
33944ab7
...
@@ -50,9 +50,7 @@ public class RESTAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuc
...
@@ -50,9 +50,7 @@ public class RESTAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuc
&&
!
rootAllowLogin
)
&&
!
rootAllowLogin
)
returnStatus
=
"root not allow login"
;
returnStatus
=
"root not allow login"
;
if
(
StringUtils
.
equals
(
returnStatus
,
"ok"
))
{
LogManager
.
logInfo
(
Constants
.
LOG_AUTH_LOGIN_API
,
"登录"
,
null
);
LogManager
.
logInfo
(
Constants
.
LOG_AUTH_LOGIN_API
,
"登录"
,
null
);
}
response
.
sendRedirect
(
"/go"
);
response
.
sendRedirect
(
"/go"
);
PrintWriter
writer
=
response
.
getWriter
();
PrintWriter
writer
=
response
.
getWriter
();
...
...
src/main/java/com/keymobile/proxy/conf/SecurityConfig.java
View file @
33944ab7
...
@@ -3,9 +3,11 @@ package com.keymobile.proxy.conf;
...
@@ -3,9 +3,11 @@ package com.keymobile.proxy.conf;
import
com.keymobile.proxy.api.Constants
;
import
com.keymobile.proxy.api.Constants
;
import
com.keymobile.proxy.service.PortalService
;
import
com.keymobile.proxy.service.PortalService
;
import
com.keymobile.proxy.util.Des
;
import
com.keymobile.proxy.util.Des
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
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.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
...
@@ -37,6 +39,12 @@ import java.util.Properties;
...
@@ -37,6 +39,12 @@ import java.util.Properties;
@Configuration
@Configuration
public
class
SecurityConfig
extends
WebSecurityConfigurerAdapter
{
public
class
SecurityConfig
extends
WebSecurityConfigurerAdapter
{
@Value
(
"${ad-authenticate.domain}"
)
private
String
authDomain
;
@Value
(
"${ad-authenticate.provider-url}"
)
private
String
providerUrl
;
private
Logger
logger
=
LoggerFactory
.
getLogger
(
SecurityConfig
.
class
);
private
Logger
logger
=
LoggerFactory
.
getLogger
(
SecurityConfig
.
class
);
private
static
final
String
usersQuery
=
"select concat(user_id, ':', id, ':', disname, ':', org_no), `password`, true from p_user where user_id = ? and `status` = '1'"
;
private
static
final
String
usersQuery
=
"select concat(user_id, ':', id, ':', disname, ':', org_no), `password`, true from p_user where user_id = ? and `status` = '1'"
;
...
@@ -67,6 +75,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -67,6 +75,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
@Autowired
private
PortalService
portalService
;
private
PortalService
portalService
;
@Value
(
"${auth-login.adAuth}"
)
private
Boolean
authAdLogin
;
@Autowired
@Autowired
public
void
configure
(
AuthenticationManagerBuilder
auth
)
throws
Exception
{
public
void
configure
(
AuthenticationManagerBuilder
auth
)
throws
Exception
{
auth
.
jdbcAuthentication
().
usersByUsernameQuery
(
usersQuery
).
authoritiesByUsernameQuery
(
rolesQuery
)
auth
.
jdbcAuthentication
().
usersByUsernameQuery
(
usersQuery
).
authoritiesByUsernameQuery
(
rolesQuery
)
...
@@ -102,12 +113,14 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -102,12 +113,14 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
httpServletResponse
.
sendError
(
500
,
"sso login url missing request param"
);
httpServletResponse
.
sendError
(
500
,
"sso login url missing request param"
);
return
null
;
return
null
;
}
}
Des
des
=
new
Des
();
if
(
authAdLogin
)
{
String
pwd
=
des
.
strDec
(
portal_password
,
key
);
Des
des
=
new
Des
();
logger
.
info
(
"sso login param->userName:"
+
username
+
" pwd:"
+
pwd
);
String
pwd
=
des
.
strDec
(
portal_password
,
key
);
if
(!
authenticate
(
username
,
pwd
)){
logger
.
info
(
"sso login param->userName:"
+
username
+
" pwd:"
+
pwd
);
httpServletResponse
.
sendError
(
500
,
CallBack
+
"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});"
);
if
(!
authenticate
(
username
,
pwd
)){
return
null
;
httpServletResponse
.
sendError
(
500
,
CallBack
+
"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});"
);
return
null
;
}
}
}
httpServletRequest
.
getSession
().
setAttribute
(
"ssoLogin"
,
CallBack
+
"({'query':{'results':{'postresult':'portal_ssologin_succeed'}}});"
);
httpServletRequest
.
getSession
().
setAttribute
(
"ssoLogin"
,
CallBack
+
"({'query':{'results':{'postresult':'portal_ssologin_succeed'}}});"
);
com
.
keymobile
.
proxy
.
model
.
User
user
=
portalService
.
getUserByUserId
(
username
);
com
.
keymobile
.
proxy
.
model
.
User
user
=
portalService
.
getUserByUserId
(
username
);
...
@@ -116,6 +129,13 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -116,6 +129,13 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
httpServletResponse
.
sendError
(
500
,
CallBack
+
"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});"
);
httpServletResponse
.
sendError
(
500
,
CallBack
+
"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});"
);
return
null
;
return
null
;
}
}
if
(!
authAdLogin
)
{
if
(!
StringUtils
.
equals
(
user
.
getPassword
(),
portal_password
))
{
logger
.
error
(
username
+
" password:"
+
portal_password
+
" is error"
);
httpServletResponse
.
sendError
(
500
,
CallBack
+
"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});"
);
return
null
;
}
}
List
<
GrantedAuthority
>
authorities
=
new
ArrayList
<>();
List
<
GrantedAuthority
>
authorities
=
new
ArrayList
<>();
String
userName
=
user
.
getUserId
()
+
":"
+
user
.
getId
()
+
":"
+
user
.
getDisname
()
+
":"
+
user
.
getOrgNo
();
String
userName
=
user
.
getUserId
()
+
":"
+
user
.
getId
()
+
":"
+
user
.
getDisname
()
+
":"
+
user
.
getOrgNo
();
List
<
String
>
authors
=
portalService
.
getByUserId
(
username
);
List
<
String
>
authors
=
portalService
.
getByUserId
(
username
);
...
@@ -133,46 +153,42 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -133,46 +153,42 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
return
authenticationFilter
;
return
authenticationFilter
;
}
}
/**
/**
* 验证用户登录
* 验证用户登录
*
*
* @param user
Name
* @param user
ID
* String 用户名格式为 username或者username@hntobacco.com
* String 用户名格式为 username或者username@hntobacco.com
湖南内网的domain必须是@hntobacco.com,不是hnyc.com
湖南内网的domain必须是@hntobacco.com,不是hnyc.com
* @param password
* @param password
* String
* String
* @return boolean
* @return boolean
*/
*/
public
boolean
authenticate
(
String
user
Name
,
String
password
)
{
public
boolean
authenticate
(
String
user
ID
,
String
password
)
{
if
(
password
!=
null
&&
!
""
.
equals
(
password
.
trim
()))
{
if
(
password
!=
null
&&
!
""
.
equals
(
password
.
trim
()))
{
DirContext
ctx1
;
DirContext
ctx1
;
try
{
try
{
String
domain
=
"@
hntobacco.com"
;
String
domain
=
"@
"
+
authDomain
;
Properties
ldapEnv
=
new
Properties
();
Properties
ldapEnv
=
new
Properties
();
ldapEnv
.
put
(
Context
.
INITIAL_CONTEXT_FACTORY
,
ldapEnv
.
put
(
Context
.
INITIAL_CONTEXT_FACTORY
,
"com.sun.jndi.ldap.LdapCtxFactory"
);
"com.sun.jndi.ldap.LdapCtxFactory"
);
ldapEnv
.
put
(
Context
.
PROVIDER_URL
,
"ldap://hntobacco.com:389"
);
//服务器必须配置DNS,否则无法解析hntobacc.com
ldapEnv
.
put
(
Context
.
PROVIDER_URL
,
providerUrl
);
//服务器必须配置DNS,否则无法解析hntobacc.com
ldapEnv
.
put
(
Context
.
SECURITY_AUTHENTICATION
,
"simple"
);
ldapEnv
.
put
(
Context
.
SECURITY_AUTHENTICATION
,
"simple"
);
String
user
=
user
Name
.
indexOf
(
domain
)
>
0
?
userName
:
userName
String
user
=
user
ID
.
indexOf
(
domain
)
>
0
?
userID
:
userID
+
domain
;
+
domain
;
ldapEnv
.
put
(
Context
.
SECURITY_PRINCIPAL
,
user
);
ldapEnv
.
put
(
Context
.
SECURITY_PRINCIPAL
,
user
);
ldapEnv
.
put
(
Context
.
SECURITY_CREDENTIALS
,
password
);
ldapEnv
.
put
(
Context
.
SECURITY_CREDENTIALS
,
password
);
ctx1
=
new
InitialDirContext
(
ldapEnv
);
ctx1
=
new
InitialDirContext
(
ldapEnv
);
ctx1
.
close
();
ctx1
.
close
();
logger
.
info
(
"登录验证成功!"
);
return
true
;
return
true
;
}
catch
(
javax
.
naming
.
AuthenticationException
e
)
{
}
catch
(
AuthenticationException
e
)
{
logger
.
info
(
"登录失败!"
+
e
.
getLocalizedMessage
()
);
System
.
out
.
println
(
"登录失败!"
);
e
.
printStackTrace
();
e
.
printStackTrace
();
return
false
;
return
false
;
}
catch
(
NamingException
e
)
{
}
catch
(
NamingException
e
)
{
logger
.
info
(
"登录失败!"
+
e
.
getLocalizedMessage
());
e
.
printStackTrace
();
e
.
printStackTrace
();
return
false
;
return
false
;
}
}
}
else
{
}
else
{
logger
.
info
(
"登录验证失败!"
);
return
false
;
return
false
;
}
}
}
}
...
...
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