@Test void auth() throws NoSuchFieldException { FieldSetter.setField(service, service.getClass().getDeclaredField("response"), new MockHttpServletResponse()); FieldSetter.setField(service, service.getClass().getDeclaredField("loginPage"), "www.loginPage.html"); when(referencePolicy.fromURL(anyString(), any(), anyString())).thenReturn(getConsentReference()); ResponseEntity<AuthorizeResponse> result = service.auth(AUTH_ID, ConsentType.AIS, ENCRYPTED_ID, response); assertEquals(getExpectedAuthResponse(), result); }
public ResponseEntity<AuthorizeResponse> auth(String redirectId, ConsentType consentType, String encryptedConsentId, HttpServletResponse response) { AuthorizeResponse authResponse = new AuthorizeResponse(); try { ConsentReference consentReference = referencePolicy.fromURL(redirectId, consentType, encryptedConsentId); authResponse.setEncryptedConsentId(encryptedConsentId); authResponse.setAuthorisationId(redirectId); String token = Optional.ofNullable(request.getHeader(HttpHeaders.AUTHORIZATION)) .filter(t -> StringUtils.startsWithIgnoreCase(t, BEARER_TOKEN_PREFIX)) .map(t -> StringUtils.substringAfter(t, BEARER_TOKEN_PREFIX)) .orElse(null); AccessTokenTO tokenTO = Optional.ofNullable(token).map(t -> userMgmtRestClient.validate(t).getBody()) .map(BearerTokenTO::getAccessTokenObject) .orElse(null); responseUtils.setCookies(response, consentReference, token, tokenTO); if (StringUtils.isNotBlank(token)) { response.addHeader(HttpHeaders.AUTHORIZATION, token); } } catch (InvalidConsentException e) { log.info(e.getMessage()); responseUtils.removeCookies(response); return responseUtils.unknownCredentials(authResponse, response); } String uriString = UriComponentsBuilder.fromUriString(loginPage) .queryParam("encryptedConsentId", authResponse.getEncryptedConsentId()) .queryParam("authorisationId", authResponse.getAuthorisationId()) .build().toUriString(); response.addHeader("Location", uriString); return ResponseEntity.ok(authResponse); }
XISControllerService { public ResponseEntity<AuthorizeResponse> auth(String redirectId, ConsentType consentType, String encryptedConsentId, HttpServletResponse response) { AuthorizeResponse authResponse = new AuthorizeResponse(); try { ConsentReference consentReference = referencePolicy.fromURL(redirectId, consentType, encryptedConsentId); authResponse.setEncryptedConsentId(encryptedConsentId); authResponse.setAuthorisationId(redirectId); String token = Optional.ofNullable(request.getHeader(HttpHeaders.AUTHORIZATION)) .filter(t -> StringUtils.startsWithIgnoreCase(t, BEARER_TOKEN_PREFIX)) .map(t -> StringUtils.substringAfter(t, BEARER_TOKEN_PREFIX)) .orElse(null); AccessTokenTO tokenTO = Optional.ofNullable(token).map(t -> userMgmtRestClient.validate(t).getBody()) .map(BearerTokenTO::getAccessTokenObject) .orElse(null); responseUtils.setCookies(response, consentReference, token, tokenTO); if (StringUtils.isNotBlank(token)) { response.addHeader(HttpHeaders.AUTHORIZATION, token); } } catch (InvalidConsentException e) { log.info(e.getMessage()); responseUtils.removeCookies(response); return responseUtils.unknownCredentials(authResponse, response); } String uriString = UriComponentsBuilder.fromUriString(loginPage) .queryParam("encryptedConsentId", authResponse.getEncryptedConsentId()) .queryParam("authorisationId", authResponse.getAuthorisationId()) .build().toUriString(); response.addHeader("Location", uriString); return ResponseEntity.ok(authResponse); } }
XISControllerService { public ResponseEntity<AuthorizeResponse> auth(String redirectId, ConsentType consentType, String encryptedConsentId, HttpServletResponse response) { AuthorizeResponse authResponse = new AuthorizeResponse(); try { ConsentReference consentReference = referencePolicy.fromURL(redirectId, consentType, encryptedConsentId); authResponse.setEncryptedConsentId(encryptedConsentId); authResponse.setAuthorisationId(redirectId); String token = Optional.ofNullable(request.getHeader(HttpHeaders.AUTHORIZATION)) .filter(t -> StringUtils.startsWithIgnoreCase(t, BEARER_TOKEN_PREFIX)) .map(t -> StringUtils.substringAfter(t, BEARER_TOKEN_PREFIX)) .orElse(null); AccessTokenTO tokenTO = Optional.ofNullable(token).map(t -> userMgmtRestClient.validate(t).getBody()) .map(BearerTokenTO::getAccessTokenObject) .orElse(null); responseUtils.setCookies(response, consentReference, token, tokenTO); if (StringUtils.isNotBlank(token)) { response.addHeader(HttpHeaders.AUTHORIZATION, token); } } catch (InvalidConsentException e) { log.info(e.getMessage()); responseUtils.removeCookies(response); return responseUtils.unknownCredentials(authResponse, response); } String uriString = UriComponentsBuilder.fromUriString(loginPage) .queryParam("encryptedConsentId", authResponse.getEncryptedConsentId()) .queryParam("authorisationId", authResponse.getAuthorisationId()) .build().toUriString(); response.addHeader("Location", uriString); return ResponseEntity.ok(authResponse); }  }
XISControllerService { public ResponseEntity<AuthorizeResponse> auth(String redirectId, ConsentType consentType, String encryptedConsentId, HttpServletResponse response) { AuthorizeResponse authResponse = new AuthorizeResponse(); try { ConsentReference consentReference = referencePolicy.fromURL(redirectId, consentType, encryptedConsentId); authResponse.setEncryptedConsentId(encryptedConsentId); authResponse.setAuthorisationId(redirectId); String token = Optional.ofNullable(request.getHeader(HttpHeaders.AUTHORIZATION)) .filter(t -> StringUtils.startsWithIgnoreCase(t, BEARER_TOKEN_PREFIX)) .map(t -> StringUtils.substringAfter(t, BEARER_TOKEN_PREFIX)) .orElse(null); AccessTokenTO tokenTO = Optional.ofNullable(token).map(t -> userMgmtRestClient.validate(t).getBody()) .map(BearerTokenTO::getAccessTokenObject) .orElse(null); responseUtils.setCookies(response, consentReference, token, tokenTO); if (StringUtils.isNotBlank(token)) { response.addHeader(HttpHeaders.AUTHORIZATION, token); } } catch (InvalidConsentException e) { log.info(e.getMessage()); responseUtils.removeCookies(response); return responseUtils.unknownCredentials(authResponse, response); } String uriString = UriComponentsBuilder.fromUriString(loginPage) .queryParam("encryptedConsentId", authResponse.getEncryptedConsentId()) .queryParam("authorisationId", authResponse.getAuthorisationId()) .build().toUriString(); response.addHeader("Location", uriString); return ResponseEntity.ok(authResponse); }  ResponseEntity<AuthorizeResponse> auth(String redirectId, ConsentType consentType, String encryptedConsentId, HttpServletResponse response); ResponseEntity<SCALoginResponseTO> performLoginForConsent(String login, String pin, String operationId, String authId, OpTypeTO operationType); ResponseEntity<PaymentAuthorizeResponse> resolvePaymentWorkflow(PaymentWorkflow workflow); }
XISControllerService { public ResponseEntity<AuthorizeResponse> auth(String redirectId, ConsentType consentType, String encryptedConsentId, HttpServletResponse response) { AuthorizeResponse authResponse = new AuthorizeResponse(); try { ConsentReference consentReference = referencePolicy.fromURL(redirectId, consentType, encryptedConsentId); authResponse.setEncryptedConsentId(encryptedConsentId); authResponse.setAuthorisationId(redirectId); String token = Optional.ofNullable(request.getHeader(HttpHeaders.AUTHORIZATION)) .filter(t -> StringUtils.startsWithIgnoreCase(t, BEARER_TOKEN_PREFIX)) .map(t -> StringUtils.substringAfter(t, BEARER_TOKEN_PREFIX)) .orElse(null); AccessTokenTO tokenTO = Optional.ofNullable(token).map(t -> userMgmtRestClient.validate(t).getBody()) .map(BearerTokenTO::getAccessTokenObject) .orElse(null); responseUtils.setCookies(response, consentReference, token, tokenTO); if (StringUtils.isNotBlank(token)) { response.addHeader(HttpHeaders.AUTHORIZATION, token); } } catch (InvalidConsentException e) { log.info(e.getMessage()); responseUtils.removeCookies(response); return responseUtils.unknownCredentials(authResponse, response); } String uriString = UriComponentsBuilder.fromUriString(loginPage) .queryParam("encryptedConsentId", authResponse.getEncryptedConsentId()) .queryParam("authorisationId", authResponse.getAuthorisationId()) .build().toUriString(); response.addHeader("Location", uriString); return ResponseEntity.ok(authResponse); }  ResponseEntity<AuthorizeResponse> auth(String redirectId, ConsentType consentType, String encryptedConsentId, HttpServletResponse response); ResponseEntity<SCALoginResponseTO> performLoginForConsent(String login, String pin, String operationId, String authId, OpTypeTO operationType); ResponseEntity<PaymentAuthorizeResponse> resolvePaymentWorkflow(PaymentWorkflow workflow);  }