Commit f44f1bc1 by linxu

Merge branch 'mcd-jdk17' of ssh://132.232.112.242:7022/lanmw/loginservice into mcd-jdk17

parents 69922cb7 0a1c6eb3
......@@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.provisioning.UserDetailsManager;
import org.springframework.security.web.authentication.WebAuthenticationDetails;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
......@@ -62,7 +63,7 @@ public class LoginManagement {
private AuthService authService;
@Autowired
private CustomizedUserDetailService customizedUserDetailService;
private UserDetailsManager customizedUserDetailService;
@Autowired
private SsoUserRepository ssoUserRepository;
......
......@@ -43,7 +43,7 @@ import java.util.concurrent.TimeUnit;
@Tag(name = "用户中心")
public class PeopleCenterApi {
private static final Logger log = LoggerFactory.getLogger(LoginManagement.class);
private static final Logger log = LoggerFactory.getLogger(PeopleCenterApi.class);
@Value("${peopleCenter.sysSecret}")
private String sysSecret;
......
//package com.keymobile.login.conf;
//
//import com.keymobile.auth.common.security.CustomizedUserDetailService;
//import org.springframework.beans.factory.annotation.Autowired;
//
//import org.springframework.context.annotation.ComponentScan;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.crypto.password.NoOpPasswordEncoder;
//
//
//@Configuration
//@ComponentScan("com.keymobile.auth.common.security")
//public class SecurityConfig extends WebSecurityConfigurerAdapter {
//
// @Autowired
// private CustomizedUserDetailService customUserDetailService;
// @Autowired
// private RESTAuthenticationEntryPoint authenticationEntryPoint;
// @Autowired
// private RESTAuthenticationFailureHandler authenticationFailureHandler;
// @Autowired
// private RESTAuthenticationSuccessHandler authenticationSuccessHandler;
// @Autowired
// private RESTLogoutSuccessHandler logoutSuccessHandler;
//
// @Autowired
// public void configure(AuthenticationManagerBuilder auth) throws Exception {
// auth.userDetailsService(customUserDetailService).passwordEncoder(NoOpPasswordEncoder.getInstance());
// }
//
// @Override
// protected void configure(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);
// }
//
//}
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 SecurityConfig {
@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 {
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;
import com.keymobile.auth.common.security.CustomizedUserDetailService;
import org.springframework.stereotype.Service;
import javax.sql.DataSource;
@Service
public class CustomizedUserDetailServiceImpl extends CustomizedUserDetailService {
public CustomizedUserDetailServiceImpl(DataSource dataSource) {
super(dataSource);
}
}
//package com.keymobile.login.service;
//
//import com.keymobile.auth.common.security.CustomizedUserDetailService;
//import org.springframework.stereotype.Service;
//
//import javax.sql.DataSource;
//
//@Service
//public class CustomizedUserDetailServiceImpl extends CustomizedUserDetailService {
//
// public CustomizedUserDetailServiceImpl(DataSource 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