I have a Program, that has a UI and in the background talks to a AWS Database and sends Get and Put Request to an Endpoint. This Endpoint is protected by AWS Cognito and OAuth2. There are credentials for the program set up, so everything that has to do with OAuth2 is only Server Server Communication. I implemented this through a Spring reactive webClient. The problem now is, that Vaadin detects, that Spring Security is present and because of that redirects to the default Spring login page, which is not, what I want, since the user should never interact with OAuth2 in this case.
I already tryed to set Spring Security Configuration as follows:
public class SecurityConfiguration {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.formLogin().disable();
return http.build();
}
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring().antMatchers("/");
}
}
When I use the upper bean by itself, I get an error, that I am not allowed to access the web page. Then I have the lower one added as well though, I get an error, that I am not authorized to send the Request to the endpoint, because Spring apparently does not send the OAuth2 key with it then.
So where do I have to add Configuration now to tell Vaadin and Spring Security, that the UI has nothing to do with the OAuth2 Authentication and that the OAuth2 Authentication is only Server to Server?
Relevant Classes:
@Configuration
public class SecurityConfiguration {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.formLogin().disable();
return http.build();
}
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring().antMatchers("/");
}
}
Relevant Properties:
spring.security.oauth2.client.registration.aws.client-id= client ID
spring.security.oauth2.client.registration.aws.client-secret= client Secret
spring.security.oauth2.client.registration.aws.authorization-grant-type=client_credentials
spring.security.oauth2.client.registration.aws.scope= scope
spring.security.oauth2.client.provider.aws.token-uri= uri
And the connector I use in the end to actually call the endpoint:
public class Connector{
private List<Person> listOfFetchedData = Collections.synchronizedList(new ArrayList<>());
private final WebClient webClient;
private Mono<Person> sendRequestCore(String searchString)
{
return webClient.get()
.uri("BaseUri" + searchString)
.retrieve()
.bodyToMono(Person.class);
}
public Person sendRequestForEntryAndWaitForResult(String searchString) {
return sendRequestCore(searchString).block();
}
public void sendRequestForEntryAndWriteIntoList(String searchString) {
sendRequestCore(searchString).subscribe(result -> listOfFetchedData.add(result));
}
public void flushListOfFetchedData()
{
listOfFetchedData.clear();
}
public void deleteEntryFromList(Person person)
{listOfFetchedData.remove(person);}
}