Skip to content

Commit dbf7f72

Browse files
authored
Merge branch 'fix_vuln_kafka_upd' into kafka_upd
2 parents e688811 + 82dc545 commit dbf7f72

File tree

49 files changed

+440
-226
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+440
-226
lines changed

devicehive-auth/pom.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,16 @@
6767
</exclusions>
6868
</dependency>
6969
<dependency>
70-
<groupId>org.springframework.boot</groupId>
71-
<artifactId>spring-boot-starter-security</artifactId>
70+
<groupId>org.springframework.security</groupId>
71+
<artifactId>spring-security-core</artifactId>
7272
</dependency>
7373
<dependency>
74-
<groupId>org.springframework.boot</groupId>
75-
<artifactId>spring-boot-starter-aop</artifactId>
74+
<groupId>org.springframework.security</groupId>
75+
<artifactId>spring-security-config</artifactId>
76+
</dependency>
77+
<dependency>
78+
<groupId>org.springframework.security</groupId>
79+
<artifactId>spring-security-web</artifactId>
7680
</dependency>
7781
</dependencies>
7882
<build>

devicehive-auth/src/main/java/com/devicehive/application/AuthRpcClientConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.devicehive.shim.kafka.serializer.ResponseSerializer;
3131
import com.devicehive.shim.kafka.topic.KafkaTopicService;
3232
import com.google.gson.Gson;
33+
import jakarta.annotation.PostConstruct;
3334
import org.apache.kafka.clients.producer.KafkaProducer;
3435
import org.apache.kafka.clients.producer.Producer;
3536
import org.apache.kafka.common.serialization.StringSerializer;
@@ -38,7 +39,6 @@
3839
import org.springframework.context.annotation.*;
3940
import org.springframework.core.env.Environment;
4041

41-
import javax.annotation.PostConstruct;
4242
import java.net.InetAddress;
4343
import java.net.NetworkInterface;
4444
import java.net.SocketException;

devicehive-auth/src/main/java/com/devicehive/application/DeviceHiveAuthApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public Gson gson() {
9292
}
9393

9494
@Bean
95-
public Validator localValidator() {
95+
public LocalValidatorFactoryBean localValidator() {
9696
return new LocalValidatorFactoryBean();
9797
}
9898
}

devicehive-auth/src/main/java/com/devicehive/application/filter/SwaggerFilter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
* #L%
2121
*/
2222

23+
import jakarta.servlet.FilterChain;
24+
import jakarta.servlet.ServletException;
25+
import jakarta.servlet.annotation.WebFilter;
26+
import jakarta.servlet.http.HttpServletRequest;
27+
import jakarta.servlet.http.HttpServletResponse;
2328
import org.slf4j.Logger;
2429
import org.slf4j.LoggerFactory;
2530
import org.springframework.beans.factory.annotation.Value;
2631
import org.springframework.web.filter.OncePerRequestFilter;
2732

28-
import javax.servlet.FilterChain;
29-
import javax.servlet.ServletException;
30-
import javax.servlet.annotation.WebFilter;
31-
import javax.servlet.http.HttpServletRequest;
32-
import javax.servlet.http.HttpServletResponse;
3333
import java.io.IOException;
3434
import java.net.URL;
3535

devicehive-auth/src/main/java/com/devicehive/application/security/WebSecurityConfig.java

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.devicehive.model.ErrorResponse;
2828
import com.google.gson.Gson;
2929
import com.google.gson.GsonBuilder;
30+
import jakarta.servlet.http.HttpServletResponse;
3031
import org.springframework.context.annotation.Bean;
3132
import org.springframework.context.annotation.Configuration;
3233
import org.springframework.core.Ordered;
@@ -36,57 +37,57 @@
3637
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
3738
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
3839
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
39-
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
40+
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
4041
import org.springframework.security.config.http.SessionCreationPolicy;
4142
import org.springframework.security.web.AuthenticationEntryPoint;
43+
import org.springframework.security.web.SecurityFilterChain;
4244
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
4345

44-
import javax.servlet.http.HttpServletResponse;
46+
4547

4648
@Configuration
4749
@EnableWebSecurity
4850
@Order(Ordered.HIGHEST_PRECEDENCE)
49-
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
51+
public class WebSecurityConfig {
5052

51-
private Gson gson = new GsonBuilder().create();
53+
private final Gson gson = new GsonBuilder().create();
5254

55+
private final SimpleCORSFilter simpleCORSFilter;
5356
private final JwtTokenAuthenticationProvider jwtTokenAuthenticationProvider;
5457

55-
public WebSecurityConfig(final JwtTokenAuthenticationProvider jwtTokenAuthenticationProvider) {
56-
super();
58+
public WebSecurityConfig(JwtTokenAuthenticationProvider jwtTokenAuthenticationProvider,
59+
SimpleCORSFilter simpleCORSFilter) {
60+
this.simpleCORSFilter = simpleCORSFilter;
5761
this.jwtTokenAuthenticationProvider = jwtTokenAuthenticationProvider;
5862
}
5963

60-
@Override
61-
protected void configure(HttpSecurity http) throws Exception {
64+
@Bean
65+
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
6266
http
63-
.csrf().disable()
64-
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
65-
.and()
66-
.authorizeRequests()
67-
.antMatchers("/css/**", "/server/**", "/scripts/**", "/webjars/**", "/templates/**").permitAll()
68-
.antMatchers("/*/swagger.json", "/*/swagger.yaml").permitAll()
69-
.and()
70-
.anonymous().disable()
71-
.exceptionHandling()
72-
.authenticationEntryPoint(unauthorizedEntryPoint());
67+
.csrf(AbstractHttpConfigurer::disable)
68+
.sessionManagement(sess -> sess.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
69+
.authorizeHttpRequests(auth -> auth
70+
.requestMatchers("/css/**", "/server/**", "/scripts/**",
71+
"/webjars/**", "/templates/**", "/*/swagger.json", "/*/swagger.yaml").permitAll()
72+
.anyRequest().authenticated()
73+
)
74+
.exceptionHandling(exception -> exception
75+
.authenticationEntryPoint(unauthorizedEntryPoint())
76+
);
7377

7478
http
75-
.addFilterBefore(new SimpleCORSFilter(), BasicAuthenticationFilter.class)
76-
.addFilterAfter(new HttpAuthenticationFilter(authenticationManager()), SimpleCORSFilter.class);
79+
.addFilterBefore(simpleCORSFilter, BasicAuthenticationFilter.class)
80+
.addFilterAfter(new HttpAuthenticationFilter(http.getSharedObject(AuthenticationManager.class)), SimpleCORSFilter.class);
81+
82+
return http.build();
7783
}
7884

79-
@Override
80-
protected void configure(AuthenticationManagerBuilder auth) {
85+
@Bean
86+
public AuthenticationManager authenticationManagerBuilder(AuthenticationManagerBuilder auth) throws Exception {
8187
auth
8288
.authenticationProvider(jwtTokenAuthenticationProvider)
8389
.authenticationProvider(anonymousAuthenticationProvider());
84-
}
85-
86-
@Bean
87-
@Override
88-
public AuthenticationManager authenticationManagerBean() throws Exception {
89-
return super.authenticationManagerBean();
90+
return auth.build();
9091
}
9192

9293
@Bean
@@ -103,4 +104,4 @@ public AuthenticationEntryPoint unauthorizedEntryPoint() {
103104
gson.toJson(new ErrorResponse(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage())));
104105
};
105106
}
106-
}
107+
}

devicehive-backend/src/main/java/com/devicehive/application/DeviceHiveBackendApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222

2323
import org.springframework.boot.WebApplicationType;
24+
import org.springframework.boot.autoconfigure.SpringBootApplication;
2425
import org.springframework.boot.builder.SpringApplicationBuilder;
2526
import org.springframework.context.ConfigurableApplicationContext;
2627
import org.springframework.context.annotation.ComponentScan;

devicehive-backend/src/main/java/com/devicehive/application/RequestHandlersMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
import com.devicehive.shim.api.Action;
3636
import com.devicehive.shim.api.server.RequestHandler;
3737
import com.google.common.collect.ImmutableMap;
38+
import jakarta.annotation.PostConstruct;
3839
import org.springframework.beans.factory.annotation.Autowired;
3940
import org.springframework.stereotype.Component;
4041

41-
import javax.annotation.PostConstruct;
4242
import java.util.Map;
4343

4444
@Component

devicehive-common-service/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
<version>${project.parent.version}</version>
2222
<scope>provided</scope>
2323
</dependency>
24+
<dependency>
25+
<groupId>com.fasterxml.jackson.core</groupId>
26+
<artifactId>jackson-databind</artifactId>
27+
<version>${jackson-databind.version}</version>
28+
</dependency>
2429
<dependency>
2530
<groupId>org.springframework.boot</groupId>
2631
<artifactId>spring-boot-starter-jersey</artifactId>
@@ -60,6 +65,12 @@
6065
<groupId>org.apache.httpcomponents</groupId>
6166
<artifactId>httpclient</artifactId>
6267
</dependency>
68+
<dependency>
69+
<groupId>javax.servlet</groupId>
70+
<artifactId>javax.servlet-api</artifactId>
71+
<version>4.0.1</version>
72+
<scope>compile</scope>
73+
</dependency>
6374
</dependencies>
6475

6576
</project>

devicehive-common-service/src/main/java/com/devicehive/auth/rest/HttpAuthenticationFilter.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
*/
2222

2323
import com.devicehive.auth.HiveAuthentication;
24+
import jakarta.servlet.FilterChain;
25+
import jakarta.servlet.ServletException;
26+
import jakarta.servlet.ServletRequest;
27+
import jakarta.servlet.ServletResponse;
28+
import jakarta.servlet.http.HttpServletRequest;
29+
import jakarta.servlet.http.HttpServletResponse;
2430
import org.slf4j.Logger;
2531
import org.slf4j.LoggerFactory;
2632
import org.slf4j.MDC;
@@ -37,12 +43,7 @@
3743
import org.springframework.web.filter.GenericFilterBean;
3844
import org.springframework.web.util.UrlPathHelper;
3945

40-
import javax.servlet.FilterChain;
41-
import javax.servlet.ServletException;
42-
import javax.servlet.ServletRequest;
43-
import javax.servlet.ServletResponse;
44-
import javax.servlet.http.HttpServletRequest;
45-
import javax.servlet.http.HttpServletResponse;
46+
4647
import java.io.IOException;
4748
import java.net.InetAddress;
4849
import java.net.UnknownHostException;

devicehive-common-service/src/main/java/com/devicehive/auth/rest/SimpleCORSFilter.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,29 @@
99
* Licensed under the Apache License, Version 2.0 (the "License");
1010
* you may not use this file except in compliance with the License.
1111
* You may obtain a copy of the License at
12-
*
12+
*
1313
* http://www.apache.org/licenses/LICENSE-2.0
14-
*
14+
*
1515
* Unless required by applicable law or agreed to in writing, software
1616
* distributed under the License is distributed on an "AS IS" BASIS,
1717
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1818
* See the License for the specific language governing permissions and
1919
* limitations under the License.
2020
* #L%
2121
*/
22-
2322
import org.springframework.web.filter.GenericFilterBean;
23+
import jakarta.servlet.FilterChain;
24+
import jakarta.servlet.ServletException;
25+
import jakarta.servlet.ServletRequest;
26+
import jakarta.servlet.ServletResponse;
27+
import jakarta.servlet.http.HttpServletResponse;
2428

25-
import javax.servlet.FilterChain;
26-
import javax.servlet.ServletException;
27-
import javax.servlet.ServletRequest;
28-
import javax.servlet.ServletResponse;
29-
import javax.servlet.http.HttpServletResponse;
3029
import java.io.IOException;
3130

3231
public class SimpleCORSFilter extends GenericFilterBean {
3332

3433
@Override
35-
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
34+
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException, ServletException {
3635
final HttpServletResponse resp = (HttpServletResponse) servletResponse;
3736
resp.setHeader("Access-Control-Allow-Credentials", "true");
3837
resp.setHeader("Access-Control-Allow-Origin", "*");

devicehive-common-service/src/main/java/com/devicehive/resource/exceptions/AccessDeniedExceptionMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
*/
2222

2323
import com.devicehive.model.ErrorResponse;
24+
import jakarta.servlet.http.HttpServletRequest;
2425
import org.springframework.security.access.AccessDeniedException;
2526

26-
import javax.servlet.http.HttpServletRequest;
2727
import javax.ws.rs.core.Context;
2828
import javax.ws.rs.core.MediaType;
2929
import javax.ws.rs.core.Response;

devicehive-common-service/src/main/java/com/devicehive/resource/exceptions/BadCredentialsExceptionMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
*/
2222

2323
import com.devicehive.model.ErrorResponse;
24+
import jakarta.servlet.http.HttpServletRequest;
2425
import org.springframework.security.authentication.BadCredentialsException;
2526

26-
import javax.servlet.http.HttpServletRequest;
2727
import javax.ws.rs.core.Context;
2828
import javax.ws.rs.core.MediaType;
2929
import javax.ws.rs.core.Response;

devicehive-common-service/src/main/java/com/devicehive/resource/exceptions/InvalidPrincipalExceptionMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
import com.devicehive.exceptions.InvalidPrincipalException;
2424
import com.devicehive.model.ErrorResponse;
25+
import jakarta.servlet.http.HttpServletRequest;
2526

26-
import javax.servlet.http.HttpServletRequest;
2727
import javax.ws.rs.core.Context;
2828
import javax.ws.rs.core.MediaType;
2929
import javax.ws.rs.core.Response;

devicehive-common-service/src/main/java/com/devicehive/security/util/JwtSecretService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222

2323
import com.devicehive.configuration.Constants;
2424
import com.devicehive.service.configuration.ConfigurationService;
25+
import jakarta.annotation.PostConstruct;
2526
import org.springframework.beans.factory.annotation.Autowired;
2627
import org.springframework.stereotype.Component;
2728
import org.springframework.util.StringUtils;
2829

29-
import javax.annotation.PostConstruct;
3030
import java.math.BigInteger;
3131
import java.security.SecureRandom;
3232

devicehive-common-service/src/main/java/com/devicehive/service/BaseDeviceService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import java.util.concurrent.CompletableFuture;
4747

4848
import static com.devicehive.configuration.Messages.ACCESS_DENIED;
49-
import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN;
49+
import static jakarta.servlet.http.HttpServletResponse.SC_FORBIDDEN;
5050
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
5151
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
5252

devicehive-common-service/src/main/java/com/devicehive/service/BaseFilterService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
import static com.devicehive.configuration.Messages.ACCESS_DENIED;
4747
import static com.devicehive.configuration.Messages.DEVICE_TYPES_NOT_FOUND;
4848
import static com.devicehive.configuration.Messages.NETWORKS_NOT_FOUND;
49-
import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN;
50-
import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
49+
import static jakarta.servlet.http.HttpServletResponse.SC_FORBIDDEN;
50+
import static jakarta.servlet.http.HttpServletResponse.SC_NOT_FOUND;
5151

5252
@Component
5353
public class BaseFilterService {

devicehive-common-service/src/main/java/com/devicehive/service/BaseNetworkService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@
5757
import java.util.stream.Collectors;
5858

5959
import static com.devicehive.configuration.Messages.NETWORKS_NOT_FOUND;
60+
import static jakarta.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
61+
import static jakarta.servlet.http.HttpServletResponse.SC_FORBIDDEN;
6062
import static java.util.Optional.empty;
6163
import static java.util.Optional.of;
6264
import static java.util.Optional.ofNullable;
63-
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
64-
import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN;
6565
import static org.springframework.util.CollectionUtils.isEmpty;
6666

6767
@Component

devicehive-common-service/src/main/java/com/devicehive/service/configuration/ConfigurationService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
import org.springframework.beans.factory.annotation.Autowired;
3030
import org.springframework.context.annotation.Lazy;
3131
import org.springframework.stereotype.Component;
32+
import org.springframework.transaction.annotation.Transactional;
33+
3234

33-
import javax.transaction.Transactional;
3435
import javax.validation.constraints.NotNull;
3536
import java.util.Optional;
3637

devicehive-common-service/src/main/java/com/devicehive/service/helpers/HttpRestHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.devicehive.model.ErrorResponse;
2626
import com.google.gson.Gson;
2727
import com.google.gson.JsonSyntaxException;
28+
import jakarta.annotation.PostConstruct;
2829
import org.apache.http.HttpEntity;
2930
import org.apache.http.client.methods.CloseableHttpResponse;
3031
import org.apache.http.client.methods.HttpGet;
@@ -39,7 +40,6 @@
3940
import org.springframework.stereotype.Component;
4041
import org.springframework.util.StringUtils;
4142

42-
import javax.annotation.PostConstruct;
4343
import javax.ws.rs.ServiceUnavailableException;
4444
import javax.ws.rs.core.MediaType;
4545
import javax.ws.rs.core.Response;

0 commit comments

Comments
 (0)