-
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.
Flytter Jackson mapper til felles-mapper, abac til felles-abac, ny im… (
#761) * Flytter Jackson mapper til felles-mapper, abac til felles-abac, ny implementasjon av pdp med jersey.
- Loading branch information
Showing
130 changed files
with
3,505 additions
and
2,226 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>felles</artifactId> | ||
<groupId>no.nav.foreldrepenger.felles</groupId> | ||
<version>3.0.83-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>felles-abac</artifactId> | ||
<name>Felles :: ABAC</name> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>no.nav.foreldrepenger.felles</groupId> | ||
<artifactId>felles-feil</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>no.nav.foreldrepenger.felles</groupId> | ||
<artifactId>felles-log</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>no.nav.foreldrepenger.felles</groupId> | ||
<artifactId>felles-mapper</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.nimbusds</groupId> | ||
<artifactId>oauth2-oidc-sdk</artifactId> | ||
<version>9.3.3</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>net.minidev</groupId> | ||
<artifactId>json-smart</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.minidev</groupId> | ||
<artifactId>json-smart</artifactId> | ||
<version>2.4.2</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.ow2.asm</groupId> | ||
<artifactId>asm</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.interceptor</groupId> | ||
<artifactId>jakarta.interceptor-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<!-- kun for Xacml - kan erstattes ved å bytte JsonUtil til Jackson ObjectMapper --> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-json-p-provider</artifactId> | ||
<version>${resteasy.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>no.nav.foreldrepenger.felles.integrasjon</groupId> | ||
<artifactId>felles-integrasjon-rest-klient</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
7 changes: 7 additions & 0 deletions
7
felles/abac/src/main/java/no/nav/foreldrepenger/sikkerhet/abac/AbacDto.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,7 @@ | ||
package no.nav.foreldrepenger.sikkerhet.abac; | ||
|
||
import no.nav.foreldrepenger.sikkerhet.abac.domene.AbacDataAttributter; | ||
|
||
public interface AbacDto { | ||
AbacDataAttributter abacAttributter(); | ||
} |
6 changes: 4 additions & 2 deletions
6
...ikkerhet/abac/TilpassetAbacAttributt.java → ...enger/sikkerhet/abac/AbacDtoSupplier.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
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
135 changes: 135 additions & 0 deletions
135
.../abac/src/main/java/no/nav/foreldrepenger/sikkerhet/abac/BeskyttetRessursInterceptor.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,135 @@ | ||
package no.nav.foreldrepenger.sikkerhet.abac; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.Collection; | ||
|
||
import javax.annotation.Priority; | ||
import javax.enterprise.context.Dependent; | ||
import javax.inject.Inject; | ||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
|
||
import no.nav.foreldrepenger.sikkerhet.abac.auditlog.AbacAuditlogger; | ||
import no.nav.foreldrepenger.sikkerhet.abac.domene.AbacResultat; | ||
import no.nav.foreldrepenger.sikkerhet.abac.domene.ActionType; | ||
import no.nav.foreldrepenger.sikkerhet.abac.domene.BeskyttRessursAttributer; | ||
import no.nav.foreldrepenger.sikkerhet.abac.domene.Tilgangsbeslutning; | ||
import no.nav.foreldrepenger.sikkerhet.abac.pep.Pep; | ||
import no.nav.foreldrepenger.sikkerhet.abac.pep.PepNektetTilgangException; | ||
import no.nav.vedtak.exception.TekniskException; | ||
import no.nav.vedtak.util.env.Environment; | ||
|
||
|
||
@BeskyttetRessurs(action = ActionType.DUMMY, path = "") | ||
@Interceptor | ||
@Priority(Interceptor.Priority.APPLICATION + 11) | ||
@Dependent | ||
public class BeskyttetRessursInterceptor { | ||
|
||
private static final Environment ENV = Environment.current(); | ||
|
||
private final Pep pep; | ||
private final AbacAuditlogger abacAuditlogger; | ||
|
||
@Inject | ||
public BeskyttetRessursInterceptor(Pep pep, AbacAuditlogger abacAuditlogger) { | ||
this.pep = pep; | ||
this.abacAuditlogger = abacAuditlogger; | ||
} | ||
|
||
@AroundInvoke | ||
public Object wrapTransaction(final InvocationContext invocationContext) throws Exception { | ||
var attributter = hentAttributter(invocationContext); | ||
var beslutning = pep.vurderTilgang(attributter); | ||
if (beslutning.fikkTilgang()) { | ||
return proceed(invocationContext, attributter, beslutning); | ||
} | ||
return ikkeTilgang(attributter, beslutning); | ||
} | ||
|
||
private BeskyttRessursAttributer hentAttributter(InvocationContext invocationContext) { | ||
var method = invocationContext.getMethod(); | ||
var beskyttetRessurs = method.getAnnotation(BeskyttetRessurs.class); | ||
|
||
var attributter = new BeskyttRessursAttributer() | ||
.setServiceType(beskyttetRessurs.service()) | ||
.setActionType(beskyttetRessurs.action()) | ||
.setRequestPath(beskyttetRessurs.path()); | ||
|
||
if (!beskyttetRessurs.property().isEmpty()) { | ||
var resource = ENV.getProperty(beskyttetRessurs.property()); | ||
attributter.setResource(resource); | ||
} else if (!beskyttetRessurs.resource().isEmpty()) { | ||
attributter.setResource(beskyttetRessurs.resource()); | ||
} | ||
|
||
// Legg på alle attributer fra AbacDtoer og AbacDtoSupplier | ||
var parameterDecl = method.getParameters(); | ||
for (int i = 0; i < method.getParameterCount(); i++) { | ||
Object parameterValue = invocationContext.getParameters()[i]; | ||
AbacDtoSupplier supplierAnnoterign = parameterDecl[i].getAnnotation(AbacDtoSupplier.class); | ||
leggTilAttributterFraParameter(attributter, parameterValue, supplierAnnoterign); | ||
} | ||
return attributter; | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
static void leggTilAttributterFraParameter(BeskyttRessursAttributer attributter, Object parameterValue, AbacDtoSupplier supplierAnnotering) { | ||
if (supplierAnnotering != null) { | ||
leggTil(attributter, supplierAnnotering, parameterValue); | ||
} else { | ||
if (parameterValue instanceof AbacDto) { // NOSONAR for å støtte både enkelt-DTO-er og collection av DTO-er | ||
attributter.leggTil(((AbacDto) parameterValue).abacAttributter()); | ||
} else if (parameterValue instanceof Collection) { // NOSONAR for å støtte både enkelt-DTO-er og collection av DTO-er | ||
leggTilAbacDtoSamling(attributter, (Collection) parameterValue); | ||
} | ||
} | ||
} | ||
|
||
private static void leggTilAbacDtoSamling(BeskyttRessursAttributer attributter, Collection<?> parameterValue) { | ||
for (Object value : parameterValue) { | ||
if (value instanceof AbacDto) { | ||
attributter.leggTil(((AbacDto) value).abacAttributter()); | ||
} else { | ||
throw new TekniskException("F-261962", | ||
String.format("Ugyldig input forventet at samling inneholdt bare AbacDto-er, men fant %s", | ||
value != null ? value.getClass().getName() : "null")); | ||
} | ||
} | ||
} | ||
|
||
private static void leggTil(BeskyttRessursAttributer attributter, AbacDtoSupplier abacDtoSupplier, Object verdi) { | ||
try { | ||
var dataAttributter = abacDtoSupplier.supplierClass().getDeclaredConstructor().newInstance().apply(verdi); | ||
attributter.leggTil(dataAttributter); | ||
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException e) { | ||
throw new IllegalStateException(e); | ||
} catch (InvocationTargetException e) { | ||
throw new IllegalStateException(e.getCause()); | ||
} | ||
} | ||
|
||
private Object proceed(InvocationContext invocationContext, BeskyttRessursAttributer attributter, Tilgangsbeslutning beslutning) throws Exception { | ||
Method method = invocationContext.getMethod(); | ||
boolean auditlogges = method.getAnnotation(BeskyttetRessurs.class).sporingslogg(); | ||
if (auditlogges) { | ||
abacAuditlogger.loggTilgang(beslutning.getPdpRequest(), attributter); | ||
return invocationContext.proceed(); | ||
} | ||
return invocationContext.proceed(); | ||
} | ||
|
||
private Object ikkeTilgang(BeskyttRessursAttributer attributter, Tilgangsbeslutning beslutning) { | ||
abacAuditlogger.loggDeny(beslutning.getPdpRequest(), attributter); | ||
|
||
switch (beslutning.getBeslutningKode()) { | ||
case AVSLÅTT_KODE_6: throw new PepNektetTilgangException("F-709170", "Tilgangskontroll.Avslag.Kode6"); | ||
case AVSLÅTT_KODE_7: throw new PepNektetTilgangException("F-027901", "Tilgangskontroll.Avslag.Kode7"); | ||
case AVSLÅTT_EGEN_ANSATT: throw new PepNektetTilgangException("F-788257", "Tilgangskontroll.Avslag.EgenAnsatt"); | ||
default: throw new PepNektetTilgangException("F-608625", "Ikke tilgang"); | ||
} | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
felles/abac/src/main/java/no/nav/foreldrepenger/sikkerhet/abac/PdpRequestBuilder.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,8 @@ | ||
package no.nav.foreldrepenger.sikkerhet.abac; | ||
|
||
import no.nav.foreldrepenger.sikkerhet.abac.domene.BeskyttRessursAttributer; | ||
import no.nav.foreldrepenger.sikkerhet.abac.pep.PdpRequest; | ||
|
||
public interface PdpRequestBuilder { | ||
PdpRequest lagPdpRequest(BeskyttRessursAttributer attributter); | ||
} |
Oops, something went wrong.