Merge branch 'eugenp:master' into PR-7005
This commit is contained in:
commit
49f51d1f56
|
@ -76,6 +76,11 @@
|
|||
<artifactId>jersey-apache-connector</artifactId>
|
||||
<version>${jersey.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-multipart</artifactId>
|
||||
<version>${jersey.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -102,4 +107,4 @@
|
|||
<jersey.version>3.1.1</jersey.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
package com.baeldung.jersey.server.form;
|
||||
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
@Path("form")
|
||||
public class FormExampleResource
|
||||
{
|
||||
@GET
|
||||
@Path("/example1")
|
||||
@Produces({MediaType.TEXT_HTML})
|
||||
public InputStream getExample1() throws Exception
|
||||
{
|
||||
File f = new File("src/main/resources/html/example1.html");
|
||||
return new FileInputStream(f);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/example2")
|
||||
@Produces({MediaType.TEXT_HTML})
|
||||
public InputStream getExample2() throws Exception
|
||||
{
|
||||
File f = new File("src/main/resources/html/example2.html");
|
||||
return new FileInputStream(f);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/example1")
|
||||
public String example1(@FormParam("first_name") String firstName,
|
||||
@FormParam("last_name") String lastName,
|
||||
@FormParam("age") String age)
|
||||
{
|
||||
return "Got: First = " + firstName + ", Last = " + lastName + ", Age = " + age;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/example2")
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
public String example2(@FormDataParam("first_name") String firstName,
|
||||
@FormDataParam("last_name") String lastName,
|
||||
@FormDataParam("age") String age,
|
||||
@FormDataParam("photo") InputStream photo)
|
||||
throws Exception
|
||||
{
|
||||
int len;
|
||||
int size = 1024;
|
||||
byte[] buf;
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
buf = new byte[size];
|
||||
while ((len = photo.read(buf, 0, size)) != -1)
|
||||
bos.write(buf, 0, len);
|
||||
buf = bos.toByteArray();
|
||||
return "Got: First = " + firstName + ", Last = " + lastName + ", Age = " + age + ", Photo (# of bytes) = " + buf.length;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Example 1 using @FormParam</title>
|
||||
</head>
|
||||
<body>
|
||||
<form method="post" action="/form/example1">
|
||||
<label for="first_name">First Name</label>
|
||||
<input id="first_name" name="first_name" type="text">
|
||||
<label for="last_name">Last Name</label>
|
||||
<input id="last_name" name="last_name" type="text">
|
||||
<label for="age">Age</label>
|
||||
<input id="age" name="age" type="text">
|
||||
<input type="submit">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,18 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Example 2 using @FormDataParam</title>
|
||||
</head>
|
||||
<body>
|
||||
<form method="post" action="/form/example2" enctype="multipart/form-data">
|
||||
<label for="first_name">First Name</label>
|
||||
<input id="first_name" name="first_name" type="text">
|
||||
<label for="last_name">Last Name</label>
|
||||
<input id="last_name" name="last_name" type="text">
|
||||
<label for="age">Age</label>
|
||||
<input id="age" name="age" type="text">
|
||||
<label for="photo">Profile Photo</label>
|
||||
<input id="photo" name="photo" type="file">
|
||||
<input type="submit">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
1
pom.xml
1
pom.xml
|
@ -1005,6 +1005,7 @@
|
|||
<module>spring-cloud-modules/spring-cloud-azure</module>
|
||||
<module>spring-cloud-modules/spring-cloud-circuit-breaker</module>
|
||||
<module>spring-cloud-modules/spring-cloud-contract</module>
|
||||
<module>spring-cloud-modules/spring-cloud-data-flow</module>
|
||||
<module>spring-cloud-modules/spring-cloud-netflix-feign</module>
|
||||
<module>spring-cloud-modules/spring-cloud-stream-starters</module>
|
||||
<module>spring-cloud-modules/spring-cloud-zuul-eureka-integration</module>
|
||||
|
|
|
@ -102,7 +102,7 @@
|
|||
</build>
|
||||
|
||||
<properties>
|
||||
<start-class>com.baeldung.keycloak.SpringBoot</start-class>
|
||||
<start-class>com.baeldung.keycloak.SpringBootKeycloakApp</start-class>
|
||||
<jaxb-runtime.version>4.0.0</jaxb-runtime.version>
|
||||
<wsdl4j.version>1.6.3</wsdl4j.version>
|
||||
<jaxb2-maven-plugin.version>2.5.0</jaxb2-maven-plugin.version>
|
||||
|
|
|
@ -6,11 +6,10 @@ import org.springframework.context.annotation.Bean;
|
|||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@SpringBootApplication
|
||||
|
||||
public class SpringBoot {
|
||||
public class SpringBootKeycloakApp {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringBoot.class, args);
|
||||
SpringApplication.run(SpringBootKeycloakApp.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
|
@ -4,10 +4,9 @@ import org.junit.Test;
|
|||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import com.baeldung.keycloak.SpringBoot;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = { SpringBoot.class })
|
||||
@SpringBootTest(classes = { SpringBootKeycloakApp.class })
|
||||
public class KeycloakContextIntegrationTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -3,10 +3,11 @@ package com.baeldung.swaggerkeycloak;
|
|||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.config.Customizer;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer;
|
||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||
import org.springframework.security.core.session.SessionRegistryImpl;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy;
|
||||
|
@ -24,16 +25,19 @@ public class GlobalSecurityConfig {
|
|||
|
||||
@Bean
|
||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||
http.csrf()
|
||||
.disable()
|
||||
.authorizeRequests()
|
||||
.requestMatchers(HttpMethod.OPTIONS)
|
||||
|
||||
http.csrf(AbstractHttpConfigurer::disable)
|
||||
.authorizeHttpRequests((requests) -> requests.requestMatchers(HttpMethod.OPTIONS)
|
||||
.permitAll()
|
||||
.requestMatchers("/api/**")
|
||||
.authenticated()
|
||||
.anyRequest()
|
||||
.permitAll();
|
||||
http.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt);
|
||||
.permitAll());
|
||||
|
||||
http.oauth2ResourceServer((oauth2) -> oauth2
|
||||
.jwt(Customizer.withDefaults())
|
||||
);
|
||||
|
||||
return http.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -41,28 +41,35 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-contract-wiremock</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<version>${spring-cloud-contract.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-contract-stub-runner</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<version>${spring-cloud-contract.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-contract-verifier</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<version>${spring-cloud-contract.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy</artifactId>
|
||||
<version>${groovy.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<properties>
|
||||
<spring-cloud.version>4.0.3</spring-cloud.version>
|
||||
<spring-cloud-contract.version>4.0.4</spring-cloud-contract.version>
|
||||
<spring-boot.version>2.1.4.RELEASE</spring-boot.version>
|
||||
<log4j2.version>2.17.1</log4j2.version>
|
||||
<groovy.version>2.5.6</groovy.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -16,6 +16,15 @@
|
|||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-rest</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-contract-wiremock</artifactId>
|
||||
|
@ -26,20 +35,13 @@
|
|||
<artifactId>spring-cloud-contract-stub-runner</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-rest</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baeldung.spring.cloud</groupId>
|
||||
<artifactId>spring-cloud-contract-producer</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
|
@ -50,6 +52,12 @@
|
|||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -16,19 +16,17 @@
|
|||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-contract-verifier</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-rest</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
|
@ -39,6 +37,18 @@
|
|||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-contract-verifier</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -46,7 +56,7 @@
|
|||
<plugin>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
|
||||
<version>2.1.1.RELEASE</version>
|
||||
<version>${spring-cloud-contract.version}</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<baseClassForTests>com.baeldung.spring.cloud.springcloudcontractproducer.BaseTestClass
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.context.annotation.Configuration;
|
|||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.session.data.redis.config.ConfigureRedisAction;
|
||||
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
|
@ -39,5 +40,10 @@ public class DataFlowServerApplicationIntegrationTest {
|
|||
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public static ConfigureRedisAction configureRedisAction() {
|
||||
return ConfigureRedisAction.NO_OP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue