Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skille Autentisering og Autorisering/Abac #1353

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions felles/auth-filter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
<groupId>no.nav.foreldrepenger.felles</groupId>
<artifactId>felles-oidc</artifactId>
</dependency>
<dependency>
<groupId>no.nav.foreldrepenger.felles</groupId>
<artifactId>felles-abac</artifactId>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import jakarta.ws.rs.core.Response;
import no.nav.vedtak.exception.TekniskException;
import no.nav.vedtak.log.mdc.MDCOperations;
import no.nav.vedtak.sikkerhet.abac.BeskyttetRessurs;
import no.nav.vedtak.sikkerhet.abac.ÅpenRessurs;
import no.nav.vedtak.sikkerhet.kontekst.BasisKontekst;
import no.nav.vedtak.sikkerhet.kontekst.KontekstHolder;
import no.nav.vedtak.sikkerhet.kontekst.RequestKontekst;
Expand Down Expand Up @@ -54,8 +52,7 @@ public static void validerSettKontekst(ResourceInfo resourceInfo, ContainerReque
public static void validerSettKontekst(ResourceInfo resourceInfo, ContainerRequestContext ctx, String cookiePath) {
try {
Method method = resourceInfo.getResourceMethod();
var beskyttetRessurs = method.getAnnotation(BeskyttetRessurs.class);
var åpenRessurs = method.getAnnotation(ÅpenRessurs.class);
var utenAutentiseringRessurs = method.getAnnotation(UtenAutentisering.class);
var metodenavn = method.getName();
if (KontekstHolder.harKontekst()) {
LOG.info("Kall til {} hadde kontekst {}", metodenavn, KontekstHolder.getKontekst().getKompaktUid());
Expand All @@ -64,11 +61,10 @@ public static void validerSettKontekst(ResourceInfo resourceInfo, ContainerReque
MDC.clear();
setCallAndConsumerId(ctx);
LOG.trace("{} i klasse {}", metodenavn, method.getDeclaringClass());
if (beskyttetRessurs == null && (åpenRessurs != null || method.getDeclaringClass().getName().startsWith("io.swagger"))) {
// Kan vurdere å unnta metodenavn = getOpenApi og getDeclaringClass startsWith io.swagger + endsWith OpenApiResource
if (utenAutentiseringRessurs != null ) {
KontekstHolder.setKontekst(BasisKontekst.ikkeAutentisertRequest(MDCOperations.getConsumerId()));
LOG.trace("{} er whitelisted", metodenavn);
} else if (beskyttetRessurs == null) {
throw new WebApplicationException(metodenavn + " mangler annotering", Response.Status.INTERNAL_SERVER_ERROR);
} else {
var tokenString = getToken(ctx, cookiePath)
.orElseThrow(() -> new ValideringsFeil("Mangler token"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package no.nav.vedtak.sikkerhet.jaxrs;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import jakarta.ws.rs.NameBinding;

/*
* Primært for endepunkt som kalles av plattformen (liveness, prestop, ...)
* Kan vurdere å legge til TYPE ved behov for å annotere hele interface eller klasser
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
@NameBinding
public @interface UtenAutentisering {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.container.ResourceInfo;
import no.nav.vedtak.sikkerhet.abac.BeskyttetRessurs;
import no.nav.vedtak.sikkerhet.abac.ÅpenRessurs;
import no.nav.vedtak.sikkerhet.kontekst.IdentType;
import no.nav.vedtak.sikkerhet.kontekst.KontekstHolder;
import no.nav.vedtak.sikkerhet.kontekst.SikkerhetContext;
Expand Down Expand Up @@ -180,22 +178,21 @@ private static TokenString getGyldigToken() {
@Path("foo")
static class RestClass {

@ÅpenRessurs
@UtenAutentisering
@Path("ubeskyttet")
public void ubeskyttet() {
}

@BeskyttetRessurs()
@Path("beskyttet")
public void beskyttet() {
}

}

private class TestInvocationContext implements ResourceInfo {
private static class TestInvocationContext implements ResourceInfo {

private Method method;
private Class<?> resourceClass;
private final Method method;
private final Class<?> resourceClass;

TestInvocationContext(Method method, Class<?> resourceClass) {
this.method = method;
Expand Down
5 changes: 0 additions & 5 deletions integrasjon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@
<artifactId>felles-oidc</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>no.nav.foreldrepenger.felles.sikkerhet</groupId>
<artifactId>felles-sikkerhet</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>no.nav.foreldrepenger.felles</groupId>
<artifactId>felles-klient</artifactId>
Expand Down