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
Hide 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 {
http
.
formLogin
().
successHandler
(
authenticationSuccessHandler
);
http
.
formLogin
().
failureHandler
(
authenticationFailureHandler
);
http
.
formLogin
().
loginPage
(
"/login"
);
//
http.formLogin().loginProcessingUrl("/signin");
http
.
formLogin
().
loginProcessingUrl
(
"/signin"
);
http
.
logout
().
logoutUrl
(
"/signout"
);
http
.
logout
().
logoutSuccessHandler
(
logoutSuccessHandler
);
http
.
sessionManagement
().
maximumSessions
(
1
).
expiredUrl
(
"/login"
);
...
...
@@ -125,77 +125,77 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
authenticationFilter
.
setAuthenticationSuccessHandler
(
authenticationSuccessHandler
);
return
authenticationFilter
;
}
@Bean
public
AbstractAuthenticationProcessingFilter
authenticationFilter1
()
throws
Exception
{
AbstractAuthenticationProcessingFilter
authenticationFilter
=
new
AbstractAuthenticationProcessingFilter
(
"/signin"
)
{
@Override
public
Authentication
attemptAuthentication
(
HttpServletRequest
httpServletRequest
,
HttpServletResponse
httpServletResponse
)
throws
AuthenticationException
,
IOException
,
ServletException
{
String
portal_actionURL
=
httpServletRequest
.
getParameter
(
"portal_actionURL"
);
String
username
=
httpServletRequest
.
getParameter
(
"username"
);
String
portal_password
=
httpServletRequest
.
getParameter
(
"password"
);
String
CallBack
=
""
;
if
(
null
==
username
||
null
==
portal_password
){
// httpServletResponse.sendError(200,"sso login url missing request param");
httpServletResponse
.
setStatus
(
401
);
PrintWriter
writer
=
httpServletResponse
.
getWriter
();
writer
.
write
(
CallBack
+
"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});"
);
writer
.
flush
();
writer
.
close
();
return
null
;
}
if
(
authAdLogin
)
{
// logger.info("signin login param->userName:"+username+" pwd:"+portal_password);
if
(!
authenticate
(
username
,
portal_password
)){
httpServletResponse
.
setStatus
(
401
);
PrintWriter
writer
=
httpServletResponse
.
getWriter
();
writer
.
write
(
CallBack
+
"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});"
);
writer
.
flush
();
writer
.
close
();
// httpServletResponse.sendError(200,CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
return
null
;
}
}
httpServletRequest
.
getSession
().
setAttribute
(
"loginMsg"
,
"ok"
);
com
.
keymobile
.
proxy
.
model
.
User
user
=
portalService
.
getUserByUserId
(
username
);
if
(
user
==
null
)
{
logger
.
error
(
username
+
" is not exit"
);
// httpServletResponse.sendError(200,CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
httpServletResponse
.
setStatus
(
401
);
PrintWriter
writer
=
httpServletResponse
.
getWriter
();
writer
.
write
(
CallBack
+
"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});"
);
writer
.
flush
();
writer
.
close
();
return
null
;
}
if
(!
authAdLogin
)
{
if
(!
StringUtils
.
equals
(
user
.
getPassword
(),
portal_password
))
{
logger
.
error
(
username
+
" password is error"
);
httpServletResponse
.
setStatus
(
401
);
PrintWriter
writer
=
httpServletResponse
.
getWriter
();
writer
.
write
(
CallBack
+
"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});"
);
writer
.
flush
();
writer
.
close
();
// httpServletResponse.sendError(200,CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
return
null
;
}
}
List
<
GrantedAuthority
>
authorities
=
new
ArrayList
<>();
String
userName
=
user
.
getUserId
()
+
":"
+
user
.
getId
()
+
":"
+
user
.
getDisname
()
+
":"
+
user
.
getOrgNo
();
List
<
String
>
authors
=
portalService
.
getByUserId
(
username
);
if
(!
CollectionUtils
.
isEmpty
(
authors
))
{
for
(
String
author
:
authors
)
{
GrantedAuthority
authorityInfo
=
new
SimpleGrantedAuthority
(
Constants
.
ROLE_PREFIX
+
author
);
authorities
.
add
(
authorityInfo
);
}
}
return
new
UsernamePasswordAuthenticationToken
(
new
User
(
userName
,
user
.
getPassword
(),
authorities
),
null
,
authorities
);
}
};
authenticationFilter
.
setAuthenticationManager
(
authenticationManager
());
authenticationFilter
.
setAuthenticationSuccessHandler
(
authenticationSuccessHandler
);
return
authenticationFilter
;
}
//
@Bean
//
public AbstractAuthenticationProcessingFilter authenticationFilter1() throws Exception {
//
AbstractAuthenticationProcessingFilter authenticationFilter = new AbstractAuthenticationProcessingFilter("/signin") {
//
@Override
//
public Authentication attemptAuthentication(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws AuthenticationException, IOException, ServletException {
//
String portal_actionURL = httpServletRequest.getParameter("portal_actionURL");
//
String username = httpServletRequest.getParameter("username");
//
String portal_password = httpServletRequest.getParameter("password");
//
String CallBack = "";
//
if(null == username || null == portal_password){
//
// httpServletResponse.sendError(200,"sso login url missing request param");
//
httpServletResponse.setStatus(401);
//
PrintWriter writer = httpServletResponse.getWriter();
//
writer.write(CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
//
writer.flush();
//
writer.close();
//
return null;
//
}
//
if (authAdLogin) {
//
// logger.info("signin login param->userName:"+username+" pwd:"+portal_password);
//
//
if(!authenticate(username,portal_password)){
//
httpServletResponse.setStatus(401);
//
PrintWriter writer = httpServletResponse.getWriter();
//
writer.write(CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
//
writer.flush();
//
writer.close();
//
// httpServletResponse.sendError(200,CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
//
return null;
//
}
//
}
//
httpServletRequest.getSession().setAttribute("loginMsg","ok");
//
com.keymobile.proxy.model.User user = portalService.getUserByUserId(username);
//
if (user == null) {
//
logger.error(username + " is not exit");
//
// httpServletResponse.sendError(200,CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
//
httpServletResponse.setStatus(401);
//
PrintWriter writer = httpServletResponse.getWriter();
//
writer.write(CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
//
writer.flush();
//
writer.close();
//
return null;
//
}
//
if (! authAdLogin) {
//
if (! StringUtils.equals(user.getPassword(), portal_password)) {
//
logger.error(username + " password is error");
//
httpServletResponse.setStatus(401);
//
PrintWriter writer = httpServletResponse.getWriter();
//
writer.write(CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
//
writer.flush();
//
writer.close();
//
// httpServletResponse.sendError(200,CallBack+"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});");
//
return null;
//
}
//
}
//
List<GrantedAuthority> authorities = new ArrayList<>();
//
String userName = user.getUserId() + ":" + user.getId() + ":" + user.getDisname() + ":" + user.getOrgNo();
//
List<String> authors = portalService.getByUserId(username);
//
if (! CollectionUtils.isEmpty(authors)) {
//
for (String author : authors) {
//
GrantedAuthority authorityInfo = new SimpleGrantedAuthority(Constants.ROLE_PREFIX + author);
//
authorities.add(authorityInfo);
//
}
//
}
//
return new UsernamePasswordAuthenticationToken(new User(userName, user.getPassword(), authorities), null, authorities);
//
}
//
};
//
authenticationFilter.setAuthenticationManager(authenticationManager());
//
authenticationFilter.setAuthenticationSuccessHandler(authenticationSuccessHandler);
//
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