Commit e4f80335 by chenzy

【修改】环境JDK21,language19,springboot版本升级

parent e36ae21d
...@@ -11,15 +11,15 @@ ...@@ -11,15 +11,15 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version> <version>3.0.13</version>
<relativePath/> <relativePath />
</parent> </parent>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!--<java.version>1.8</java.version>--> <!--<java.version>1.8</java.version>-->
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version> <spring-cloud.version>2022.0.3</spring-cloud.version>
</properties> </properties>
<!-- <repositories>--> <!-- <repositories>-->
<!-- <repository>--> <!-- <repository>-->
...@@ -32,6 +32,10 @@ ...@@ -32,6 +32,10 @@
<dependencies> <dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>
...@@ -52,10 +56,10 @@ ...@@ -52,10 +56,10 @@
<version>1.2</version> <version>1.2</version>
</dependency> </dependency>
<dependency> <!-- <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId> <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency> </dependency>-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
...@@ -67,22 +71,22 @@ ...@@ -67,22 +71,22 @@
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>3.7</version> <version>3.7</version>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>io.springfox</groupId>-->
<!-- <artifactId>springfox-swagger2</artifactId>-->
<!-- <version>2.5.0</version>-->
<!-- </dependency>-->
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>org.springdoc</groupId>
<artifactId>springfox-swagger2</artifactId> <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.5.0</version> <version>2.0.3</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.2.2</version>
</dependency> </dependency>
<!--引入oauth2--> <!--引入oauth2-->
<dependency> <!-- <dependency>-->
<groupId>com.fasterxml.jackson.core</groupId> <!-- <groupId>com.fasterxml.jackson.core</groupId>-->
<artifactId>jackson-core</artifactId> <!-- <artifactId>jackson-core</artifactId>-->
<version>2.10.2</version> <!-- <version>2.10.2</version>-->
</dependency> <!-- </dependency>-->
<dependency> <dependency>
<groupId>com.auth0</groupId> <groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId> <artifactId>java-jwt</artifactId>
...@@ -160,13 +164,13 @@ ...@@ -160,13 +164,13 @@
<dependency> <dependency>
<groupId>com.keymobile.auth</groupId> <groupId>com.keymobile.auth</groupId>
<artifactId>security</artifactId> <artifactId>security</artifactId>
<version>3.0.12-release</version> <version>mr-1.0.0-beta</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.keymobile</groupId> <groupId>com.keymobile</groupId>
<artifactId>config</artifactId> <artifactId>config</artifactId>
<version>1.1.2-release</version> <version>mr-1.0.9-beta</version>
</dependency> </dependency>
<dependency> <dependency>
......
...@@ -3,9 +3,13 @@ package com.keymobile.login.api; ...@@ -3,9 +3,13 @@ package com.keymobile.login.api;
import com.auth0.jwt.JWT; import com.auth0.jwt.JWT;
import com.auth0.jwt.interfaces.Claim; import com.auth0.jwt.interfaces.Claim;
import com.auth0.jwt.interfaces.DecodedJWT; import com.auth0.jwt.interfaces.DecodedJWT;
import com.keymobile.auth.common.security.CustomizedUserDetailService;
import com.keymobile.login.oauth2.Oauth2Properties; import com.keymobile.login.oauth2.Oauth2Properties;
import com.keymobile.login.service.AuthService; import com.keymobile.login.service.AuthService;
import com.keymobile.login.service.UserDetailsServiceImpl;
import jakarta.annotation.PostConstruct;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -17,14 +21,14 @@ import org.springframework.security.web.authentication.WebAuthenticationDetails; ...@@ -17,14 +21,14 @@ import org.springframework.security.web.authentication.WebAuthenticationDetails;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -41,8 +45,7 @@ public class LoginManagement { ...@@ -41,8 +45,7 @@ public class LoginManagement {
private Oauth2Properties oauth2Properties; private Oauth2Properties oauth2Properties;
@Autowired @Autowired
private CustomizedUserDetailService customizedUserDetailService; private UserDetailsServiceImpl userDetailsService;
@Autowired @Autowired
private AuthService authService; private AuthService authService;
...@@ -50,7 +53,7 @@ public class LoginManagement { ...@@ -50,7 +53,7 @@ public class LoginManagement {
@PostConstruct @PostConstruct
public void init() { public void init() {
restTemplate = new RestTemplateBuilder().basicAuthorization(oauth2Properties.getClientId(), oauth2Properties.getClientSecret()).build(); restTemplate = new RestTemplateBuilder().basicAuthentication(oauth2Properties.getClientId(), oauth2Properties.getClientSecret()).build();
} }
@RequestMapping(value = "sessionInfo", method = {RequestMethod.POST, RequestMethod.GET}) @RequestMapping(value = "sessionInfo", method = {RequestMethod.POST, RequestMethod.GET})
...@@ -138,7 +141,7 @@ public class LoginManagement { ...@@ -138,7 +141,7 @@ public class LoginManagement {
toAdd.put("password", "37fa265330ad83eaa879efb1e2db6380896cf639"); toAdd.put("password", "37fa265330ad83eaa879efb1e2db6380896cf639");
authService.addUser(toAdd); authService.addUser(toAdd);
} }
UserDetails userDetails = customizedUserDetailService.loadUserByUsername(userDetailByTokenInfo.get("unique_name")); UserDetails userDetails = userDetailsService.loadUserByUsername(userDetailByTokenInfo.get("unique_name"));
UsernamePasswordAuthenticationToken authentication = UsernamePasswordAuthenticationToken authentication =
new UsernamePasswordAuthenticationToken(userDetails, userDetails.getPassword(), userDetails.getAuthorities()); new UsernamePasswordAuthenticationToken(userDetails, userDetails.getPassword(), userDetails.getAuthorities());
authentication.setDetails(new WebAuthenticationDetails(request)); authentication.setDetails(new WebAuthenticationDetails(request));
......
...@@ -2,6 +2,10 @@ package com.keymobile.login.conf; ...@@ -2,6 +2,10 @@ package com.keymobile.login.conf;
import com.keymobile.login.api.Constants; import com.keymobile.login.api.Constants;
import com.keymobile.login.oauth2.Oauth2Properties; import com.keymobile.login.oauth2.Oauth2Properties;
import jakarta.annotation.PostConstruct;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -13,10 +17,6 @@ import org.springframework.security.web.authentication.logout.LogoutHandler; ...@@ -13,10 +17,6 @@ import org.springframework.security.web.authentication.logout.LogoutHandler;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -33,7 +33,7 @@ public class LogoutProcessHandler implements LogoutHandler { ...@@ -33,7 +33,7 @@ public class LogoutProcessHandler implements LogoutHandler {
@PostConstruct @PostConstruct
public void init() { public void init() {
restTemplate = new RestTemplateBuilder().basicAuthorization(oauth2Properties.getClientId(), oauth2Properties.getClientSecret()).build(); restTemplate = new RestTemplateBuilder().basicAuthentication(oauth2Properties.getClientId(), oauth2Properties.getClientSecret()).build();
MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter(); MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
mappingJackson2HttpMessageConverter.setSupportedMediaTypes(Arrays.asList( mappingJackson2HttpMessageConverter.setSupportedMediaTypes(Arrays.asList(
MediaType.TEXT_HTML, MediaType.TEXT_HTML,
......
package com.keymobile.login.conf; package com.keymobile.login.conf;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
@Component @Component
......
package com.keymobile.login.conf; package com.keymobile.login.conf;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler; import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
@Component @Component
......
package com.keymobile.login.conf; package com.keymobile.login.conf;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler; import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
......
package com.keymobile.login.conf; package com.keymobile.login.conf;
import com.keymobile.login.oauth2.Oauth2Properties; import com.keymobile.login.oauth2.Oauth2Properties;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
@Component @Component
......
package com.keymobile.login.conf; package com.keymobile.login.conf;
import com.keymobile.auth.common.security.CustomizedUserDetailService; import com.keymobile.login.service.UserDetailsServiceImpl;
import com.keymobile.login.api.Constants;
import com.keymobile.login.oauth2.Oauth2Properties;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 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.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.Authentication;
import org.springframework.security.crypto.password.NoOpPasswordEncoder; import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.web.authentication.logout.LogoutHandler; import org.springframework.security.web.SecurityFilterChain;
import org.springframework.web.client.RestTemplate;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
@Configuration @Configuration
@ComponentScan("com.keymobile.auth.common.security") @ComponentScan("com.keymobile.auth.common.security")
public class SecurityConfig extends WebSecurityConfigurerAdapter { public class SecurityConfig {
private static final Logger log = LoggerFactory.getLogger(SecurityConfig.class); private static final Logger log = LoggerFactory.getLogger(SecurityConfig.class);
@Autowired @Autowired
private CustomizedUserDetailService customUserDetailService; private UserDetailsServiceImpl userDetailsService;
@Autowired @Autowired
private RESTAuthenticationEntryPoint authenticationEntryPoint; private RESTAuthenticationEntryPoint authenticationEntryPoint;
@Autowired @Autowired
...@@ -45,15 +33,15 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -45,15 +33,15 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired @Autowired
public void configure(AuthenticationManagerBuilder auth) throws Exception { public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(customUserDetailService).passwordEncoder(NoOpPasswordEncoder.getInstance()); auth.userDetailsService(userDetailsService).passwordEncoder(NoOpPasswordEncoder.getInstance());
} }
@Override @Bean
protected void configure(HttpSecurity http) throws Exception { public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
// http.authorizeRequests().anyRequest().authenticated(); // http.authorizeRequests().anyRequest().authenticated();
http http
.authorizeRequests() .authorizeHttpRequests()
.antMatchers("/login", "/error", "/signin", "/signout", "/oauth/**").permitAll() .requestMatchers("/login", "/error", "/signin", "/signout", "/oauth/**").permitAll()
.anyRequest().authenticated(); .anyRequest().authenticated();
http.csrf().disable(); http.csrf().disable();
...@@ -64,6 +52,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -64,6 +52,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
http.formLogin().loginProcessingUrl("/signin"); http.formLogin().loginProcessingUrl("/signin");
http.logout().logoutUrl("/signout"); http.logout().logoutUrl("/signout");
http.logout().logoutSuccessHandler(logoutSuccessHandler); http.logout().logoutSuccessHandler(logoutSuccessHandler);
return http.build();
} }
......
package com.keymobile.login.service;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl;
import org.springframework.stereotype.Repository;
import javax.sql.DataSource;
@Repository
public class UserDetailsServiceImpl extends JdbcDaoImpl implements UserDetailsService {
@Autowired
private DataSource dataSource;
/**
* 初始化时,设置给父类
*/
@PostConstruct
private void initialize() {
setDataSource(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