Skip to content

Commit fb018de

Browse files
Scenario completed
1 parent 45533a1 commit fb018de

File tree

5 files changed

+111
-1
lines changed

5 files changed

+111
-1
lines changed

http-client-demo/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Новый HTTP-клиент от Amplicode на Kotlin Script для Spring-приложений и не только
2+
3+
[![](https://i3.ytimg.com/vi/P-aN3GuWYvo/maxresdefault.jpg)](https://youtu.be/P-aN3GuWYvo)
4+
5+
Текущая директория содержит проект `app`, который был использован в видео.
6+
7+
Все действия производились в ветке `http-client-demo`.
8+
9+
Первый коммит с которого можно начать повторять демо `45533a161d53426276793623c93931c519f10d66`.

http-client-demo/app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ dependencies {
2929
'org.flywaydb:flyway-core',
3030
'org.flywaydb:flyway-database-postgresql',
3131
'org.springframework.kafka:spring-kafka',
32-
'org.springframework.boot:spring-boot-docker-compose'
32+
'org.springframework.boot:spring-boot-docker-compose',
33+
'org.springframework.boot:spring-boot-starter-security'
3334
)
3435

3536
runtimeOnly (
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"test": {
3+
"login": "admin",
4+
"password": "admin",
5+
"host": "http://localhost:8080"
6+
}
7+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import org.hamcrest.CoreMatchers.`is`
2+
import java.util.*
3+
4+
val login: String by env
5+
val password: String by env
6+
val token: String = Base64.getEncoder().encodeToString("$login:$password".toByteArray())
7+
8+
val host: String by env
9+
10+
GET("$host/rest/owners/{id}") {
11+
header("Authorization", "Basic $token")
12+
pathParams("id", 1)
13+
}
14+
15+
GET("$host/rest/owners") {
16+
header("Authorization", "Basic $token")
17+
queryParam("firstNameStarts", "J")
18+
}
19+
20+
val id by variable<Long>()
21+
22+
POST("$host/rest/owners") {
23+
header("Authorization", "Basic $token")
24+
header("Content-Type", "application/json")
25+
body(
26+
"""
27+
{
28+
"firstName": "Johny",
29+
"lastName": "Dow-vie",
30+
"address": "Spring Avenue",
31+
"city": "London",
32+
"telephone": null
33+
}
34+
""".trimIndent()
35+
)
36+
} extract {
37+
id.set(body().jsonPath().getLong("id"))
38+
}
39+
40+
GET("$host/rest/owners/{id}") {
41+
header("Authorization", "Basic $token")
42+
pathParams("id", id.get()!!)
43+
} assert {
44+
statusCode(200)
45+
body("firstName", `is`("Johny"))
46+
body("lastName", `is`("Dow-vie"))
47+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.springframework.samples.petclinic;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.security.config.Customizer;
6+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
7+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
8+
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
9+
import org.springframework.security.core.userdetails.User;
10+
import org.springframework.security.core.userdetails.UserDetailsService;
11+
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
12+
import org.springframework.security.web.SecurityFilterChain;
13+
14+
@Configuration
15+
@EnableWebSecurity
16+
public class WebSecurityConfiguration {
17+
18+
@Bean
19+
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
20+
http.authorizeHttpRequests(authorizeHttpRequests -> authorizeHttpRequests
21+
.anyRequest()
22+
.authenticated());
23+
http.headers(Customizer.withDefaults());
24+
http.sessionManagement(Customizer.withDefaults());
25+
http.formLogin(Customizer.withDefaults());
26+
http.anonymous(Customizer.withDefaults());
27+
http.csrf(AbstractHttpConfigurer::disable);
28+
http.userDetailsService(inMemoryUserDetailsService());
29+
http.httpBasic(Customizer.withDefaults());
30+
return http.build();
31+
}
32+
33+
public UserDetailsService inMemoryUserDetailsService() {
34+
User.UserBuilder users = User.builder();
35+
InMemoryUserDetailsManager userDetailsManager = new InMemoryUserDetailsManager();
36+
userDetailsManager.createUser(users.username("admin")
37+
.password("{noop}admin")
38+
.roles("ADMIN")
39+
.build());
40+
userDetailsManager.createUser(users.username("user")
41+
.password("{noop}user")
42+
.roles("USER")
43+
.build());
44+
return userDetailsManager;
45+
}
46+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy