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
151fad0e
Commit
151fad0e
authored
Jun 25, 2021
by
hzc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成sso登录
parent
c0315a76
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
72 deletions
+72
-72
SecurityConfig.java
src/main/java/com/keymobile/proxy/conf/SecurityConfig.java
+72
-72
No files found.
src/main/java/com/keymobile/proxy/conf/SecurityConfig.java
View file @
151fad0e
...
@@ -97,7 +97,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -97,7 +97,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
http
.
formLogin
().
successHandler
(
authenticationSuccessHandler
);
http
.
formLogin
().
successHandler
(
authenticationSuccessHandler
);
http
.
formLogin
().
failureHandler
(
authenticationFailureHandler
);
http
.
formLogin
().
failureHandler
(
authenticationFailureHandler
);
http
.
formLogin
().
loginPage
(
"/login"
);
http
.
formLogin
().
loginPage
(
"/login"
);
//
http.formLogin().loginProcessingUrl("/signin");
http
.
formLogin
().
loginProcessingUrl
(
"/signin"
);
http
.
logout
().
logoutUrl
(
"/signout"
);
http
.
logout
().
logoutUrl
(
"/signout"
);
http
.
logout
().
logoutSuccessHandler
(
logoutSuccessHandler
);
http
.
logout
().
logoutSuccessHandler
(
logoutSuccessHandler
);
http
.
sessionManagement
().
maximumSessions
(
1
).
expiredUrl
(
"/login"
);
http
.
sessionManagement
().
maximumSessions
(
1
).
expiredUrl
(
"/login"
);
...
@@ -125,77 +125,77 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -125,77 +125,77 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
authenticationFilter
.
setAuthenticationSuccessHandler
(
authenticationSuccessHandler
);
authenticationFilter
.
setAuthenticationSuccessHandler
(
authenticationSuccessHandler
);
return
authenticationFilter
;
return
authenticationFilter
;
}
}
@Bean
//
@Bean
public
AbstractAuthenticationProcessingFilter
authenticationFilter1
()
throws
Exception
{
//
public AbstractAuthenticationProcessingFilter authenticationFilter1() throws Exception {
AbstractAuthenticationProcessingFilter
authenticationFilter
=
new
AbstractAuthenticationProcessingFilter
(
"/signin"
)
{
//
AbstractAuthenticationProcessingFilter authenticationFilter = new AbstractAuthenticationProcessingFilter("/signin") {
@Override
//
@Override
public
Authentication
attemptAuthentication
(
HttpServletRequest
httpServletRequest
,
HttpServletResponse
httpServletResponse
)
throws
AuthenticationException
,
IOException
,
ServletException
{
//
public Authentication attemptAuthentication(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws AuthenticationException, IOException, ServletException {
String
portal_actionURL
=
httpServletRequest
.
getParameter
(
"portal_actionURL"
);
//
String portal_actionURL = httpServletRequest.getParameter("portal_actionURL");
String
username
=
httpServletRequest
.
getParameter
(
"username"
);
//
String username = httpServletRequest.getParameter("username");
String
portal_password
=
httpServletRequest
.
getParameter
(
"password"
);
//
String portal_password = httpServletRequest.getParameter("password");
String
CallBack
=
""
;
//
String CallBack = "";
if
(
null
==
username
||
null
==
portal_password
){
//
if(null == username || null == portal_password){
// httpServletResponse.sendError(200,"sso login url missing request param");
//
// httpServletResponse.sendError(200,"sso login url missing request param");
httpServletResponse
.
setStatus
(
401
);
//
httpServletResponse.setStatus(401);
PrintWriter
writer
=
httpServletResponse
.
getWriter
();
//
PrintWriter writer = httpServletResponse.getWriter();
writer
.
write
(
CallBack
+
"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});"
);
//
writer.write(CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
writer
.
flush
();
//
writer.flush();
writer
.
close
();
//
writer.close();
return
null
;
//
return null;
}
//
}
if
(
authAdLogin
)
{
//
if (authAdLogin) {
// logger.info("signin login param->userName:"+username+" pwd:"+portal_password);
//
// logger.info("signin login param->userName:"+username+" pwd:"+portal_password);
//
if
(!
authenticate
(
username
,
portal_password
)){
//
if(!authenticate(username,portal_password)){
httpServletResponse
.
setStatus
(
401
);
//
httpServletResponse.setStatus(401);
PrintWriter
writer
=
httpServletResponse
.
getWriter
();
//
PrintWriter writer = httpServletResponse.getWriter();
writer
.
write
(
CallBack
+
"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});"
);
//
writer.write(CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
writer
.
flush
();
//
writer.flush();
writer
.
close
();
//
writer.close();
// httpServletResponse.sendError(200,CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
//
// httpServletResponse.sendError(200,CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
return
null
;
//
return null;
}
//
}
}
//
}
httpServletRequest
.
getSession
().
setAttribute
(
"loginMsg"
,
"ok"
);
//
httpServletRequest.getSession().setAttribute("loginMsg","ok");
com
.
keymobile
.
proxy
.
model
.
User
user
=
portalService
.
getUserByUserId
(
username
);
//
com.keymobile.proxy.model.User user = portalService.getUserByUserId(username);
if
(
user
==
null
)
{
//
if (user == null) {
logger
.
error
(
username
+
" is not exit"
);
//
logger.error(username + " is not exit");
// httpServletResponse.sendError(200,CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
//
// httpServletResponse.sendError(200,CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
httpServletResponse
.
setStatus
(
401
);
//
httpServletResponse.setStatus(401);
PrintWriter
writer
=
httpServletResponse
.
getWriter
();
//
PrintWriter writer = httpServletResponse.getWriter();
writer
.
write
(
CallBack
+
"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});"
);
//
writer.write(CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
writer
.
flush
();
//
writer.flush();
writer
.
close
();
//
writer.close();
return
null
;
//
return null;
}
//
}
if
(!
authAdLogin
)
{
//
if (! authAdLogin) {
if
(!
StringUtils
.
equals
(
user
.
getPassword
(),
portal_password
))
{
//
if (! StringUtils.equals(user.getPassword(), portal_password)) {
logger
.
error
(
username
+
" password is error"
);
//
logger.error(username + " password is error");
httpServletResponse
.
setStatus
(
401
);
//
httpServletResponse.setStatus(401);
PrintWriter
writer
=
httpServletResponse
.
getWriter
();
//
PrintWriter writer = httpServletResponse.getWriter();
writer
.
write
(
CallBack
+
"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});"
);
//
writer.write(CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
writer
.
flush
();
//
writer.flush();
writer
.
close
();
//
writer.close();
// httpServletResponse.sendError(200,CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
//
// httpServletResponse.sendError(200,CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
return
null
;
//
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);
if
(!
CollectionUtils
.
isEmpty
(
authors
))
{
//
if (! CollectionUtils.isEmpty(authors)) {
for
(
String
author
:
authors
)
{
//
for (String author : authors) {
GrantedAuthority
authorityInfo
=
new
SimpleGrantedAuthority
(
Constants
.
ROLE_PREFIX
+
author
);
//
GrantedAuthority authorityInfo = new SimpleGrantedAuthority(Constants.ROLE_PREFIX + author);
authorities
.
add
(
authorityInfo
);
//
authorities.add(authorityInfo);
}
//
}
}
//
}
return
new
UsernamePasswordAuthenticationToken
(
new
User
(
userName
,
user
.
getPassword
(),
authorities
),
null
,
authorities
);
//
return new UsernamePasswordAuthenticationToken(new User(userName, user.getPassword(), authorities), null, authorities);
}
//
}
};
//
};
authenticationFilter
.
setAuthenticationManager
(
authenticationManager
());
//
authenticationFilter.setAuthenticationManager(authenticationManager());
authenticationFilter
.
setAuthenticationSuccessHandler
(
authenticationSuccessHandler
);
//
authenticationFilter.setAuthenticationSuccessHandler(authenticationSuccessHandler);
return
authenticationFilter
;
//
return authenticationFilter;
}
//
}
/**
/**
* 验证用户登录
* 验证用户登录
*
*
...
...
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