Commit 151fad0e by hzc

完成sso登录

parent c0315a76
......@@ -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;
// }
/**
* 验证用户登录
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment