@Test public void testRedirectToIntygUserHasAccess() { when(webCertUserService.getUser()).thenReturn(createMockUser(false)); when(intygService.getIssuingVardenhetHsaId(INTYG_ID, INTYG_TYP_FK7263)).thenReturn("ve-1"); when(mailLinkService.intygRedirect(INTYG_TYP_FK7263, INTYG_TYPE_VERSION, INTYG_ID)).thenReturn(buildMockURI()); ResponseEntity<Object> result = controller.redirectToIntyg(INTYG_ID, INTYG_TYP_FK7263); assertEquals(303, result.getStatusCode().value()); }
@RequestMapping(value = "/maillink/intyg/{typ}/{intygId}", method = RequestMethod.GET) @PrometheusTimeMethod public ResponseEntity<Object> redirectToIntyg(@PathVariable("intygId") String intygId, @PathVariable("typ") String typ) { String enhetHsaId = intygService.getIssuingVardenhetHsaId(intygId, typ); if (enhetHsaId == null) { LOG.error("Could not redirect user to utkast using /maillink for intygsId '" + intygId + "'. No enhetsId found for utkast. Does the utkast exist?"); return new ResponseEntity<>(HttpStatus.NOT_FOUND); } WebCertUser user = webCertUserService.getUser(); if (!user.changeValdVardenhet(enhetHsaId)) { HttpHeaders httpHeaders = new HttpHeaders(); URI uri = UriBuilder.fromPath("/error.jsp") .queryParam("reason", "enhet.auth.exception") .queryParam("enhetHsaId", enhetHsaId) .build(); httpHeaders.setLocation(uri); return new ResponseEntity<>(httpHeaders, HttpStatus.FOUND); } String intygTypeVersion = intygService.getIntygTypeInfo(intygId).getIntygTypeVersion(); URI uri = mailLinkService.intygRedirect(typ, intygTypeVersion, intygId); if (uri == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } else { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation(uri); return new ResponseEntity<>(httpHeaders, HttpStatus.SEE_OTHER); } }
PageController { @RequestMapping(value = "/maillink/intyg/{typ}/{intygId}", method = RequestMethod.GET) @PrometheusTimeMethod public ResponseEntity<Object> redirectToIntyg(@PathVariable("intygId") String intygId, @PathVariable("typ") String typ) { String enhetHsaId = intygService.getIssuingVardenhetHsaId(intygId, typ); if (enhetHsaId == null) { LOG.error("Could not redirect user to utkast using /maillink for intygsId '" + intygId + "'. No enhetsId found for utkast. Does the utkast exist?"); return new ResponseEntity<>(HttpStatus.NOT_FOUND); } WebCertUser user = webCertUserService.getUser(); if (!user.changeValdVardenhet(enhetHsaId)) { HttpHeaders httpHeaders = new HttpHeaders(); URI uri = UriBuilder.fromPath("/error.jsp") .queryParam("reason", "enhet.auth.exception") .queryParam("enhetHsaId", enhetHsaId) .build(); httpHeaders.setLocation(uri); return new ResponseEntity<>(httpHeaders, HttpStatus.FOUND); } String intygTypeVersion = intygService.getIntygTypeInfo(intygId).getIntygTypeVersion(); URI uri = mailLinkService.intygRedirect(typ, intygTypeVersion, intygId); if (uri == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } else { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation(uri); return new ResponseEntity<>(httpHeaders, HttpStatus.SEE_OTHER); } } }
PageController { @RequestMapping(value = "/maillink/intyg/{typ}/{intygId}", method = RequestMethod.GET) @PrometheusTimeMethod public ResponseEntity<Object> redirectToIntyg(@PathVariable("intygId") String intygId, @PathVariable("typ") String typ) { String enhetHsaId = intygService.getIssuingVardenhetHsaId(intygId, typ); if (enhetHsaId == null) { LOG.error("Could not redirect user to utkast using /maillink for intygsId '" + intygId + "'. No enhetsId found for utkast. Does the utkast exist?"); return new ResponseEntity<>(HttpStatus.NOT_FOUND); } WebCertUser user = webCertUserService.getUser(); if (!user.changeValdVardenhet(enhetHsaId)) { HttpHeaders httpHeaders = new HttpHeaders(); URI uri = UriBuilder.fromPath("/error.jsp") .queryParam("reason", "enhet.auth.exception") .queryParam("enhetHsaId", enhetHsaId) .build(); httpHeaders.setLocation(uri); return new ResponseEntity<>(httpHeaders, HttpStatus.FOUND); } String intygTypeVersion = intygService.getIntygTypeInfo(intygId).getIntygTypeVersion(); URI uri = mailLinkService.intygRedirect(typ, intygTypeVersion, intygId); if (uri == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } else { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation(uri); return new ResponseEntity<>(httpHeaders, HttpStatus.SEE_OTHER); } }  }
PageController { @RequestMapping(value = "/maillink/intyg/{typ}/{intygId}", method = RequestMethod.GET) @PrometheusTimeMethod public ResponseEntity<Object> redirectToIntyg(@PathVariable("intygId") String intygId, @PathVariable("typ") String typ) { String enhetHsaId = intygService.getIssuingVardenhetHsaId(intygId, typ); if (enhetHsaId == null) { LOG.error("Could not redirect user to utkast using /maillink for intygsId '" + intygId + "'. No enhetsId found for utkast. Does the utkast exist?"); return new ResponseEntity<>(HttpStatus.NOT_FOUND); } WebCertUser user = webCertUserService.getUser(); if (!user.changeValdVardenhet(enhetHsaId)) { HttpHeaders httpHeaders = new HttpHeaders(); URI uri = UriBuilder.fromPath("/error.jsp") .queryParam("reason", "enhet.auth.exception") .queryParam("enhetHsaId", enhetHsaId) .build(); httpHeaders.setLocation(uri); return new ResponseEntity<>(httpHeaders, HttpStatus.FOUND); } String intygTypeVersion = intygService.getIntygTypeInfo(intygId).getIntygTypeVersion(); URI uri = mailLinkService.intygRedirect(typ, intygTypeVersion, intygId); if (uri == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } else { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation(uri); return new ResponseEntity<>(httpHeaders, HttpStatus.SEE_OTHER); } }  @RequestMapping(value = "/maillink/intyg/{typ}/{intygId}", method = RequestMethod.GET) @PrometheusTimeMethod ResponseEntity<Object> redirectToIntyg(@PathVariable("intygId") String intygId, @PathVariable("typ") String typ); }
PageController { @RequestMapping(value = "/maillink/intyg/{typ}/{intygId}", method = RequestMethod.GET) @PrometheusTimeMethod public ResponseEntity<Object> redirectToIntyg(@PathVariable("intygId") String intygId, @PathVariable("typ") String typ) { String enhetHsaId = intygService.getIssuingVardenhetHsaId(intygId, typ); if (enhetHsaId == null) { LOG.error("Could not redirect user to utkast using /maillink for intygsId '" + intygId + "'. No enhetsId found for utkast. Does the utkast exist?"); return new ResponseEntity<>(HttpStatus.NOT_FOUND); } WebCertUser user = webCertUserService.getUser(); if (!user.changeValdVardenhet(enhetHsaId)) { HttpHeaders httpHeaders = new HttpHeaders(); URI uri = UriBuilder.fromPath("/error.jsp") .queryParam("reason", "enhet.auth.exception") .queryParam("enhetHsaId", enhetHsaId) .build(); httpHeaders.setLocation(uri); return new ResponseEntity<>(httpHeaders, HttpStatus.FOUND); } String intygTypeVersion = intygService.getIntygTypeInfo(intygId).getIntygTypeVersion(); URI uri = mailLinkService.intygRedirect(typ, intygTypeVersion, intygId); if (uri == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } else { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation(uri); return new ResponseEntity<>(httpHeaders, HttpStatus.SEE_OTHER); } }  @RequestMapping(value = "/maillink/intyg/{typ}/{intygId}", method = RequestMethod.GET) @PrometheusTimeMethod ResponseEntity<Object> redirectToIntyg(@PathVariable("intygId") String intygId, @PathVariable("typ") String typ);  }