-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for checking user access to specific Altinn resources
#deploy-altinn3-tilgang-service #deploy-altinn3-tilgang-service-prod Introduced functionality to verify if a user has access to a specific Altinn resource (e.g., Dolly) via a newly added API endpoint. Refactored existing Altinn-related services, renamed classes for clarity, and integrated the new "authorized parties" API. Updated configurations and added new DTOs and services to support the changes.
- Loading branch information
Showing
17 changed files
with
189 additions
and
35 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
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
39 changes: 39 additions & 0 deletions
39
...av/testnav/altinn3tilgangservice/consumer/altinn/command/GetAuthorizedPartiesCommand.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,39 @@ | ||
package no.nav.testnav.altinn3tilgangservice.consumer.altinn.command; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import no.nav.testnav.altinn3tilgangservice.consumer.altinn.dto.AltinnAuthorizedPartiesRequestDTO; | ||
import no.nav.testnav.altinn3tilgangservice.consumer.altinn.dto.AuthorizedPartyDTO; | ||
import no.nav.testnav.libs.reactivecore.utils.WebClientFilter; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.core.publisher.Flux; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class GetAuthorizedPartiesCommand implements Callable<Flux<AuthorizedPartyDTO>> { | ||
|
||
private static final String ALTINN_URL = "/resourceregistry/accessmanagement/api/v1/resourceowner/authorizedparties"; | ||
|
||
private final WebClient webClient; | ||
private final AltinnAuthorizedPartiesRequestDTO request; | ||
private final String token; | ||
|
||
@Override | ||
public Flux<AuthorizedPartyDTO> call() { | ||
|
||
log.info("Spøøring om bruker {}", request); | ||
return webClient | ||
.post() | ||
.uri(builder -> builder.path(ALTINN_URL).build()) | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + token) | ||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) | ||
.bodyValue(request) | ||
.retrieve() | ||
.bodyToFlux(AuthorizedPartyDTO.class) | ||
.doOnError(WebClientFilter::logErrorMessage); | ||
} | ||
} |
Empty file.
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
18 changes: 18 additions & 0 deletions
18
.../testnav/altinn3tilgangservice/consumer/altinn/dto/AltinnAuthorizedPartiesRequestDTO.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,18 @@ | ||
package no.nav.testnav.altinn3tilgangservice.consumer.altinn.dto; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class AltinnAuthorizedPartiesRequestDTO { | ||
|
||
private static final String IDENT_IDENTIFIKATOR = "urn:altinn:person:identifier-no"; | ||
|
||
private String type; | ||
private String value; | ||
|
||
public AltinnAuthorizedPartiesRequestDTO(String ident) { | ||
|
||
this.type = IDENT_IDENTIFIKATOR; | ||
this.value = ident; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ain/java/no/nav/testnav/altinn3tilgangservice/consumer/altinn/dto/AuthorizedPartyDTO.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,20 @@ | ||
package no.nav.testnav.altinn3tilgangservice.consumer.altinn.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class AuthorizedPartyDTO { | ||
|
||
private String personId; | ||
private String organizationNumber; | ||
private List<String> authorizedResources; | ||
} | ||
|
14 changes: 14 additions & 0 deletions
14
...gang-service/src/main/java/no/nav/testnav/altinn3tilgangservice/domain/PersonRequest.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,14 @@ | ||
package no.nav.testnav.altinn3tilgangservice.domain; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class PersonRequest { | ||
|
||
private String ident; | ||
private String orgnummer; | ||
} |
24 changes: 24 additions & 0 deletions
24
...ain/java/no/nav/testnav/altinn3tilgangservice/provider/AltinnBrukerTilgangController.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,24 @@ | ||
package no.nav.testnav.altinn3tilgangservice.provider; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import no.nav.testnav.altinn3tilgangservice.domain.PersonRequest; | ||
import no.nav.testnav.altinn3tilgangservice.service.AltinnBrukerTilgangService; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import reactor.core.publisher.Mono; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/brukertilgang") | ||
@RequiredArgsConstructor | ||
public class AltinnBrukerTilgangController { | ||
|
||
private final AltinnBrukerTilgangService brukerTilgangService; | ||
|
||
@PostMapping | ||
public Mono<Boolean> harDollyTilgang(@RequestBody PersonRequest personRequest) { | ||
|
||
return brukerTilgangService.harDollyTilgang(personRequest); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
...rc/main/java/no/nav/testnav/altinn3tilgangservice/service/AltinnBrukerTilgangService.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,25 @@ | ||
package no.nav.testnav.altinn3tilgangservice.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import no.nav.testnav.altinn3tilgangservice.consumer.altinn.AltinnConsumer; | ||
import no.nav.testnav.altinn3tilgangservice.domain.PersonRequest; | ||
import org.springframework.stereotype.Service; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class AltinnBrukerTilgangService { | ||
|
||
private final AltinnConsumer altinnConsumer; | ||
|
||
public Mono<Boolean> harDollyTilgang(PersonRequest personRequest) { | ||
|
||
return altinnConsumer.getAuthorizedParties(personRequest.getIdent()) | ||
.doOnNext(party -> log.info("AuthorizedParty {}", party)) | ||
.filter(party -> party.getOrganizationNumber().equals(personRequest.getOrgnummer())) | ||
.filter(part -> part.getAuthorizedResources().contains("dolly")) | ||
.reduce(Boolean.FALSE, (a, b) -> Boolean.TRUE); | ||
} | ||
} |
Oops, something went wrong.