Commit d1d1e990 by xieshaohua

修复登录bug

parent fdccd9c0
...@@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Value; ...@@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.provisioning.UserDetailsManager;
import org.springframework.security.web.authentication.WebAuthenticationDetails; import org.springframework.security.web.authentication.WebAuthenticationDetails;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -62,7 +63,7 @@ public class LoginManagement { ...@@ -62,7 +63,7 @@ public class LoginManagement {
private AuthService authService; private AuthService authService;
@Autowired @Autowired
private CustomizedUserDetailService customizedUserDetailService; private UserDetailsManager customizedUserDetailService;
@Autowired @Autowired
private SsoUserRepository ssoUserRepository; private SsoUserRepository ssoUserRepository;
......
...@@ -43,7 +43,7 @@ import java.util.concurrent.TimeUnit; ...@@ -43,7 +43,7 @@ import java.util.concurrent.TimeUnit;
@Tag(name = "用户中心") @Tag(name = "用户中心")
public class PeopleCenterApi { public class PeopleCenterApi {
private static final Logger log = LoggerFactory.getLogger(LoginManagement.class); private static final Logger log = LoggerFactory.getLogger(PeopleCenterApi.class);
@Value("${peopleCenter.sysSecret}") @Value("${peopleCenter.sysSecret}")
private String sysSecret; private String sysSecret;
......
//package com.keymobile.login.conf; package com.keymobile.login.conf;
//
//import com.keymobile.auth.common.security.CustomizedUserDetailService; import com.keymobile.auth.common.security.CustomizedUserDetailService;
//import org.springframework.beans.factory.annotation.Autowired; import org.apache.commons.codec.digest.DigestUtils;
// import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.ComponentScan; import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Bean;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.context.annotation.ComponentScan;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.context.annotation.Configuration;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
//import org.springframework.security.crypto.password.NoOpPasswordEncoder; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
// import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
// import org.springframework.security.crypto.password.NoOpPasswordEncoder;
//@Configuration import org.springframework.security.crypto.password.PasswordEncoder;
//@ComponentScan("com.keymobile.auth.common.security") import org.springframework.security.provisioning.UserDetailsManager;
//public class SecurityConfig extends WebSecurityConfigurerAdapter { import org.springframework.security.web.SecurityFilterChain;
//
// @Autowired import javax.sql.DataSource;
// private CustomizedUserDetailService customUserDetailService;
// @Autowired /**
// private RESTAuthenticationEntryPoint authenticationEntryPoint; * SecurityConfig.
// @Autowired * @author mahx
// private RESTAuthenticationFailureHandler authenticationFailureHandler; * @version 1.0
// @Autowired * @date 2019/12/27 16:55
// private RESTAuthenticationSuccessHandler authenticationSuccessHandler; */
// @Autowired @Configuration
// private RESTLogoutSuccessHandler logoutSuccessHandler; @EnableWebSecurity
// @EnableGlobalMethodSecurity(prePostEnabled = true)
// @Autowired @ComponentScan("com.keymobile.auth.common.security")
// public void configure(AuthenticationManagerBuilder auth) throws Exception { public class SecurityConfig {
// auth.userDetailsService(customUserDetailService).passwordEncoder(NoOpPasswordEncoder.getInstance());
// } @Autowired
// private RESTAuthenticationEntryPoint authenticationEntryPoint;
// @Override @Autowired
// protected void configure(HttpSecurity http) throws Exception { private RESTAuthenticationFailureHandler authenticationFailureHandler;
// http.authorizeRequests().anyRequest().permitAll(); @Autowired
// http.csrf().disable(); private RESTAuthenticationSuccessHandler authenticationSuccessHandler;
// http.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint); @Autowired
// http.formLogin().successHandler(authenticationSuccessHandler); private RESTLogoutSuccessHandler logoutSuccessHandler;
// http.formLogin().failureHandler(authenticationFailureHandler);
// http.formLogin().loginPage("/login"); @Bean
// http.formLogin().loginProcessingUrl("/signin"); public UserDetailsManager users(DataSource dataSource) {
// http.logout().logoutUrl("/signout"); return new CustomizedUserDetailService(dataSource);
// http.logout().logoutSuccessHandler(logoutSuccessHandler); }
// }
// @Bean
//} public PasswordEncoder passwordEncoder() {
return NoOpPasswordEncoder.getInstance();
}
@Bean
protected SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll();
http.csrf().disable();
http.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint);
http.formLogin().successHandler(authenticationSuccessHandler);
http.formLogin().failureHandler(authenticationFailureHandler);
http.formLogin().loginPage("/login");
http.formLogin().loginProcessingUrl("/signin");
http.logout().logoutUrl("/signout");
http.logout().logoutSuccessHandler(logoutSuccessHandler);
return http.build();
}
class SHA1PasswordEncoder implements PasswordEncoder {
@Override
public String encode(CharSequence charSequence) {
return DigestUtils.sha1Hex(charSequence.toString());
}
@Override
public boolean matches(CharSequence charSequence, String s) {
return DigestUtils.sha1Hex(charSequence.toString()).equals(s);
}
}
}
package com.keymobile.login.conf;
import com.keymobile.auth.common.security.CustomizedUserDetailService;
import org.apache.commons.codec.digest.DigestUtils;
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.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.UserDetailsManager;
import org.springframework.security.web.SecurityFilterChain;
import javax.sql.DataSource;
/**
* SecurityConfig.
* @author mahx
* @version 1.0
* @date 2019/12/27 16:55
*/
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
@ComponentScan("com.keymobile.auth.common.security")
public class SecurityNewConfig {
@Value("${security.permit}")
private boolean permit;
@Autowired
private CustomizedUserDetailService customUserDetailService;
@Autowired
private RESTAuthenticationEntryPoint authenticationEntryPoint;
@Autowired
private RESTAuthenticationFailureHandler authenticationFailureHandler;
@Autowired
private RESTAuthenticationSuccessHandler authenticationSuccessHandler;
@Autowired
private RESTLogoutSuccessHandler logoutSuccessHandler;
@Bean
public UserDetailsManager users(DataSource dataSource) {
return new CustomizedUserDetailService(dataSource);
}
@Bean
public PasswordEncoder passwordEncoder() {
return NoOpPasswordEncoder.getInstance();
}
@Bean
protected SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
if (permit) {
http.httpBasic().and().authorizeHttpRequests().anyRequest().permitAll();
} else {
http.httpBasic().and().authorizeHttpRequests().requestMatchers("/actuator/**").permitAll()
.and().authorizeHttpRequests().anyRequest().authenticated();
}
http.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint);
http.formLogin().successHandler(authenticationSuccessHandler);
http.formLogin().failureHandler(authenticationFailureHandler);
http.formLogin().loginPage("/login");
http.formLogin().loginProcessingUrl("/signin");
http.logout().logoutUrl("/signout");
http.logout().logoutSuccessHandler(logoutSuccessHandler);
http.csrf().disable();
return http.build();
}
class SHA1PasswordEncoder implements PasswordEncoder {
@Override
public String encode(CharSequence charSequence) {
return DigestUtils.sha1Hex(charSequence.toString());
}
@Override
public boolean matches(CharSequence charSequence, String s) {
return DigestUtils.sha1Hex(charSequence.toString()).equals(s);
}
}
}
package com.keymobile.login.service; //package com.keymobile.login.service;
//
import com.keymobile.auth.common.security.CustomizedUserDetailService; //import com.keymobile.auth.common.security.CustomizedUserDetailService;
import org.springframework.stereotype.Service; //import org.springframework.stereotype.Service;
//
import javax.sql.DataSource; //import javax.sql.DataSource;
//
@Service //@Service
public class CustomizedUserDetailServiceImpl extends CustomizedUserDetailService { //public class CustomizedUserDetailServiceImpl extends CustomizedUserDetailService {
//
public CustomizedUserDetailServiceImpl(DataSource dataSource) { // public CustomizedUserDetailServiceImpl(DataSource dataSource) {
super(dataSource); // super(dataSource);
} // }
} //}
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