Commit f082635f by linxu

refactor

parent 6674cb9d
package com.keymobile.login; package com.keymobile.sso;
import com.keymobile.authservice.component.SecurityConfig;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.PropertySource; import org.springframework.context.annotation.PropertySource;
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient @EnableDiscoveryClient
@ComponentScan(basePackages = {"com.keymobile.config.logging", "com.keymobile.config.naming", @ComponentScan(basePackages = {"com.keymobile.sso",
"com.keymobile.config.redisclient"}) "com.keymobile.config.logging", "com.keymobile.config.naming",
"com.keymobile.config.redisclient", "com.keymobile.authservice.component"}, excludeFilters = {
@ComponentScan.Filter(type= FilterType.ASSIGNABLE_TYPE, value= SecurityConfig.class)
})
@PropertySource(value = "classpath:/application.yml") @PropertySource(value = "classpath:/application.yml")
public class SsoApplication { public class SsoApplication {
......
package com.keymobile.login.api; package com.keymobile.sso.api;
public class Constants { public class Constants {
......
package com.keymobile.login.api; package com.keymobile.sso.api;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
......
package com.keymobile.login.conf; package com.keymobile.sso.conf;
import jakarta.servlet.ServletException; import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
......
package com.keymobile.login.conf; package com.keymobile.sso.conf;
import jakarta.servlet.ServletException; import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
......
package com.keymobile.login.conf; package com.keymobile.sso.conf;
import jakarta.servlet.ServletException; import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
...@@ -15,7 +15,7 @@ import java.io.PrintWriter; ...@@ -15,7 +15,7 @@ import java.io.PrintWriter;
@Component @Component
public class RESTAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler { public class RESTAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
@Value("${security.allowRootLogin:true}") @Value("${self.web.login.allowRoot:true}")
private boolean rootAllowLogin = true; private boolean rootAllowLogin = true;
@Override @Override
......
package com.keymobile.login.conf; package com.keymobile.sso.conf;
import jakarta.servlet.ServletException; import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
......
package com.keymobile.login.conf; package com.keymobile.sso.conf;
import com.keymobile.authservice.component.CustomizedUserDetailService;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; 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.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.crypto.password.NoOpPasswordEncoder; import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.UserDetailsManager;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
import javax.sql.DataSource;
@Configuration @Configuration
@EnableWebSecurity @EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true) public class SsoSecurityConfig {
@ComponentScan("com.keymobile.authservice.component")
public class SecurityConfig {
@Autowired @Autowired
private RESTAuthenticationEntryPoint authenticationEntryPoint; private RESTAuthenticationEntryPoint authenticationEntryPoint;
...@@ -36,27 +27,32 @@ public class SecurityConfig { ...@@ -36,27 +27,32 @@ public class SecurityConfig {
private RESTLogoutSuccessHandler logoutSuccessHandler; private RESTLogoutSuccessHandler logoutSuccessHandler;
@Bean @Bean
public UserDetailsManager users(DataSource dataSource) {
return new CustomizedUserDetailService(dataSource);
}
@Bean
public PasswordEncoder passwordEncoder() { public PasswordEncoder passwordEncoder() {
return NoOpPasswordEncoder.getInstance(); return NoOpPasswordEncoder.getInstance();
} }
@Bean @Bean
protected SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { protected SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests((request) -> {
request.anyRequest().permitAll();
});
http.csrf((httpSecurityCsrfConfigurer) -> {
httpSecurityCsrfConfigurer.disable();
});
http.exceptionHandling((exceptionHandling) -> {
exceptionHandling.authenticationEntryPoint(authenticationEntryPoint);
});
http.formLogin((formLogin) -> {
formLogin.successHandler(authenticationSuccessHandler);
formLogin.failureHandler(authenticationFailureHandler);
formLogin.loginPage("/login");
formLogin.loginProcessingUrl("/signin");
});
http.logout((logout) -> {
logout.logoutUrl("/signout");
logout.logoutSuccessHandler(logoutSuccessHandler);
});
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(); return http.build();
} }
......
package com.keymobile.login.exception; package com.keymobile.sso.exception;
import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
......
package com.keymobile.login.exception; package com.keymobile.sso.exception;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
......
package com.keymobile.login.logging; package com.keymobile.sso.logging;
public interface LogConstants { public interface LogConstants {
......
package com.keymobile.login.logging; package com.keymobile.sso.logging;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
......
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