Commit 151fad0e by hzc

完成sso登录

parent c0315a76
...@@ -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;
} // }
/** /**
* 验证用户登录 * 验证用户登录
* *
......
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