forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/eugenp/tutorials
- Loading branch information
Showing
30 changed files
with
301 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
### Relevant Articles: | ||
- [Introduction to Apache CXF](http://www.baeldung.com/introduction-to-apache-cxf) | ||
- [Introduction to Apache CXF](https://www.baeldung.com/introduction-to-apache-cxf) |
45 changes: 45 additions & 0 deletions
45
...a-11-2/src/test/java/com/baeldung/httpclient/parameters/HttpClientParametersLiveTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.baeldung.httpclient.parameters; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.http.HttpClient; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class HttpClientParametersLiveTest { | ||
|
||
private static HttpClient client; | ||
|
||
@BeforeAll | ||
public static void setUp() { | ||
client = HttpClient.newHttpClient(); | ||
} | ||
|
||
@Test | ||
public void givenQueryParams_whenGetRequest_thenResponseOk() throws IOException, InterruptedException { | ||
HttpRequest request = HttpRequest.newBuilder() | ||
.version(HttpClient.Version.HTTP_2) | ||
.uri(URI.create("https://postman-echo.com/get?param1=value1¶m2=value2")) | ||
.GET() | ||
.build(); | ||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); | ||
|
||
assertEquals(response.statusCode(), 200); | ||
} | ||
|
||
@Test | ||
public void givenQueryParams_whenGetRequestWithDefaultConfiguration_thenResponseOk() throws IOException, InterruptedException { | ||
HttpRequest request = HttpRequest.newBuilder() | ||
.uri(URI.create("https://postman-echo.com/get?param1=value1¶m2=value2")) | ||
.build(); | ||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); | ||
|
||
assertEquals(response.statusCode(), 200); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Relevant Articles: | ||
|
||
- [Running Spring Boot with PostgreSQL in Docker Compose](https://www.baeldung.com/spring-boot-postgresql-docker) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Relevant Articles: | ||
|
||
- [How To Configure Java Heap Size Inside a Docker Container](https://www.baeldung.com/ops/docker-jvm-heap-size) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...g-boot-modules/spring-boot-keycloak/src/main/java/com/baeldung/disablingkeycloak/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.baeldung.disablingkeycloak; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication(scanBasePackages = { "com.baeldung.disablingkeycloak" }) | ||
public class App { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(App.class, args); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...t-keycloak/src/main/java/com/baeldung/disablingkeycloak/DisableSecurityConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.baeldung.disablingkeycloak; | ||
|
||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
|
||
@Configuration | ||
@ConditionalOnProperty(name = "keycloak.enabled", havingValue = "false") | ||
public class DisableSecurityConfiguration extends WebSecurityConfigurerAdapter { | ||
|
||
@Override | ||
protected void configure(final HttpSecurity http) throws Exception { | ||
http.csrf() | ||
.disable() | ||
.authorizeRequests() | ||
.anyRequest() | ||
.permitAll(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...ing-boot-keycloak/src/main/java/com/baeldung/disablingkeycloak/KeycloakConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.baeldung.disablingkeycloak; | ||
|
||
import org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class KeycloakConfiguration { | ||
|
||
@Bean | ||
public KeycloakSpringBootConfigResolver keycloakConfigResolver() { | ||
return new KeycloakSpringBootConfigResolver(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...ng-boot-keycloak/src/main/java/com/baeldung/disablingkeycloak/KeycloakSecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.baeldung.disablingkeycloak; | ||
|
||
import org.keycloak.adapters.springsecurity.KeycloakConfiguration; | ||
import org.keycloak.adapters.springsecurity.config.KeycloakWebSecurityConfigurerAdapter; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.web.authentication.session.NullAuthenticatedSessionStrategy; | ||
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy; | ||
|
||
@KeycloakConfiguration | ||
@ConditionalOnProperty(name = "keycloak.enabled", havingValue = "true", matchIfMissing = true) | ||
public class KeycloakSecurityConfig extends KeycloakWebSecurityConfigurerAdapter { | ||
|
||
@Autowired | ||
public void configureGlobal(AuthenticationManagerBuilder auth) { | ||
auth.authenticationProvider(keycloakAuthenticationProvider()); | ||
} | ||
|
||
@Bean | ||
@Override | ||
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() { | ||
return new NullAuthenticatedSessionStrategy(); | ||
} | ||
|
||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
super.configure(http); | ||
|
||
http.csrf() | ||
.disable() | ||
.authorizeRequests() | ||
.anyRequest() | ||
.authenticated(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...-boot-modules/spring-boot-keycloak/src/main/java/com/baeldung/disablingkeycloak/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.baeldung.disablingkeycloak; | ||
|
||
public class User { | ||
private Long id; | ||
private String firstname; | ||
private String lastname; | ||
|
||
public User() { | ||
} | ||
|
||
public User(Long id, String firstname, String lastname) { | ||
this.id = id; | ||
this.firstname = firstname; | ||
this.lastname = lastname; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getFirstname() { | ||
return firstname; | ||
} | ||
|
||
public void setFirstname(String firstname) { | ||
this.firstname = firstname; | ||
} | ||
|
||
public String getLastname() { | ||
return lastname; | ||
} | ||
|
||
public void setLastname(String lastname) { | ||
this.lastname = lastname; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...les/spring-boot-keycloak/src/main/java/com/baeldung/disablingkeycloak/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.baeldung.disablingkeycloak; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/users") | ||
public class UserController { | ||
|
||
@GetMapping("/{userId}") | ||
public User getCustomer(@PathVariable Long userId) { | ||
return new User(userId, "John", "Doe"); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...modules/spring-boot-keycloak/src/main/resources/application-disabling-keycloak.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Keycloak authentication is enabled for production. | ||
keycloak.enabled=true | ||
keycloak.realm=SpringBootKeycloak | ||
keycloak.auth-server-url=http://localhost:8180/auth | ||
keycloak.resource=login-app | ||
keycloak.bearer-only=true | ||
keycloak.ssl-required=external |
33 changes: 33 additions & 0 deletions
33
...ycloak/src/test/java/com/baeldung/disablingkeycloak/DisablingKeycloakIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.baeldung.disablingkeycloak; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
@SpringBootTest(classes = App.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
@RunWith(SpringRunner.class) | ||
@ActiveProfiles("disablingkeycloak") | ||
public class DisablingKeycloakIntegrationTest { | ||
|
||
@Autowired | ||
private TestRestTemplate restTemplate; | ||
|
||
@Test | ||
public void givenUnauthenticated_whenGettingUser_shouldReturnUser() { | ||
ResponseEntity<User> responseEntity = restTemplate.getForEntity("/users/1", User.class); | ||
|
||
assertEquals(HttpStatus.SC_OK, responseEntity.getStatusCodeValue()); | ||
assertNotNull(responseEntity.getBody() | ||
.getFirstname()); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...-modules/spring-boot-keycloak/src/test/resources/application-disablingkeycloak.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
keycloak.enabled=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.