lisan
lisan
JCHJava Community | Help. Code. Learn.
Created by lisan on 10/1/2024 in #java-help
Testcontainers and application-test.yml
I have a question do i need add properties to application-test if im using testcontainers for mysql for example: the part of initialize:
@Override
public void initialize(ConfigurableApplicationContext ctx) {
TestPropertyValues.of(
"spring.datasource.driverClassName=" + mysql.getDriverClassName(),
"spring.datasource.url=" + mysql.getJdbcUrl(),
"spring.datasource.username=" + mysql.getUsername(),
"spring.datasource.password=" + mysql.getPassword()
).applyTo(ctx.getEnvironment());
}
@Override
public void initialize(ConfigurableApplicationContext ctx) {
TestPropertyValues.of(
"spring.datasource.driverClassName=" + mysql.getDriverClassName(),
"spring.datasource.url=" + mysql.getJdbcUrl(),
"spring.datasource.username=" + mysql.getUsername(),
"spring.datasource.password=" + mysql.getPassword()
).applyTo(ctx.getEnvironment());
}
or (here is kafka and postgres, but i think this doesnt matter)
@DynamicPropertySource
static void props(DynamicPropertyRegistry registry) {
registry.add("spring.kafka.bootstrap-servers", kafka::getBootstrapServers);
registry.add("spring.datasource.url", postgres::getJdbcUrl);
registry.add("spring.datasource.username", postgres::getUsername);
registry.add("spring.datasource.password", postgres::getPassword);
}
@DynamicPropertySource
static void props(DynamicPropertyRegistry registry) {
registry.add("spring.kafka.bootstrap-servers", kafka::getBootstrapServers);
registry.add("spring.datasource.url", postgres::getJdbcUrl);
registry.add("spring.datasource.username", postgres::getUsername);
registry.add("spring.datasource.password", postgres::getPassword);
}
so should i have something in my application-test.yml with mysql? or initializing those properties in test containers is enough
4 replies
JCHJava Community | Help. Code. Learn.
Created by lisan on 6/9/2024 in #java-help
JWT return Dto. Login and Register REST Endpoints
@PostMapping("/register")
public AuthenticationResponseDto register(@RequestBody Command command) {
return authenticationService.register(command);
}
@PostMapping("/register")
public AuthenticationResponseDto register(@RequestBody Command command) {
return authenticationService.register(command);
}
public class AuthenticationResponseDto {

private String token;

}
public class AuthenticationResponseDto {

private String token;

}
REST Returning token when register and login? Does it make sense? Maybe shouldnt. Why, why not. If not how can i login and have authentication to other endpoints. What return
4 replies
JCHJava Community | Help. Code. Learn.
Created by lisan on 6/4/2024 in #java-help
Richardson Mapping With Spring Security
Hi, Im curious about, how to properly create mappings for security endpoints. I have now a UserController. So where would you like to put mappings like "login, register and verify email", to UserController or AuthController. And how would you like to create endpoints. I have only users. For example if we chose UserController -> "/api/v1/users" Is this good?
@PostMapping("/login")
public ResponseDto login(@RequestBody Command2 command) {
return service.login(command);
}

@PostMapping("/register")
@ResponseStatus(HttpStatus.CREATED)
public ResponseDto create(@RequestBody @Valid Command command) {
return service.register(command);
}

@GetMapping("/verify/{id}")
public ResponseDto verify(@PathVariable int id) {
return service.verify(token);
}
@PostMapping("/login")
public ResponseDto login(@RequestBody Command2 command) {
return service.login(command);
}

@PostMapping("/register")
@ResponseStatus(HttpStatus.CREATED)
public ResponseDto create(@RequestBody @Valid Command command) {
return service.register(command);
}

@GetMapping("/verify/{id}")
public ResponseDto verify(@PathVariable int id) {
return service.verify(token);
}
5 replies
JCHJava Community | Help. Code. Learn.
Created by lisan on 5/26/2024 in #java-help
Maturity level rest
Hi i have a question, do you think these mappings are properly defined for maturity level? I have a controller with authentication to create Clients. /api/v1/auth: register: @PostMapping("/register") + request body login: @PostMapping("/login") + headery email-verify (after registration to get authorized): @GetMapping("/verify/{token}") + path variable Maybe these mappings should be in client controller too?
4 replies