diff --git a/devicehive-auth/pom.xml b/devicehive-auth/pom.xml index b00965f58..94b395c44 100644 --- a/devicehive-auth/pom.xml +++ b/devicehive-auth/pom.xml @@ -67,12 +67,16 @@ - org.springframework.boot - spring-boot-starter-security + org.springframework.security + spring-security-core - org.springframework.boot - spring-boot-starter-aop + org.springframework.security + spring-security-config + + + org.springframework.security + spring-security-web diff --git a/devicehive-auth/src/main/java/com/devicehive/application/AuthRpcClientConfig.java b/devicehive-auth/src/main/java/com/devicehive/application/AuthRpcClientConfig.java index fc20344fd..89a4e3d0d 100644 --- a/devicehive-auth/src/main/java/com/devicehive/application/AuthRpcClientConfig.java +++ b/devicehive-auth/src/main/java/com/devicehive/application/AuthRpcClientConfig.java @@ -30,6 +30,7 @@ import com.devicehive.shim.kafka.serializer.ResponseSerializer; import com.devicehive.shim.kafka.topic.KafkaTopicService; import com.google.gson.Gson; +import jakarta.annotation.PostConstruct; import org.apache.kafka.clients.producer.KafkaProducer; import org.apache.kafka.clients.producer.Producer; import org.apache.kafka.common.serialization.StringSerializer; @@ -38,7 +39,6 @@ import org.springframework.context.annotation.*; import org.springframework.core.env.Environment; -import javax.annotation.PostConstruct; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; diff --git a/devicehive-auth/src/main/java/com/devicehive/application/DeviceHiveAuthApplication.java b/devicehive-auth/src/main/java/com/devicehive/application/DeviceHiveAuthApplication.java index 497d38ad5..55a3a98b7 100644 --- a/devicehive-auth/src/main/java/com/devicehive/application/DeviceHiveAuthApplication.java +++ b/devicehive-auth/src/main/java/com/devicehive/application/DeviceHiveAuthApplication.java @@ -92,7 +92,7 @@ public Gson gson() { } @Bean - public Validator localValidator() { + public LocalValidatorFactoryBean localValidator() { return new LocalValidatorFactoryBean(); } } diff --git a/devicehive-auth/src/main/java/com/devicehive/application/filter/SwaggerFilter.java b/devicehive-auth/src/main/java/com/devicehive/application/filter/SwaggerFilter.java index bf0beae44..db9e35f49 100644 --- a/devicehive-auth/src/main/java/com/devicehive/application/filter/SwaggerFilter.java +++ b/devicehive-auth/src/main/java/com/devicehive/application/filter/SwaggerFilter.java @@ -20,16 +20,16 @@ * #L% */ +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebFilter; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.filter.OncePerRequestFilter; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebFilter; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.net.URL; diff --git a/devicehive-auth/src/main/java/com/devicehive/application/security/WebSecurityConfig.java b/devicehive-auth/src/main/java/com/devicehive/application/security/WebSecurityConfig.java index 059c1ba7c..31caea2b8 100644 --- a/devicehive-auth/src/main/java/com/devicehive/application/security/WebSecurityConfig.java +++ b/devicehive-auth/src/main/java/com/devicehive/application/security/WebSecurityConfig.java @@ -27,6 +27,7 @@ import com.devicehive.model.ErrorResponse; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; @@ -36,57 +37,57 @@ 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.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.web.AuthenticationEntryPoint; +import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; -import javax.servlet.http.HttpServletResponse; + @Configuration @EnableWebSecurity @Order(Ordered.HIGHEST_PRECEDENCE) -public class WebSecurityConfig extends WebSecurityConfigurerAdapter { +public class WebSecurityConfig { - private Gson gson = new GsonBuilder().create(); + private final Gson gson = new GsonBuilder().create(); + private final SimpleCORSFilter simpleCORSFilter; private final JwtTokenAuthenticationProvider jwtTokenAuthenticationProvider; - public WebSecurityConfig(final JwtTokenAuthenticationProvider jwtTokenAuthenticationProvider) { - super(); + public WebSecurityConfig(JwtTokenAuthenticationProvider jwtTokenAuthenticationProvider, + SimpleCORSFilter simpleCORSFilter) { + this.simpleCORSFilter = simpleCORSFilter; this.jwtTokenAuthenticationProvider = jwtTokenAuthenticationProvider; } - @Override - protected void configure(HttpSecurity http) throws Exception { + @Bean + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http - .csrf().disable() - .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) - .and() - .authorizeRequests() - .antMatchers("/css/**", "/server/**", "/scripts/**", "/webjars/**", "/templates/**").permitAll() - .antMatchers("/*/swagger.json", "/*/swagger.yaml").permitAll() - .and() - .anonymous().disable() - .exceptionHandling() - .authenticationEntryPoint(unauthorizedEntryPoint()); + .csrf(AbstractHttpConfigurer::disable) + .sessionManagement(sess -> sess.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) + .authorizeHttpRequests(auth -> auth + .requestMatchers("/css/**", "/server/**", "/scripts/**", + "/webjars/**", "/templates/**", "/*/swagger.json", "/*/swagger.yaml").permitAll() + .anyRequest().authenticated() + ) + .exceptionHandling(exception -> exception + .authenticationEntryPoint(unauthorizedEntryPoint()) + ); http - .addFilterBefore(new SimpleCORSFilter(), BasicAuthenticationFilter.class) - .addFilterAfter(new HttpAuthenticationFilter(authenticationManager()), SimpleCORSFilter.class); + .addFilterBefore(simpleCORSFilter, BasicAuthenticationFilter.class) + .addFilterAfter(new HttpAuthenticationFilter(http.getSharedObject(AuthenticationManager.class)), SimpleCORSFilter.class); + + return http.build(); } - @Override - protected void configure(AuthenticationManagerBuilder auth) { + @Bean + public AuthenticationManager authenticationManagerBuilder(AuthenticationManagerBuilder auth) throws Exception { auth .authenticationProvider(jwtTokenAuthenticationProvider) .authenticationProvider(anonymousAuthenticationProvider()); - } - - @Bean - @Override - public AuthenticationManager authenticationManagerBean() throws Exception { - return super.authenticationManagerBean(); + return auth.build(); } @Bean @@ -103,4 +104,4 @@ public AuthenticationEntryPoint unauthorizedEntryPoint() { gson.toJson(new ErrorResponse(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage()))); }; } -} +} \ No newline at end of file diff --git a/devicehive-backend/src/main/java/com/devicehive/application/DeviceHiveBackendApplication.java b/devicehive-backend/src/main/java/com/devicehive/application/DeviceHiveBackendApplication.java index fc8264bb0..8b7d402b7 100644 --- a/devicehive-backend/src/main/java/com/devicehive/application/DeviceHiveBackendApplication.java +++ b/devicehive-backend/src/main/java/com/devicehive/application/DeviceHiveBackendApplication.java @@ -21,6 +21,7 @@ */ import org.springframework.boot.WebApplicationType; +import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.ComponentScan; diff --git a/devicehive-backend/src/main/java/com/devicehive/application/RequestHandlersMapper.java b/devicehive-backend/src/main/java/com/devicehive/application/RequestHandlersMapper.java index 23042b299..95ddf1049 100644 --- a/devicehive-backend/src/main/java/com/devicehive/application/RequestHandlersMapper.java +++ b/devicehive-backend/src/main/java/com/devicehive/application/RequestHandlersMapper.java @@ -35,10 +35,10 @@ import com.devicehive.shim.api.Action; import com.devicehive.shim.api.server.RequestHandler; import com.google.common.collect.ImmutableMap; +import jakarta.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import javax.annotation.PostConstruct; import java.util.Map; @Component diff --git a/devicehive-common-service/pom.xml b/devicehive-common-service/pom.xml index 918448991..0f9eedf89 100644 --- a/devicehive-common-service/pom.xml +++ b/devicehive-common-service/pom.xml @@ -21,6 +21,11 @@ ${project.parent.version} provided + + com.fasterxml.jackson.core + jackson-databind + ${jackson-databind.version} + org.springframework.boot spring-boot-starter-jersey @@ -60,6 +65,12 @@ org.apache.httpcomponents httpclient + + javax.servlet + javax.servlet-api + 4.0.1 + compile + \ No newline at end of file diff --git a/devicehive-common-service/src/main/java/com/devicehive/auth/rest/HttpAuthenticationFilter.java b/devicehive-common-service/src/main/java/com/devicehive/auth/rest/HttpAuthenticationFilter.java index 0a4440c97..d5e020e52 100644 --- a/devicehive-common-service/src/main/java/com/devicehive/auth/rest/HttpAuthenticationFilter.java +++ b/devicehive-common-service/src/main/java/com/devicehive/auth/rest/HttpAuthenticationFilter.java @@ -21,6 +21,12 @@ */ import com.devicehive.auth.HiveAuthentication; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; @@ -37,12 +43,7 @@ import org.springframework.web.filter.GenericFilterBean; import org.springframework.web.util.UrlPathHelper; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; + import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; diff --git a/devicehive-common-service/src/main/java/com/devicehive/auth/rest/SimpleCORSFilter.java b/devicehive-common-service/src/main/java/com/devicehive/auth/rest/SimpleCORSFilter.java index 37457264f..ee8a40b09 100644 --- a/devicehive-common-service/src/main/java/com/devicehive/auth/rest/SimpleCORSFilter.java +++ b/devicehive-common-service/src/main/java/com/devicehive/auth/rest/SimpleCORSFilter.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -19,20 +19,19 @@ * limitations under the License. * #L% */ - import org.springframework.web.filter.GenericFilterBean; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletResponse; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; public class SimpleCORSFilter extends GenericFilterBean { @Override - public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException, ServletException { final HttpServletResponse resp = (HttpServletResponse) servletResponse; resp.setHeader("Access-Control-Allow-Credentials", "true"); resp.setHeader("Access-Control-Allow-Origin", "*"); diff --git a/devicehive-common-service/src/main/java/com/devicehive/resource/exceptions/AccessDeniedExceptionMapper.java b/devicehive-common-service/src/main/java/com/devicehive/resource/exceptions/AccessDeniedExceptionMapper.java index 4bbb205da..250a1a2d1 100644 --- a/devicehive-common-service/src/main/java/com/devicehive/resource/exceptions/AccessDeniedExceptionMapper.java +++ b/devicehive-common-service/src/main/java/com/devicehive/resource/exceptions/AccessDeniedExceptionMapper.java @@ -21,9 +21,9 @@ */ import com.devicehive.model.ErrorResponse; +import jakarta.servlet.http.HttpServletRequest; import org.springframework.security.access.AccessDeniedException; -import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; diff --git a/devicehive-common-service/src/main/java/com/devicehive/resource/exceptions/BadCredentialsExceptionMapper.java b/devicehive-common-service/src/main/java/com/devicehive/resource/exceptions/BadCredentialsExceptionMapper.java index 9e616b4e7..742bc77b2 100644 --- a/devicehive-common-service/src/main/java/com/devicehive/resource/exceptions/BadCredentialsExceptionMapper.java +++ b/devicehive-common-service/src/main/java/com/devicehive/resource/exceptions/BadCredentialsExceptionMapper.java @@ -21,9 +21,9 @@ */ import com.devicehive.model.ErrorResponse; +import jakarta.servlet.http.HttpServletRequest; import org.springframework.security.authentication.BadCredentialsException; -import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; diff --git a/devicehive-common-service/src/main/java/com/devicehive/resource/exceptions/InvalidPrincipalExceptionMapper.java b/devicehive-common-service/src/main/java/com/devicehive/resource/exceptions/InvalidPrincipalExceptionMapper.java index c07c38f6e..75c365d23 100644 --- a/devicehive-common-service/src/main/java/com/devicehive/resource/exceptions/InvalidPrincipalExceptionMapper.java +++ b/devicehive-common-service/src/main/java/com/devicehive/resource/exceptions/InvalidPrincipalExceptionMapper.java @@ -22,8 +22,8 @@ import com.devicehive.exceptions.InvalidPrincipalException; import com.devicehive.model.ErrorResponse; +import jakarta.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; diff --git a/devicehive-common-service/src/main/java/com/devicehive/security/util/JwtSecretService.java b/devicehive-common-service/src/main/java/com/devicehive/security/util/JwtSecretService.java index 263d9d3cb..4c9aaf9d5 100644 --- a/devicehive-common-service/src/main/java/com/devicehive/security/util/JwtSecretService.java +++ b/devicehive-common-service/src/main/java/com/devicehive/security/util/JwtSecretService.java @@ -22,11 +22,11 @@ import com.devicehive.configuration.Constants; import com.devicehive.service.configuration.ConfigurationService; +import jakarta.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; -import javax.annotation.PostConstruct; import java.math.BigInteger; import java.security.SecureRandom; diff --git a/devicehive-common-service/src/main/java/com/devicehive/service/BaseDeviceService.java b/devicehive-common-service/src/main/java/com/devicehive/service/BaseDeviceService.java index e20a6bdfb..ae5cc4028 100644 --- a/devicehive-common-service/src/main/java/com/devicehive/service/BaseDeviceService.java +++ b/devicehive-common-service/src/main/java/com/devicehive/service/BaseDeviceService.java @@ -46,7 +46,7 @@ import java.util.concurrent.CompletableFuture; import static com.devicehive.configuration.Messages.ACCESS_DENIED; -import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN; +import static jakarta.servlet.http.HttpServletResponse.SC_FORBIDDEN; import static javax.ws.rs.core.Response.Status.BAD_REQUEST; import static javax.ws.rs.core.Response.Status.NOT_FOUND; diff --git a/devicehive-common-service/src/main/java/com/devicehive/service/BaseFilterService.java b/devicehive-common-service/src/main/java/com/devicehive/service/BaseFilterService.java index f7aeabcd5..fa74cfae3 100644 --- a/devicehive-common-service/src/main/java/com/devicehive/service/BaseFilterService.java +++ b/devicehive-common-service/src/main/java/com/devicehive/service/BaseFilterService.java @@ -46,8 +46,8 @@ import static com.devicehive.configuration.Messages.ACCESS_DENIED; import static com.devicehive.configuration.Messages.DEVICE_TYPES_NOT_FOUND; import static com.devicehive.configuration.Messages.NETWORKS_NOT_FOUND; -import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN; -import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND; +import static jakarta.servlet.http.HttpServletResponse.SC_FORBIDDEN; +import static jakarta.servlet.http.HttpServletResponse.SC_NOT_FOUND; @Component public class BaseFilterService { diff --git a/devicehive-common-service/src/main/java/com/devicehive/service/BaseNetworkService.java b/devicehive-common-service/src/main/java/com/devicehive/service/BaseNetworkService.java index b6508baab..e9d7d3720 100644 --- a/devicehive-common-service/src/main/java/com/devicehive/service/BaseNetworkService.java +++ b/devicehive-common-service/src/main/java/com/devicehive/service/BaseNetworkService.java @@ -57,11 +57,11 @@ import java.util.stream.Collectors; import static com.devicehive.configuration.Messages.NETWORKS_NOT_FOUND; +import static jakarta.servlet.http.HttpServletResponse.SC_BAD_REQUEST; +import static jakarta.servlet.http.HttpServletResponse.SC_FORBIDDEN; import static java.util.Optional.empty; import static java.util.Optional.of; import static java.util.Optional.ofNullable; -import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST; -import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN; import static org.springframework.util.CollectionUtils.isEmpty; @Component diff --git a/devicehive-common-service/src/main/java/com/devicehive/service/configuration/ConfigurationService.java b/devicehive-common-service/src/main/java/com/devicehive/service/configuration/ConfigurationService.java index d07c2073f..fd49f1050 100644 --- a/devicehive-common-service/src/main/java/com/devicehive/service/configuration/ConfigurationService.java +++ b/devicehive-common-service/src/main/java/com/devicehive/service/configuration/ConfigurationService.java @@ -29,8 +29,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + -import javax.transaction.Transactional; import javax.validation.constraints.NotNull; import java.util.Optional; diff --git a/devicehive-common-service/src/main/java/com/devicehive/service/helpers/HttpRestHelper.java b/devicehive-common-service/src/main/java/com/devicehive/service/helpers/HttpRestHelper.java index b4e06d7e3..702a25741 100644 --- a/devicehive-common-service/src/main/java/com/devicehive/service/helpers/HttpRestHelper.java +++ b/devicehive-common-service/src/main/java/com/devicehive/service/helpers/HttpRestHelper.java @@ -25,6 +25,7 @@ import com.devicehive.model.ErrorResponse; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; +import jakarta.annotation.PostConstruct; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; @@ -39,7 +40,6 @@ import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; -import javax.annotation.PostConstruct; import javax.ws.rs.ServiceUnavailableException; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; diff --git a/devicehive-common/dependency-reduced-pom.xml b/devicehive-common/dependency-reduced-pom.xml new file mode 100644 index 000000000..d9b9aa0b4 --- /dev/null +++ b/devicehive-common/dependency-reduced-pom.xml @@ -0,0 +1,166 @@ + + + + devicehive-server + com.devicehive + 4.1.0 + + 4.0.0 + devicehive-common + DeviceHive Common Module + + + + maven-shade-plugin + ${maven-shade-plugin.version} + + + package + + shade + + + + + org.apache.commons:commons-lang3 + com.google.code.gson:gson + + + true + shade + + + + + + + + + com.devicehive + devicehive-shim-api + 4.1.0 + compile + + + commons-lang3 + org.apache.commons + + + + + com.devicehive + devicehive-proxy-api + 4.1.0 + compile + + + io.swagger + swagger-annotations + 1.6.6 + compile + + + io.swagger + swagger-jersey2-jaxrs + 1.6.6 + compile + + + joda-time + joda-time + 2.5 + compile + + + javax.enterprise + cdi-api + 1.2 + compile + + + org.hibernate.javax.persistence + hibernate-jpa-2.1-api + 1.0.0.Final + compile + + + javax.servlet + javax.servlet-api + 4.0.1 + provided + + + javax.validation + validation-api + 1.1.0.Final + compile + + + javax.ws.rs + javax.ws.rs-api + 2.1.1 + compile + + + org.springframework.boot + spring-boot-starter-web + 3.1.5 + compile + + + spring-boot-starter-tomcat + org.springframework.boot + + + spring-boot-starter-json + org.springframework.boot + + + + + com.google.guava + guava + 32.1.1-jre + compile + + + org.slf4j + slf4j-api + 1.7.5 + compile + + + ch.qos.logback + logback-classic + 1.2.9 + compile + + + ch.qos.logback + logback-core + 1.2.9 + compile + + + org.slf4j + jul-to-slf4j + 1.7.5 + compile + + + org.slf4j + jcl-over-slf4j + 1.7.5 + compile + + + org.slf4j + log4j-over-slf4j + 1.7.5 + compile + + + + ${project.parent.basedir} + + diff --git a/devicehive-common/pom.xml b/devicehive-common/pom.xml index 522a5acc0..553313805 100644 --- a/devicehive-common/pom.xml +++ b/devicehive-common/pom.xml @@ -58,17 +58,17 @@ hibernate-jpa-2.1-api 1.0.0.Final - javax.servlet javax.servlet-api + 4.0.1 + provided - javax.validation validation-api + 1.1.0.Final - javax.ws.rs javax.ws.rs-api diff --git a/devicehive-frontend/pom.xml b/devicehive-frontend/pom.xml index bf7b1d5f7..b6e7e3ac7 100644 --- a/devicehive-frontend/pom.xml +++ b/devicehive-frontend/pom.xml @@ -52,10 +52,6 @@ - - org.springframework.boot - spring-boot-starter-security - org.springframework.boot @@ -74,10 +70,12 @@ org.hibernate hibernate-entitymanager + 5.6.14.Final org.springframework.boot - spring-boot-starter-aop + spring-boot-starter-security + 3.1.1 diff --git a/devicehive-frontend/src/main/java/com/devicehive/application/DeviceHiveFrontendApplication.java b/devicehive-frontend/src/main/java/com/devicehive/application/DeviceHiveFrontendApplication.java index fb0ead48a..0e55dcfc6 100644 --- a/devicehive-frontend/src/main/java/com/devicehive/application/DeviceHiveFrontendApplication.java +++ b/devicehive-frontend/src/main/java/com/devicehive/application/DeviceHiveFrontendApplication.java @@ -91,7 +91,8 @@ public Gson gson() { } @Bean - public Validator localValidator() { + public LocalValidatorFactoryBean validator() { return new LocalValidatorFactoryBean(); } + } diff --git a/devicehive-frontend/src/main/java/com/devicehive/application/filter/SwaggerFilter.java b/devicehive-frontend/src/main/java/com/devicehive/application/filter/SwaggerFilter.java index bf0beae44..db9e35f49 100644 --- a/devicehive-frontend/src/main/java/com/devicehive/application/filter/SwaggerFilter.java +++ b/devicehive-frontend/src/main/java/com/devicehive/application/filter/SwaggerFilter.java @@ -20,16 +20,16 @@ * #L% */ +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebFilter; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.filter.OncePerRequestFilter; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebFilter; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.net.URL; diff --git a/devicehive-frontend/src/main/java/com/devicehive/application/security/WebSecurityConfig.java b/devicehive-frontend/src/main/java/com/devicehive/application/security/WebSecurityConfig.java index f70662063..b33bd1624 100644 --- a/devicehive-frontend/src/main/java/com/devicehive/application/security/WebSecurityConfig.java +++ b/devicehive-frontend/src/main/java/com/devicehive/application/security/WebSecurityConfig.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -27,6 +27,7 @@ import com.devicehive.model.ErrorResponse; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; @@ -36,57 +37,57 @@ 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.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.web.AuthenticationEntryPoint; +import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; -import javax.servlet.http.HttpServletResponse; + @Configuration @EnableWebSecurity @Order(Ordered.HIGHEST_PRECEDENCE) -public class WebSecurityConfig extends WebSecurityConfigurerAdapter { +public class WebSecurityConfig { - private Gson gson = new GsonBuilder().create(); + private final Gson gson = new GsonBuilder().create(); + private final SimpleCORSFilter simpleCORSFilter; private final JwtTokenAuthenticationProvider jwtTokenAuthenticationProvider; - public WebSecurityConfig(JwtTokenAuthenticationProvider jwtTokenAuthenticationProvider) { - super(); + public WebSecurityConfig(JwtTokenAuthenticationProvider jwtTokenAuthenticationProvider, + SimpleCORSFilter simpleCORSFilter) { + this.simpleCORSFilter = simpleCORSFilter; this.jwtTokenAuthenticationProvider = jwtTokenAuthenticationProvider; } - @Override - protected void configure(HttpSecurity http) throws Exception { + @Bean + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http - .csrf().disable() - .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) - .and() - .authorizeRequests() - .antMatchers("/css/**", "/server/**", "/scripts/**", "/webjars/**", "/templates/**").permitAll() - .antMatchers("/*/swagger.json", "/*/swagger.yaml").permitAll() - .and() - .anonymous().disable() - .exceptionHandling() - .authenticationEntryPoint(unauthorizedEntryPoint()); + .csrf(AbstractHttpConfigurer::disable) + .sessionManagement(sess -> sess.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) + .authorizeHttpRequests(auth -> auth + .requestMatchers("/css/**", "/server/**", "/scripts/**", + "/webjars/**", "/templates/**", "/*/swagger.json", "/*/swagger.yaml").permitAll() + .anyRequest().authenticated() + ) + .exceptionHandling(exception -> exception + .authenticationEntryPoint(unauthorizedEntryPoint()) + ); http - .addFilterBefore(new SimpleCORSFilter(), BasicAuthenticationFilter.class) - .addFilterAfter(new HttpAuthenticationFilter(authenticationManager()), SimpleCORSFilter.class); + .addFilterBefore(simpleCORSFilter, BasicAuthenticationFilter.class) + .addFilterAfter(new HttpAuthenticationFilter(http.getSharedObject(AuthenticationManager.class)), SimpleCORSFilter.class); + + return http.build(); } - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { + @Bean + public AuthenticationManager authenticationManagerBuilder(AuthenticationManagerBuilder auth) throws Exception { auth .authenticationProvider(jwtTokenAuthenticationProvider) .authenticationProvider(anonymousAuthenticationProvider()); - } - - @Bean - @Override - public AuthenticationManager authenticationManagerBean() throws Exception { - return super.authenticationManagerBean(); + return auth.build(); } @Bean diff --git a/devicehive-frontend/src/main/java/com/devicehive/service/DeviceService.java b/devicehive-frontend/src/main/java/com/devicehive/service/DeviceService.java index 52d39fa63..b666ff2c9 100644 --- a/devicehive-frontend/src/main/java/com/devicehive/service/DeviceService.java +++ b/devicehive-frontend/src/main/java/com/devicehive/service/DeviceService.java @@ -55,8 +55,8 @@ import java.util.function.Consumer; import java.util.stream.Collectors; -import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN; -import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND; +import static jakarta.servlet.http.HttpServletResponse.SC_FORBIDDEN; +import static jakarta.servlet.http.HttpServletResponse.SC_NOT_FOUND; import static javax.ws.rs.core.Response.Status.*; @Component diff --git a/devicehive-frontend/src/main/java/com/devicehive/service/DeviceTypeService.java b/devicehive-frontend/src/main/java/com/devicehive/service/DeviceTypeService.java index 067c82e32..29d9bd7af 100644 --- a/devicehive-frontend/src/main/java/com/devicehive/service/DeviceTypeService.java +++ b/devicehive-frontend/src/main/java/com/devicehive/service/DeviceTypeService.java @@ -54,8 +54,8 @@ import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; +import static jakarta.servlet.http.HttpServletResponse.SC_BAD_REQUEST; import static java.util.Optional.ofNullable; -import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST; @Component public class DeviceTypeService extends BaseDeviceTypeService { diff --git a/devicehive-frontend/src/main/java/com/devicehive/service/NetworkService.java b/devicehive-frontend/src/main/java/com/devicehive/service/NetworkService.java index 9d728a096..6136fdfae 100644 --- a/devicehive-frontend/src/main/java/com/devicehive/service/NetworkService.java +++ b/devicehive-frontend/src/main/java/com/devicehive/service/NetworkService.java @@ -19,42 +19,35 @@ * limitations under the License. * #L% */ + import com.devicehive.auth.HivePrincipal; import com.devicehive.configuration.Messages; import com.devicehive.dao.NetworkDao; import com.devicehive.exceptions.ActionNotAllowedException; -import com.devicehive.exceptions.HiveException; import com.devicehive.exceptions.IllegalParametersException; import com.devicehive.model.response.EntityCountResponse; -import com.devicehive.model.rpc.*; +import com.devicehive.model.rpc.CountNetworkRequest; +import com.devicehive.model.rpc.CountResponse; import com.devicehive.model.updates.NetworkUpdate; import com.devicehive.service.helpers.ResponseConsumer; import com.devicehive.shim.api.Request; import com.devicehive.shim.api.Response; import com.devicehive.shim.api.client.RpcClient; import com.devicehive.util.HiveValidator; -import com.devicehive.vo.DeviceVO; import com.devicehive.vo.NetworkVO; -import com.devicehive.vo.NetworkWithUsersAndDevicesVO; -import com.devicehive.vo.UserVO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.validation.constraints.NotNull; -import java.util.*; +import java.util.List; +import java.util.NoSuchElementException; import java.util.Optional; import java.util.concurrent.CompletableFuture; -import java.util.stream.Collectors; -import static com.devicehive.configuration.Messages.NETWORKS_NOT_FOUND; -import static java.util.Optional.*; -import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN; -import static org.springframework.util.CollectionUtils.isEmpty; +import static java.util.Optional.ofNullable; @Component public class NetworkService extends BaseNetworkService { diff --git a/devicehive-frontend/src/main/java/com/devicehive/websockets/DeviceHiveWebSocketHandler.java b/devicehive-frontend/src/main/java/com/devicehive/websockets/DeviceHiveWebSocketHandler.java index 19bae9c80..d47edded3 100644 --- a/devicehive-frontend/src/main/java/com/devicehive/websockets/DeviceHiveWebSocketHandler.java +++ b/devicehive-frontend/src/main/java/com/devicehive/websockets/DeviceHiveWebSocketHandler.java @@ -39,6 +39,7 @@ import com.google.gson.JsonParseException; import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; +import jakarta.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -54,7 +55,6 @@ import javax.persistence.OptimisticLockException; import javax.persistence.PersistenceException; -import javax.servlet.http.HttpServletResponse; import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolationException; import java.io.IOException; @@ -184,7 +184,7 @@ public void afterConnectionClosed(WebSocketSession session, CloseStatus status) sessionMonitor.removeSession(session.getId()); - if(session.isOpen()) { + if (session.isOpen()) { session.close(); } logger.info("Websocket Connection Closed: session id {}, close status is {} ", session.getId(), status); diff --git a/devicehive-frontend/src/main/java/com/devicehive/websockets/WebSocketRequestProcessor.java b/devicehive-frontend/src/main/java/com/devicehive/websockets/WebSocketRequestProcessor.java index 2c1c4df42..e596555bb 100644 --- a/devicehive-frontend/src/main/java/com/devicehive/websockets/WebSocketRequestProcessor.java +++ b/devicehive-frontend/src/main/java/com/devicehive/websockets/WebSocketRequestProcessor.java @@ -27,11 +27,11 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.socket.WebSocketSession; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; import static com.devicehive.configuration.Constants.DEVICE_ID; diff --git a/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/CommandHandlers.java b/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/CommandHandlers.java index 289eaa58d..1113b3794 100644 --- a/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/CommandHandlers.java +++ b/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/CommandHandlers.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -36,7 +36,8 @@ import com.devicehive.service.BaseFilterService; import com.devicehive.service.DeviceCommandService; import com.devicehive.service.DeviceService; -import com.devicehive.vo.*; +import com.devicehive.vo.DeviceVO; +import com.devicehive.vo.UserVO; import com.devicehive.websockets.converters.WebSocketResponse; import com.google.gson.Gson; import com.google.gson.JsonObject; @@ -61,10 +62,7 @@ import static com.devicehive.model.rpc.CommandSearchRequest.createCommandSearchRequest; import static com.devicehive.shim.api.Action.COMMAND_EVENT; import static com.devicehive.util.ServerResponsesFactory.createCommandMessage; -import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST; -import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN; -import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR; -import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND; +import static jakarta.servlet.http.HttpServletResponse.*; @Component public class CommandHandlers { @@ -154,7 +152,7 @@ public void processCommandUnsubscribe(JsonObject request, WebSocketSession sessi if (subscriptionId != null && !sessionSubIds.contains(subscriptionId)) { throw new HiveException(String.format(Messages.SUBSCRIPTION_NOT_FOUND, subscriptionId), SC_NOT_FOUND); } - + CompletableFuture> future; if (subscriptionId == null) { future = commandService.sendUnsubscribeRequest(sessionSubIds); @@ -163,10 +161,10 @@ public void processCommandUnsubscribe(JsonObject request, WebSocketSession sessi future = commandService.sendUnsubscribeRequest(Collections.singleton(subscriptionId)); sessionSubscriptions.remove(new SubscriptionInfo(subscriptionId)); } - + future.thenAccept(collection -> { logger.debug("command/unsubscribe completed for session {}", session.getId()); - clientHandler.sendMessage(request, new WebSocketResponse(), session); + clientHandler.sendMessage(request, new WebSocketResponse(), session); }); } @@ -174,7 +172,7 @@ public void processCommandUnsubscribe(JsonObject request, WebSocketSession sessi @PreAuthorize("isAuthenticated() and hasPermission(#deviceId, 'CREATE_DEVICE_COMMAND')") public void processCommandInsert(String deviceId, JsonObject request, WebSocketSession session) { HivePrincipal principal = (HivePrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); - + final DeviceCommandWrapper deviceCommand = gson .fromJson(request.getAsJsonObject(COMMAND), DeviceCommandWrapper.class); @@ -188,7 +186,7 @@ public void processCommandInsert(String deviceId, JsonObject request, WebSocketS if (deviceVO == null) { throw new HiveException(String.format(DEVICE_NOT_FOUND, deviceId), SC_NOT_FOUND); } - + if (deviceCommand == null) { throw new HiveException(Messages.EMPTY_COMMAND, SC_BAD_REQUEST); } @@ -242,12 +240,12 @@ public void processCommandUpdate(String deviceId, JsonObject request, WebSocketS @HiveWebsocketAuth @PreAuthorize("isAuthenticated() and hasPermission(#deviceId, 'GET_DEVICE_COMMAND')") - public void processCommandGet(String deviceId, JsonObject request, WebSocketSession session) { + public void processCommandGet(String deviceId, JsonObject request, WebSocketSession session) { if (deviceId == null) { logger.error("command/get proceed with error. Device ID should be provided."); throw new HiveException(DEVICE_ID_REQUIRED, SC_BAD_REQUEST); } - + Long commandId = gson.fromJson(request.get(COMMAND_ID), Long.class); if (commandId == null) { logger.error("command/get proceed with error. Command ID should be provided."); @@ -260,7 +258,7 @@ public void processCommandGet(String deviceId, JsonObject request, WebSocketSess logger.error("command/get proceed with error. No Device with Device ID = {} found.", deviceId); throw new HiveException(String.format(DEVICE_NOT_FOUND, deviceId), SC_NOT_FOUND); } - + WebSocketResponse webSocketResponse = commandService.findOne(commandId, deviceId) .thenApply(command -> command .map(c -> { @@ -273,7 +271,7 @@ public void processCommandGet(String deviceId, JsonObject request, WebSocketSess logger.error("Unable to get command.", ex); throw new HiveException(Messages.INTERNAL_SERVER_ERROR, SC_INTERNAL_SERVER_ERROR); }).join(); - + if (webSocketResponse == null) { logger.error(String.format(COMMAND_NOT_FOUND, commandId)); throw new HiveException(String.format(COMMAND_NOT_FOUND, commandId), SC_NOT_FOUND); @@ -286,12 +284,12 @@ public void processCommandGet(String deviceId, JsonObject request, WebSocketSess @PreAuthorize("isAuthenticated() and hasPermission(#deviceId, 'GET_DEVICE_COMMAND')") public void processCommandList(String deviceId, JsonObject request, WebSocketSession session) { CommandSearchRequest commandSearchRequest = createCommandSearchRequest(request); - + if (deviceId == null) { logger.error("command/list proceed with error. Device ID should be provided."); throw new HiveException(DEVICE_ID_REQUIRED, SC_BAD_REQUEST); } - + logger.debug("Device command query requested for device {}", deviceId); DeviceVO device = deviceService.findById(deviceId); @@ -299,9 +297,9 @@ public void processCommandList(String deviceId, JsonObject request, WebSocketSes logger.error("command/list proceed with error. No Device with Device ID = {} found.", deviceId); throw new HiveException(String.format(DEVICE_NOT_FOUND, deviceId), SC_NOT_FOUND); } - + WebSocketResponse response = new WebSocketResponse(); - + commandService.find(commandSearchRequest) .thenAccept(sortedDeviceCommands -> { response.addValue(COMMANDS, sortedDeviceCommands, COMMAND_LISTED); diff --git a/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/CommonHandlers.java b/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/CommonHandlers.java index 7b1bb0f3c..6a5555898 100644 --- a/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/CommonHandlers.java +++ b/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/CommonHandlers.java @@ -53,9 +53,7 @@ import javax.ws.rs.ServiceUnavailableException; import java.io.IOException; -import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST; -import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE; -import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED; +import static jakarta.servlet.http.HttpServletResponse.*; @Component public class CommonHandlers { diff --git a/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/ConfigurationHandlers.java b/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/ConfigurationHandlers.java index aaafd50e1..ecd0164a4 100644 --- a/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/ConfigurationHandlers.java +++ b/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/ConfigurationHandlers.java @@ -43,8 +43,8 @@ import static com.devicehive.configuration.Constants.NAME; import static com.devicehive.configuration.Constants.VALUE; import static com.devicehive.configuration.Messages.CONFIG_NOT_FOUND; -import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST; -import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND; +import static jakarta.servlet.http.HttpServletResponse.SC_BAD_REQUEST; +import static jakarta.servlet.http.HttpServletResponse.SC_NOT_FOUND; @Component public class ConfigurationHandlers { diff --git a/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/DeviceHandlers.java b/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/DeviceHandlers.java index 8d897f262..4fa40558b 100644 --- a/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/DeviceHandlers.java +++ b/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/DeviceHandlers.java @@ -48,8 +48,8 @@ import static com.devicehive.configuration.Constants.*; import static com.devicehive.json.strategies.JsonPolicyDef.Policy.DEVICES_LISTED; import static com.devicehive.json.strategies.JsonPolicyDef.Policy.DEVICE_PUBLISHED; -import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST; -import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND; +import static jakarta.servlet.http.HttpServletResponse.SC_BAD_REQUEST; +import static jakarta.servlet.http.HttpServletResponse.SC_NOT_FOUND; import static javax.ws.rs.core.Response.Status.BAD_REQUEST; @Component diff --git a/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/NotificationHandlers.java b/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/NotificationHandlers.java index a03e2916b..4a33cb2ff 100644 --- a/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/NotificationHandlers.java +++ b/devicehive-frontend/src/main/java/com/devicehive/websockets/handlers/NotificationHandlers.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -39,7 +39,7 @@ import com.devicehive.service.DeviceNotificationService; import com.devicehive.service.DeviceService; import com.devicehive.util.ServerResponsesFactory; -import com.devicehive.vo.*; +import com.devicehive.vo.DeviceVO; import com.devicehive.websockets.converters.WebSocketResponse; import com.google.gson.Gson; import com.google.gson.JsonObject; @@ -66,7 +66,7 @@ import static com.devicehive.json.strategies.JsonPolicyDef.Policy.NOTIFICATION_TO_DEVICE; import static com.devicehive.model.rpc.NotificationSearchRequest.createNotificationSearchRequest; import static com.devicehive.shim.api.Action.NOTIFICATION_EVENT; -import static javax.servlet.http.HttpServletResponse.*; +import static jakarta.servlet.http.HttpServletResponse.*; @Component public class NotificationHandlers { @@ -97,7 +97,7 @@ public NotificationHandlers(Gson gson, @PreAuthorize("isAuthenticated() and hasPermission(#deviceId, 'GET_DEVICE_NOTIFICATION')") @SuppressWarnings("unchecked") public void processNotificationSubscribe(String deviceId, JsonObject request, - WebSocketSession session) throws InterruptedException, IOException { + WebSocketSession session) throws InterruptedException, IOException { final HiveAuthentication authentication = (HiveAuthentication) SecurityContextHolder.getContext().getAuthentication(); final Date timestamp = gson.fromJson(request.get(Constants.TIMESTAMP), Date.class); Set networks = gson.fromJson(request.getAsJsonArray(NETWORK_IDS), JsonTypes.LONG_SET_TYPE); @@ -170,7 +170,7 @@ public void processNotificationUnsubscribe(JsonObject request, WebSocketSession future = notificationService.unsubscribe(Collections.singleton(subscriptionId)); sessionSubscriptions.remove(new SubscriptionInfo(subscriptionId)); } - + future.thenAccept(collection -> { logger.debug("notification/unsubscribe completed for session {}", session.getId()); clientHandler.sendMessage(request, new WebSocketResponse(), session); @@ -180,7 +180,7 @@ public void processNotificationUnsubscribe(JsonObject request, WebSocketSession @HiveWebsocketAuth @PreAuthorize("isAuthenticated() and hasPermission(#deviceId, 'CREATE_DEVICE_NOTIFICATION')") public void processNotificationInsert(String deviceId, JsonObject request, - WebSocketSession session) { + WebSocketSession session) { HivePrincipal principal = (HivePrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); DeviceNotificationWrapper notificationSubmit = gson.fromJson(request.get(Constants.NOTIFICATION), DeviceNotificationWrapper.class); @@ -272,7 +272,7 @@ public void processNotificationList(JsonObject request, WebSocketSession session logger.error("notification/list proceed with error. Device ID should be provided."); throw new HiveException(Messages.DEVICE_ID_REQUIRED, SC_BAD_REQUEST); } - + logger.debug("Device notification query requested for device {}", deviceId); DeviceVO byIdWithPermissionsCheck = deviceService.findById(deviceId); @@ -280,9 +280,9 @@ public void processNotificationList(JsonObject request, WebSocketSession session logger.error("notification/get proceed with error. No Device with Device ID = {} found.", deviceId); throw new HiveException(String.format(Messages.DEVICE_NOT_FOUND, deviceId), SC_NOT_FOUND); } - + WebSocketResponse response = new WebSocketResponse(); - + notificationService.find(notificationSearchRequest) .thenAccept(sortedDeviceNotifications -> { response.addValue(NOTIFICATIONS, sortedDeviceNotifications, NOTIFICATION_TO_CLIENT); diff --git a/devicehive-frontend/src/main/java/com/devicehive/websockets/util/SessionMonitor.java b/devicehive-frontend/src/main/java/com/devicehive/websockets/util/SessionMonitor.java index a87fcc017..f4f758bb8 100644 --- a/devicehive-frontend/src/main/java/com/devicehive/websockets/util/SessionMonitor.java +++ b/devicehive-frontend/src/main/java/com/devicehive/websockets/util/SessionMonitor.java @@ -20,6 +20,7 @@ * #L% */ +import jakarta.annotation.PreDestroy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.scheduling.annotation.Scheduled; @@ -28,7 +29,6 @@ import org.springframework.web.socket.PingMessage; import org.springframework.web.socket.WebSocketSession; -import javax.annotation.PreDestroy; import java.io.IOException; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; diff --git a/devicehive-plugin/pom.xml b/devicehive-plugin/pom.xml index 55456232d..5de2d75e6 100644 --- a/devicehive-plugin/pom.xml +++ b/devicehive-plugin/pom.xml @@ -52,10 +52,6 @@ - - org.springframework.boot - spring-boot-starter-security - org.springframework.boot spring-boot-starter-websocket @@ -70,10 +66,13 @@ + org.hibernate hibernate-entitymanager + 5.6.14.Final + org.springframework.boot spring-boot-starter-aop @@ -84,6 +83,14 @@ ${mockito-core.version} test + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.security + spring-security-config + diff --git a/devicehive-plugin/src/main/java/com/devicehive/application/DeviceHivePluginApplication.java b/devicehive-plugin/src/main/java/com/devicehive/application/DeviceHivePluginApplication.java index 8a5b69900..fb3250157 100644 --- a/devicehive-plugin/src/main/java/com/devicehive/application/DeviceHivePluginApplication.java +++ b/devicehive-plugin/src/main/java/com/devicehive/application/DeviceHivePluginApplication.java @@ -91,7 +91,7 @@ public Gson gson() { } @Bean - public Validator localValidator() { + public LocalValidatorFactoryBean localValidator() { return new LocalValidatorFactoryBean(); } } diff --git a/devicehive-plugin/src/main/java/com/devicehive/application/PluginProxyClientConfig.java b/devicehive-plugin/src/main/java/com/devicehive/application/PluginProxyClientConfig.java index a6583e6cf..7a7187167 100644 --- a/devicehive-plugin/src/main/java/com/devicehive/application/PluginProxyClientConfig.java +++ b/devicehive-plugin/src/main/java/com/devicehive/application/PluginProxyClientConfig.java @@ -27,13 +27,13 @@ import com.devicehive.proxy.client.WebSocketKafkaProxyClient; import com.devicehive.proxy.config.WebSocketKafkaProxyConfig; import com.google.gson.Gson; +import jakarta.annotation.PostConstruct; 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.context.annotation.Profile; -import javax.annotation.PostConstruct; import java.util.UUID; import static com.devicehive.configuration.Constants.REQUEST_TOPIC; diff --git a/devicehive-plugin/src/main/java/com/devicehive/application/PluginRpcClientConfig.java b/devicehive-plugin/src/main/java/com/devicehive/application/PluginRpcClientConfig.java index 6245bc467..fb6c9a0f8 100644 --- a/devicehive-plugin/src/main/java/com/devicehive/application/PluginRpcClientConfig.java +++ b/devicehive-plugin/src/main/java/com/devicehive/application/PluginRpcClientConfig.java @@ -30,6 +30,7 @@ import com.devicehive.shim.kafka.serializer.ResponseSerializer; import com.devicehive.shim.kafka.topic.KafkaTopicService; import com.google.gson.Gson; +import jakarta.annotation.PostConstruct; import org.apache.kafka.clients.producer.KafkaProducer; import org.apache.kafka.clients.producer.Producer; import org.apache.kafka.common.serialization.StringSerializer; @@ -38,7 +39,6 @@ import org.springframework.context.annotation.*; import org.springframework.core.env.Environment; -import javax.annotation.PostConstruct; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; diff --git a/devicehive-plugin/src/main/java/com/devicehive/application/filter/SwaggerFilter.java b/devicehive-plugin/src/main/java/com/devicehive/application/filter/SwaggerFilter.java index bf0beae44..db9e35f49 100644 --- a/devicehive-plugin/src/main/java/com/devicehive/application/filter/SwaggerFilter.java +++ b/devicehive-plugin/src/main/java/com/devicehive/application/filter/SwaggerFilter.java @@ -20,16 +20,16 @@ * #L% */ +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebFilter; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.filter.OncePerRequestFilter; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebFilter; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.net.URL; diff --git a/devicehive-plugin/src/main/java/com/devicehive/application/security/WebSecurityConfig.java b/devicehive-plugin/src/main/java/com/devicehive/application/security/WebSecurityConfig.java index d694e1b81..60d51d023 100644 --- a/devicehive-plugin/src/main/java/com/devicehive/application/security/WebSecurityConfig.java +++ b/devicehive-plugin/src/main/java/com/devicehive/application/security/WebSecurityConfig.java @@ -27,6 +27,7 @@ import com.devicehive.model.ErrorResponse; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; @@ -36,64 +37,59 @@ 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.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.web.AuthenticationEntryPoint; +import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; -import javax.servlet.http.HttpServletResponse; + @Configuration @EnableWebSecurity @Order(Ordered.HIGHEST_PRECEDENCE) -public class WebSecurityConfig extends WebSecurityConfigurerAdapter { +public class WebSecurityConfig { - private Gson gson = new GsonBuilder().create(); + private final Gson gson = new GsonBuilder().create(); + private final SimpleCORSFilter simpleCORSFilter; private final JwtTokenAuthenticationProvider jwtTokenAuthenticationProvider; - public WebSecurityConfig(JwtTokenAuthenticationProvider jwtTokenAuthenticationProvider) { - super(); + public WebSecurityConfig(JwtTokenAuthenticationProvider jwtTokenAuthenticationProvider, + SimpleCORSFilter simpleCORSFilter) { + this.simpleCORSFilter = simpleCORSFilter; this.jwtTokenAuthenticationProvider = jwtTokenAuthenticationProvider; } - @Override - protected void configure(HttpSecurity http) throws Exception { + @Bean + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http - .csrf().disable() - .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) - .and() - .authorizeRequests() - .antMatchers("/css/**", "/server/**", "/scripts/**", "/webjars/**", "/templates/**").permitAll() - .antMatchers("/*/swagger.json", "/*/swagger.yaml").permitAll() - .and() - .anonymous().disable() - .exceptionHandling() - .authenticationEntryPoint(unauthorizedEntryPoint()); + .csrf(AbstractHttpConfigurer::disable) + .sessionManagement(sess -> sess.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) + .authorizeHttpRequests(auth -> auth + .requestMatchers("/css/**", "/server/**", "/scripts/**", + "/webjars/**", "/templates/**", "/*/swagger.json", "/*/swagger.yaml").permitAll() + .anyRequest().authenticated() + ) + .exceptionHandling(exception -> exception + .authenticationEntryPoint(unauthorizedEntryPoint()) + ); http - .addFilterBefore(new SimpleCORSFilter(), BasicAuthenticationFilter.class) - .addFilterAfter(new HttpAuthenticationFilter(authenticationManager()), SimpleCORSFilter.class); + .addFilterBefore(simpleCORSFilter, BasicAuthenticationFilter.class) + .addFilterAfter(new HttpAuthenticationFilter(http.getSharedObject(AuthenticationManager.class)), SimpleCORSFilter.class); + + return http.build(); } - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { + @Bean + public AuthenticationManager authenticationManagerBuilder(AuthenticationManagerBuilder auth) throws Exception { auth .authenticationProvider(jwtTokenAuthenticationProvider) .authenticationProvider(anonymousAuthenticationProvider()); + return auth.build(); } - @Bean - @Override - public AuthenticationManager authenticationManagerBean() throws Exception { - return super.authenticationManagerBean(); - } - - //@Bean - //public JwtTokenAuthenticationProvider jwtTokenAuthenticationProvider() { - // return new JwtTokenAuthenticationProvider(); - //} - @Bean public HiveAnonymousAuthenticationProvider anonymousAuthenticationProvider() { return new HiveAnonymousAuthenticationProvider(); diff --git a/devicehive-proxy-ws-kafka-impl/src/main/java/com/devicehive/proxy/config/FrontendProxyClientConfig.java b/devicehive-proxy-ws-kafka-impl/src/main/java/com/devicehive/proxy/config/FrontendProxyClientConfig.java index b8bc12536..8d90dd485 100644 --- a/devicehive-proxy-ws-kafka-impl/src/main/java/com/devicehive/proxy/config/FrontendProxyClientConfig.java +++ b/devicehive-proxy-ws-kafka-impl/src/main/java/com/devicehive/proxy/config/FrontendProxyClientConfig.java @@ -36,13 +36,13 @@ import com.lmax.disruptor.WaitStrategy; import com.lmax.disruptor.WorkerPool; import com.lmax.disruptor.YieldingWaitStrategy; +import jakarta.annotation.PostConstruct; 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.context.annotation.Profile; -import javax.annotation.PostConstruct; import java.util.UUID; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; diff --git a/devicehive-rdbms-dao/src/main/java/com/devicehive/application/RdbmsPersistenceConfig.java b/devicehive-rdbms-dao/src/main/java/com/devicehive/application/RdbmsPersistenceConfig.java index ee8c791ce..1c991b179 100644 --- a/devicehive-rdbms-dao/src/main/java/com/devicehive/application/RdbmsPersistenceConfig.java +++ b/devicehive-rdbms-dao/src/main/java/com/devicehive/application/RdbmsPersistenceConfig.java @@ -20,6 +20,8 @@ * #L% */ +import jakarta.persistence.SharedCacheMode; +import jakarta.persistence.ValidationMode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.domain.EntityScan; @@ -36,8 +38,6 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.transaction.annotation.EnableTransactionManagement; -import javax.persistence.SharedCacheMode; -import javax.persistence.ValidationMode; import javax.sql.DataSource; import java.util.Map; import java.util.Properties; diff --git a/devicehive-rdbms-dao/src/main/resources/application-persistence.properties b/devicehive-rdbms-dao/src/main/resources/application-persistence.properties index 222cb5bd9..eb21c839e 100644 --- a/devicehive-rdbms-dao/src/main/resources/application-persistence.properties +++ b/devicehive-rdbms-dao/src/main/resources/application-persistence.properties @@ -21,7 +21,7 @@ spring.datasource.driver-class-name=org.postgresql.Driver spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/devicehive spring.datasource.username=postgres -spring.datasource.password=12345 +spring.datasource.password=postgres # JPA spring.data.jpa.repositories.enabled=false diff --git a/devicehive-shim-kafka-impl/src/main/java/com/devicehive/shim/config/client/KafkaRpcClientConfig.java b/devicehive-shim-kafka-impl/src/main/java/com/devicehive/shim/config/client/KafkaRpcClientConfig.java index e41ad15b3..872c0bff1 100644 --- a/devicehive-shim-kafka-impl/src/main/java/com/devicehive/shim/config/client/KafkaRpcClientConfig.java +++ b/devicehive-shim-kafka-impl/src/main/java/com/devicehive/shim/config/client/KafkaRpcClientConfig.java @@ -30,6 +30,7 @@ import com.devicehive.shim.kafka.serializer.ResponseSerializer; import com.devicehive.shim.kafka.topic.KafkaTopicService; import com.google.gson.Gson; +import jakarta.annotation.PostConstruct; import org.apache.kafka.clients.producer.KafkaProducer; import org.apache.kafka.clients.producer.Producer; import org.apache.kafka.common.serialization.StringSerializer; @@ -43,7 +44,6 @@ import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment; -import javax.annotation.PostConstruct; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; diff --git a/devicehive-shim-kafka-impl/src/main/java/com/devicehive/shim/config/server/KafkaRpcServerConfig.java b/devicehive-shim-kafka-impl/src/main/java/com/devicehive/shim/config/server/KafkaRpcServerConfig.java index e65255bb4..ea01e03d5 100644 --- a/devicehive-shim-kafka-impl/src/main/java/com/devicehive/shim/config/server/KafkaRpcServerConfig.java +++ b/devicehive-shim-kafka-impl/src/main/java/com/devicehive/shim/config/server/KafkaRpcServerConfig.java @@ -43,6 +43,7 @@ import com.lmax.disruptor.WaitStrategy; import com.lmax.disruptor.WorkerPool; import com.lmax.disruptor.YieldingWaitStrategy; +import jakarta.annotation.PostConstruct; import org.apache.kafka.clients.producer.KafkaProducer; import org.apache.kafka.clients.producer.Producer; import org.apache.kafka.common.serialization.StringSerializer; @@ -58,7 +59,6 @@ import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment; -import javax.annotation.PostConstruct; import java.util.stream.IntStream; import static com.devicehive.configuration.Constants.REQUEST_TOPIC; diff --git a/devicehive-test-utils/pom.xml b/devicehive-test-utils/pom.xml index 0ecb57b06..a573f7c53 100644 --- a/devicehive-test-utils/pom.xml +++ b/devicehive-test-utils/pom.xml @@ -1 +1 @@ - 4.0.0 devicehive-server com.devicehive 4.1.0 devicehive-test-utils DeviceHive Test Utils ${project.parent.basedir} 5.8.2 org.hsqldb hsqldb ${hsqldb.version} org.hibernate hibernate-core org.springframework.boot spring-boot-starter-test org.apache.kafka kafka-clients ${kafka.version} test org.apache.kafka kafka_${scala-binaries.version} ${kafka.version} slf4j-log4j12 org.slf4j org.apache.kafka kafka_${scala-binaries.version} ${kafka.version} test slf4j-log4j12 org.slf4j org.junit.jupiter junit-jupiter-migrationsupport ${junit-jupiter-migrationsupport.version} \ No newline at end of file + 4.0.0 devicehive-server com.devicehive 4.1.0 devicehive-test-utils DeviceHive Test Utils ${project.parent.basedir} 5.8.2 org.hsqldb hsqldb ${hsqldb.version} org.springframework.boot spring-boot-starter-test org.apache.kafka kafka-clients ${kafka.version} test org.apache.kafka kafka_${scala-binaries.version} ${kafka.version} slf4j-log4j12 org.slf4j org.apache.kafka kafka_${scala-binaries.version} ${kafka.version} test slf4j-log4j12 org.slf4j org.junit.jupiter junit-jupiter-migrationsupport ${junit-jupiter-migrationsupport.version} org.hibernate.orm hibernate-core \ No newline at end of file diff --git a/pom.xml b/pom.xml index aa3263482..a4b632520 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ UTF-8 - 2.7.5 + 3.1.5 3.8.0 1.6.6 @@ -43,12 +43,22 @@ 2.2.4 3.5.1 2.13 + 3.1.5 1.7.5 - 1.1.3 + 2.0 + 2.16.0 + 5.7.7 + 6.1.5 + 1.2.9 + 6.1.2 + 2.15.4 + 4.1.94.Final + 2.15.2 + 2.3.7.Final 4.11 2.12.0 2.3.2 - 9.4-1201-jdbc4 + 42.3.8 1.2.3.RELEASE 4.5.14 0.8 @@ -56,7 +66,7 @@ 2.8.0 3.3 1.9 - 31.1-jre + 32.1.1-jre 2.5 1.11.1 3.3.6 @@ -133,6 +143,26 @@ + + org.springframework.boot + spring-boot-starter-security + ${spring-boot-starter-security.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson-databind.version} + + + org.springframework.security + spring-security-web + ${spring-security-web.version} + + + org.springframework.security + spring-security-config + ${spring-security-config.version} + org.apache.kafka kafka-clients @@ -235,7 +265,11 @@ disruptor ${lmax-disruptor.version} - + + org.springframework.security + spring-security-core + ${spring-security-core.version} + io.swagger swagger-annotations @@ -246,7 +280,11 @@ swagger-jersey2-jaxrs ${swagger.version} - + + org.yaml + snakeyaml + ${snakeyaml.version} + javax.ws.rs javax.ws.rs-api