Skip to content

Commit

Permalink
fix(identity-trust)!: disable spring security for identityMinusTrust …
Browse files Browse the repository at this point in the history
…endpoint

Signed-off-by: Dominik Pinsel <[email protected]>
  • Loading branch information
DominikPinsel committed Jul 25, 2024
1 parent 87e8a5d commit eb03abf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.security.web.util.matcher.NegatedRequestMatcher;
import org.springframework.security.web.util.matcher.OrRequestMatcher;

import java.util.List;

import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpMethod.POST;
Expand Down Expand Up @@ -116,6 +120,10 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers(new AntPathRequestMatcher("/error")).permitAll()
).oauth2ResourceServer(resourceServer -> resourceServer.jwt(jwt ->
jwt.jwtAuthenticationConverter(new CustomAuthenticationConverter(securityConfigProperties.clientId()))))
.securityMatcher(new NegatedRequestMatcher( new OrRequestMatcher(
List.of(
new AntPathRequestMatcher(RestURI.API_PRESENTATIONS_IATP),
new AntPathRequestMatcher(RestURI.API_PRESENTATIONS_IATP_WORKAROUND)))))
.addFilterAfter(new PresentationIatpFilter(validationService), BasicAuthenticationFilter.class);

return http.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ public static Optional<String> getAccessToken(JWTClaimsSet claims) {
}

public static SignedJWT getAccessToken(String outerToken) {

// in the history of tractus-x sometimes the header contains a bearer, sometimes not.
// as it is not possible to fix this wrong behavior over all applications
// we added this mitigation here (not good, we know..).
if (outerToken.startsWith("Bearer ")) {
outerToken = outerToken.substring("Bearer ".length());
}

SignedJWT jwtOuter = parseToken(outerToken);
JWTClaimsSet claimsSet = getClaimsSet(jwtOuter);
Optional<String> accessToken = getAccessToken(claimsSet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void testPresentationQueryWithToken() {
final Map<String, Object> data2 = MAPPER.readValue(message2, Map.class);

final HttpHeaders headers2 = new HttpHeaders();
headers2.set(HttpHeaders.AUTHORIZATION, jwt);
headers2.set(HttpHeaders.AUTHORIZATION, "Bearer " + jwt);
final HttpEntity<Map<String, Object>> entity2 = new HttpEntity<>(data2, headers2);
var result2 = restTemplate
.postForEntity(RestURI.API_PRESENTATIONS_IATP, entity2, String.class);
Expand Down

0 comments on commit eb03abf

Please sign in to comment.