|
41 | 41 | import org.springframework.security.web.util.matcher.RequestMatcher; |
42 | 42 | import org.springframework.web.filter.OncePerRequestFilter; |
43 | 43 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder; |
| 44 | +import org.springframework.web.util.UriComponentsBuilder; |
44 | 45 |
|
45 | 46 | import java.io.IOException; |
46 | 47 | import java.nio.charset.StandardCharsets; |
47 | 48 | import java.util.Base64; |
48 | 49 |
|
49 | 50 | public final class WebEidMobileAuthInitFilter extends OncePerRequestFilter { |
| 51 | + private static final String WEB_EID_MOBILE_AUTH_PATH = "auth"; |
50 | 52 | private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); |
51 | 53 | private final RequestMatcher requestMatcher; |
52 | 54 | private final ChallengeNonceGenerator nonceGenerator; |
@@ -79,10 +81,20 @@ protected void doFilterInternal(@NonNull HttpServletRequest request, |
79 | 81 | webEidMobileProperties.requestSigningCert() ? Boolean.TRUE : null) |
80 | 82 | ); |
81 | 83 | String encoded = Base64.getEncoder().encodeToString(payloadJson.getBytes(StandardCharsets.UTF_8)); |
82 | | - String eidAuthUri = "web-eid-mobile://auth#" + encoded; |
| 84 | + String authUri = getAuthUri(encoded); |
83 | 85 |
|
84 | 86 | response.setContentType(MediaType.APPLICATION_JSON_VALUE); |
85 | | - OBJECT_WRITER.writeValue(response.getWriter(), new AuthUri(eidAuthUri)); |
| 87 | + OBJECT_WRITER.writeValue(response.getWriter(), new AuthUri(authUri)); |
| 88 | + } |
| 89 | + |
| 90 | + private String getAuthUri(String encodedPayload) { |
| 91 | + UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(webEidMobileProperties.baseRequestUri()); |
| 92 | + if (webEidMobileProperties.baseRequestUri().startsWith("http")) { |
| 93 | + builder.pathSegment(WEB_EID_MOBILE_AUTH_PATH); |
| 94 | + } else { |
| 95 | + builder.host(WEB_EID_MOBILE_AUTH_PATH); |
| 96 | + } |
| 97 | + return builder.fragment(encodedPayload).toUriString(); |
86 | 98 | } |
87 | 99 |
|
88 | 100 | @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) |
|
0 commit comments