spring-boot

Spring Security returns 403 with valid JWT

烂漫一生 提交于 2021-02-09 08:09:00
问题 I'm using Postman to test a simple OAuth2 API I'm creating in Spring Boot 2.2.6 with Spring Security. I successfully receive a JWT when requesting new user credentials, but all of my endpoints return a 403 Forbidden error when I attempt to access them with this token in my headers. My classes are as follows: My server security configuration: @Configuration @EnableWebSecurity @Order(1) @EnableGlobalMethodSecurity(prePostEnabled = true, proxyTargetClass = true) class ServerSecurityConfiguration

Spring Security returns 403 with valid JWT

只谈情不闲聊 提交于 2021-02-09 08:06:39
问题 I'm using Postman to test a simple OAuth2 API I'm creating in Spring Boot 2.2.6 with Spring Security. I successfully receive a JWT when requesting new user credentials, but all of my endpoints return a 403 Forbidden error when I attempt to access them with this token in my headers. My classes are as follows: My server security configuration: @Configuration @EnableWebSecurity @Order(1) @EnableGlobalMethodSecurity(prePostEnabled = true, proxyTargetClass = true) class ServerSecurityConfiguration

Spring Security returns 403 with valid JWT

会有一股神秘感。 提交于 2021-02-09 08:05:33
问题 I'm using Postman to test a simple OAuth2 API I'm creating in Spring Boot 2.2.6 with Spring Security. I successfully receive a JWT when requesting new user credentials, but all of my endpoints return a 403 Forbidden error when I attempt to access them with this token in my headers. My classes are as follows: My server security configuration: @Configuration @EnableWebSecurity @Order(1) @EnableGlobalMethodSecurity(prePostEnabled = true, proxyTargetClass = true) class ServerSecurityConfiguration

Spring Boot 2 - Webflux - Websocket - Activate Compression

被刻印的时光 ゝ 提交于 2021-02-09 07:01:27
问题 I'm using: Spring Boot 2.1.0 Release Webflux (not MVC) Websocket Reactive Netty And I would like to compress the returned payload with "GZIP" (or any other compression). I've tried with the configuration in application.yml: server.compression.enabled: true But the payload returned is still in plain text. Does anybody know how to resolve this? Thanks. 回答1: The server.compression.enabled configuration property is about HTTP response compression, so this won't achieve the desired goal. With

Spring Boot 2 - Webflux - Websocket - Activate Compression

喜夏-厌秋 提交于 2021-02-09 07:00:15
问题 I'm using: Spring Boot 2.1.0 Release Webflux (not MVC) Websocket Reactive Netty And I would like to compress the returned payload with "GZIP" (or any other compression). I've tried with the configuration in application.yml: server.compression.enabled: true But the payload returned is still in plain text. Does anybody know how to resolve this? Thanks. 回答1: The server.compression.enabled configuration property is about HTTP response compression, so this won't achieve the desired goal. With

How to fix the null value response of RestTemplate.exchange in a Mockito Test?

点点圈 提交于 2021-02-08 23:38:20
问题 My Service class is below, followed by its test - @Service public class MyServiceImpl implements MyService { @Autowired private RestTemplate restTemplate; @Override public StudentInfo getStudentInfo(String name) { HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); HttpEntity entity = new HttpEntity(headers); StudentInfo student = null; URI uri = new URI("http:\\someurl.com"); ResponseEntity<String> responseEntity = restTemplate.exchange(uri,

Validate UUID Restful service

≡放荡痞女 提交于 2021-02-08 20:54:09
问题 I have a RESTful service which receives POST request with UUID values and writes them in DB. So the problem is to validate if UUID is valid or not. For this purpose I implemented custom annotation: @Constraint(validatedBy = {}) @Target({ElementType.FIELD}) @Retention(RUNTIME) @Pattern(regexp = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[34][0-9a-fA-F]{3}-[89ab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}") public @interface validUuid { String message() default "{invalid.uuid}"; Class<?>[] groups() default {}; Class<?

Liquibase migration on startup doesnt work using Spring-Boot

半城伤御伤魂 提交于 2021-02-08 20:00:08
问题 Following this documentation: To automatically run Liquibase database migrations on startup, add the org.liquibase:liquibase-core to your classpath. The master change log is by default read from db/changelog/db.changelog-master.yaml but can be set using liquibase.change-log. In addition to YAML, Liquibase also supports JSON, XML, and SQL change log formats. I configured my application to use liquibase migrations. I added liquibase.change-log property so my whole application.properties file

How to use @NotNull with spring boot?

跟風遠走 提交于 2021-02-08 20:00:08
问题 I have this dependency: <dependency> <groupId>org.hibernate.validator</groupId> <artifactId>hibernate-validator</artifactId> </dependency> Which have it's version managed by <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.4.RELEASE</version> </parent> And I have this piece: import javax.validation.constraints.NotNull; //other imports ommited @Component @ConfigurationProperties(prefix = "collector") public class

Spring boot - setting default Content-type header if it's not present in request

情到浓时终转凉″ 提交于 2021-02-08 16:59:13
问题 I'm having the following problem: suppose I sometimes receive POST requests with no Content-type header set. In this case I want to assume that Content-type=application/json by default. Can I achieve this somehow using spring boot features and not using filters? Thanks 回答1: As of Spring Boot 2.x, you need to create a class that extends the WebMvcConfigurer interface, e.g.: @Configuration class WebMvcConfiguration implements WebMvcConfigurer { @Override public void configureContentNegotiation(