@Test public void assertIsAuthorizedOK() { WebCertUser webCertUser = createDefaultUser(AuthoritiesConstants.PRIVILEGE_SIGNERA_INTYG); doReturn(webCertUser) .when(webCertUserService).getUser(); doReturn(SekretessStatus.FALSE) .when(patientDetailsResolver).getSekretessStatus(any(Personnummer.class)); authorityAsserter.assertIsAuthorized( Personnummer.createPersonnummer("191212121212").get(), AuthoritiesConstants.PRIVILEGE_SIGNERA_INTYG); }
@Override public void assertIsAuthorized(final Personnummer personnummer, final String authority) { final WebCertUser user = webCertUserService.getUser(); authoritiesValidator.given(user) .privilege(authority) .orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, AUTH_MSG)); final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(personnummer); if (sekretessStatus == SekretessStatus.UNDEFINED) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, PU_MSG); } if (sekretessStatus == SekretessStatus.TRUE) { authoritiesValidator.given(user) .privilege(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT) .orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, AUTH_MSG)); } }
WcAuthorityAsserter implements AuthorityAsserter { @Override public void assertIsAuthorized(final Personnummer personnummer, final String authority) { final WebCertUser user = webCertUserService.getUser(); authoritiesValidator.given(user) .privilege(authority) .orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, AUTH_MSG)); final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(personnummer); if (sekretessStatus == SekretessStatus.UNDEFINED) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, PU_MSG); } if (sekretessStatus == SekretessStatus.TRUE) { authoritiesValidator.given(user) .privilege(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT) .orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, AUTH_MSG)); } } }
WcAuthorityAsserter implements AuthorityAsserter { @Override public void assertIsAuthorized(final Personnummer personnummer, final String authority) { final WebCertUser user = webCertUserService.getUser(); authoritiesValidator.given(user) .privilege(authority) .orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, AUTH_MSG)); final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(personnummer); if (sekretessStatus == SekretessStatus.UNDEFINED) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, PU_MSG); } if (sekretessStatus == SekretessStatus.TRUE) { authoritiesValidator.given(user) .privilege(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT) .orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, AUTH_MSG)); } } WcAuthorityAsserter(final WebCertUserService webCertUserService, final PatientDetailsResolver patientDetailsResolver); }
WcAuthorityAsserter implements AuthorityAsserter { @Override public void assertIsAuthorized(final Personnummer personnummer, final String authority) { final WebCertUser user = webCertUserService.getUser(); authoritiesValidator.given(user) .privilege(authority) .orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, AUTH_MSG)); final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(personnummer); if (sekretessStatus == SekretessStatus.UNDEFINED) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, PU_MSG); } if (sekretessStatus == SekretessStatus.TRUE) { authoritiesValidator.given(user) .privilege(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT) .orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, AUTH_MSG)); } } WcAuthorityAsserter(final WebCertUserService webCertUserService, final PatientDetailsResolver patientDetailsResolver); @Override void assertIsAuthorized(final Personnummer personnummer, final String authority); }
WcAuthorityAsserter implements AuthorityAsserter { @Override public void assertIsAuthorized(final Personnummer personnummer, final String authority) { final WebCertUser user = webCertUserService.getUser(); authoritiesValidator.given(user) .privilege(authority) .orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, AUTH_MSG)); final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(personnummer); if (sekretessStatus == SekretessStatus.UNDEFINED) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, PU_MSG); } if (sekretessStatus == SekretessStatus.TRUE) { authoritiesValidator.given(user) .privilege(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT) .orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, AUTH_MSG)); } } WcAuthorityAsserter(final WebCertUserService webCertUserService, final PatientDetailsResolver patientDetailsResolver); @Override void assertIsAuthorized(final Personnummer personnummer, final String authority);  }