-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INTYGFV-16799: Add (back!) legacy launch controllers. Removed unneces…
…sary legacy code. (#1101)
- Loading branch information
1 parent
ba65e8b
commit 99676b8
Showing
11 changed files
with
431 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
.../intyg/webcert/web/web/controller/legacyintegration/CertificateIntegrationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (C) 2024 Inera AB (http://www.inera.se) | ||
* | ||
* This file is part of sklintyg (https://github.com/sklintyg). | ||
* | ||
* sklintyg is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* sklintyg is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package se.inera.intyg.webcert.web.web.controller.legacyintegration; | ||
|
||
import io.swagger.annotations.Api; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.MediaType; | ||
import se.inera.intyg.infra.security.common.model.UserOriginType; | ||
|
||
/** | ||
* Controller to enable a landsting user to access certificates directly from a link. | ||
* | ||
* This controller inherits from the FragaSvarUthoppController which manages | ||
* request for UTHOPP links. This inheritance is somewhat confusing but it make | ||
* sense if we look at it from a functional perspective. | ||
*/ | ||
// CHECKSTYLE:OFF LineLength | ||
@Path("/basic-certificate") | ||
@Api(value = "/webcert/web/user/basic-certificate", produces = MediaType.APPLICATION_JSON) | ||
public class CertificateIntegrationController extends FragaSvarUthoppController { | ||
// CHECKSTYLE:ON LineLength | ||
|
||
@Override | ||
protected UserOriginType getGrantedRequestOrigin() { | ||
return UserOriginType.NORMAL; | ||
} | ||
|
||
} |
160 changes: 160 additions & 0 deletions
160
...e/inera/intyg/webcert/web/web/controller/legacyintegration/FragaSvarUthoppController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/* | ||
* Copyright (C) 2024 Inera AB (http://www.inera.se) | ||
* | ||
* This file is part of sklintyg (https://github.com/sklintyg). | ||
* | ||
* sklintyg is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* sklintyg is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package se.inera.intyg.webcert.web.web.controller.legacyintegration; | ||
|
||
import com.google.common.base.Strings; | ||
import io.swagger.annotations.Api; | ||
import java.util.Arrays; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.Response.Status; | ||
import javax.ws.rs.core.UriInfo; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import se.inera.intyg.infra.monitoring.annotation.PrometheusTimeMethod; | ||
import se.inera.intyg.infra.security.authorities.CommonAuthoritiesResolver; | ||
import se.inera.intyg.infra.security.common.model.AuthoritiesConstants; | ||
import se.inera.intyg.infra.security.common.model.UserOriginType; | ||
import se.inera.intyg.webcert.common.service.exception.WebCertServiceErrorCodeEnum; | ||
import se.inera.intyg.webcert.common.service.exception.WebCertServiceException; | ||
import se.inera.intyg.webcert.web.service.intyg.IntygService; | ||
import se.inera.intyg.webcert.web.service.user.dto.WebCertUser; | ||
import se.inera.intyg.webcert.web.web.controller.facade.util.ReactUriFactory; | ||
import se.inera.intyg.webcert.web.web.controller.integration.BaseIntegrationController; | ||
|
||
/** | ||
* Controller to enable an external user to access certificates directly from a | ||
* link in an external patient care system. | ||
* | ||
* @author nikpet | ||
*/ | ||
// CHECKSTYLE:OFF LineLength | ||
@Path("/certificate") | ||
@Api(value = "webcert web user certificate (Fråga/Svar uthopp)", description = "REST API för fråga/svar via uthoppslänk, landstingspersonal", produces = MediaType.APPLICATION_JSON) | ||
public class FragaSvarUthoppController extends BaseIntegrationController { | ||
// CHECKSTYLE:ON LineLength | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(FragaSvarUthoppController.class); | ||
|
||
private static final String[] GRANTED_ROLES = new String[]{AuthoritiesConstants.ROLE_ADMIN, AuthoritiesConstants.ROLE_LAKARE, | ||
AuthoritiesConstants.ROLE_TANDLAKARE, AuthoritiesConstants.ROLE_SJUKSKOTERSKA, AuthoritiesConstants.ROLE_BARNMORSKA}; | ||
private static final UserOriginType GRANTED_ORIGIN = UserOriginType.NORMAL; | ||
|
||
@Autowired | ||
private IntygService intygService; | ||
|
||
@Autowired | ||
private ReactUriFactory reactUriFactory; | ||
|
||
@Autowired | ||
private CommonAuthoritiesResolver commonAuthoritiesResolver; | ||
|
||
/** | ||
* Fetches a certificate from IT and then performs a redirect to the view that displays | ||
* the certificate. Can be used for all types of certificates. | ||
* | ||
* @param intygId The id of the certificate to view. | ||
*/ | ||
@GET | ||
@Path("/{type}/{intygId}/questions") | ||
@PrometheusTimeMethod | ||
public Response redirectToIntyg(@Context UriInfo uriInfo, | ||
@PathParam("type") String type, | ||
@PathParam("intygId") String intygId, | ||
@QueryParam("enhet") String enhetHsaId) { | ||
|
||
super.validateParameter("type", type); | ||
super.validateParameter("intygId", intygId); | ||
super.validateAuthorities(); | ||
this.validateAndChangeEnhet(intygId, enhetHsaId); | ||
|
||
LOG.debug("Redirecting to view intyg {} of type {}", intygId, type); | ||
return buildRedirectResponse(uriInfo, intygId); | ||
} | ||
|
||
@GET | ||
@Path("/{intygId}/questions") | ||
@PrometheusTimeMethod | ||
public Response redirectToIntyg(@Context UriInfo uriInfo, | ||
@PathParam("intygId") String intygId, | ||
@QueryParam("enhet") String enhetHsaId) { | ||
|
||
super.validateParameter("intygId", intygId); | ||
super.validateAuthorities(); | ||
this.validateAndChangeEnhet(intygId, enhetHsaId); | ||
|
||
LOG.debug("Redirecting to view intyg {}", intygId); | ||
return buildRedirectResponse(uriInfo, intygId); | ||
} | ||
|
||
@Override | ||
protected String[] getGrantedRoles() { | ||
return GRANTED_ROLES; | ||
} | ||
|
||
@Override | ||
protected UserOriginType getGrantedRequestOrigin() { | ||
return GRANTED_ORIGIN; | ||
} | ||
|
||
/** | ||
* Makes sure we change (if possible) the current vardEnhet to the one either specified in the URL or to the one | ||
* the intyg was issued on. | ||
*/ | ||
private void validateAndChangeEnhet(String intygsId, String enhetHsaId) { | ||
WebCertUser user = webCertUserService.getUser(); | ||
if (user == null) { | ||
LOG.error("No user in session, cannot continue"); | ||
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, | ||
"No user session, cannot view questions for intyg " + intygsId); | ||
} | ||
|
||
if (!Strings.nullToEmpty(enhetHsaId).trim().isEmpty()) { | ||
// Link contained not empty ?enhet= query param, try to set on user! | ||
if (!user.changeValdVardenhet(enhetHsaId)) { | ||
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, | ||
"User does not have access to enhet " + enhetHsaId); | ||
} | ||
} else { | ||
// No enhet on link (legacy fallback for pre WC 5.0 links) | ||
String enhet = intygService.getIssuingVardenhetHsaId(intygsId, null); | ||
if (!user.changeValdVardenhet(enhet)) { | ||
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, | ||
"User does not have access to enhet " + enhetHsaId); | ||
} | ||
} | ||
|
||
user.setFeatures( | ||
commonAuthoritiesResolver.getFeatures( | ||
Arrays.asList(user.getValdVardenhet().getId(), user.getValdVardgivare().getId()) | ||
) | ||
); | ||
} | ||
|
||
private Response buildRedirectResponse(UriInfo uriInfo, String certificateId) { | ||
final var uri = reactUriFactory.uriForCertificate(uriInfo, certificateId); | ||
return Response.status(Status.SEE_OTHER).location(uri).build(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...rt/web/web/controller/legacyintegration/PrivatePractitionerFragaSvarUthoppController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (C) 2024 Inera AB (http://www.inera.se) | ||
* | ||
* This file is part of sklintyg (https://github.com/sklintyg). | ||
* | ||
* sklintyg is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* sklintyg is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package se.inera.intyg.webcert.web.web.controller.legacyintegration; | ||
|
||
import static se.inera.intyg.infra.security.common.model.AuthoritiesConstants.ROLE_PRIVATLAKARE; | ||
|
||
import io.swagger.annotations.Api; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.MediaType; | ||
import se.inera.intyg.infra.security.common.model.UserOriginType; | ||
|
||
/** | ||
* Created by eriklupander on 2015-10-08. | ||
*/ | ||
// CHECKSTYLE:OFF LineLength | ||
@Path("/pp-certificate") | ||
@Api(value = "webcert web user pp-certificate (Fråga/Svar, uthopp privatläkare)", description = "REST API för fråga/svar via uthoppslänk, privatläkare", produces = MediaType.APPLICATION_JSON) | ||
public class PrivatePractitionerFragaSvarUthoppController extends FragaSvarUthoppController { | ||
// CHECKSTYLE:ON LineLength | ||
|
||
@Override | ||
protected String[] getGrantedRoles() { | ||
return new String[]{ROLE_PRIVATLAKARE}; | ||
} | ||
|
||
@Override | ||
protected UserOriginType getGrantedRequestOrigin() { | ||
return UserOriginType.NORMAL; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.