Skip to content

Commit

Permalink
Abac med Azure Jwt støtte. (#1174)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsladek authored Sep 9, 2022
1 parent 7163a5c commit 043b0ad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
15 changes: 12 additions & 3 deletions felles/abac/src/main/java/no/nav/vedtak/sikkerhet/abac/Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class Token {

public enum TokenType {
OIDC,
AZURE_JWT,
TOKENX,
SAML;
}
Expand All @@ -28,8 +29,7 @@ private Token(String token, TokenType tokenType, OpenIDToken openIDToken) {
}

public static Token withOidcToken(OpenIDToken token) {
var tokenType = OpenIDProvider.TOKENX.equals(token.provider()) ? TokenType.TOKENX : TokenType.OIDC;
return new Token(null, tokenType, token);
return new Token(null, utledTokenType(token), token);
}

public static Token withSamlToken(String token) {
Expand All @@ -40,9 +40,18 @@ public TokenType getTokenType() {
return tokenType;
}

private static TokenType utledTokenType(OpenIDToken token) {
return switch (token.provider()) {
case AZUREAD -> TokenType.AZURE_JWT;
case ISSO, STS -> TokenType.OIDC;
case TOKENX -> TokenType.TOKENX;
case IDPORTEN -> throw new IllegalStateException("IdPorten token støttes ikke.");
};
}

public String getTokenBody() {
return switch (tokenType) {
case OIDC, TOKENX -> tokenPayloadBase64(openIDToken);
case OIDC, TOKENX, AZURE_JWT -> tokenPayloadBase64(openIDToken);
case SAML -> Base64.getEncoder().encodeToString(token.getBytes(StandardCharsets.UTF_8));
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private static List<XacmlRequest.AttributeAssignment> getTokenEnvironmentAttrs(f
case OIDC -> NavFellesAttributter.ENVIRONMENT_FELLES_OIDC_TOKEN_BODY;
case TOKENX -> NavFellesAttributter.ENVIRONMENT_FELLES_TOKENX_TOKEN_BODY;
case SAML -> NavFellesAttributter.ENVIRONMENT_FELLES_SAML_TOKEN;
case AZURE_JWT -> NavFellesAttributter.ENVIRONMENT_FELLES_AZURE_JWT_TOKEN_BODY;
};
var assignement = new XacmlRequest.AttributeAssignment(envTokenBodyAttributt, beskyttetRessursAttributter.getToken().getTokenBody());
return List.of(assignement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class NavFellesAttributter {
public static final String ENVIRONMENT_FELLES_TOKENX_TOKEN_BODY = "no.nav.abac.attributter.environment.felles.tokenx_token_body";
public static final String ENVIRONMENT_FELLES_SAML_TOKEN = "no.nav.abac.attributter.environment.felles.saml_token";
public static final String ENVIRONMENT_FELLES_OIDC_TOKEN_BODY = "no.nav.abac.attributter.environment.felles.oidc_token_body";

public static final String ENVIRONMENT_FELLES_AZURE_JWT_TOKEN_BODY = "no.nav.abac.attributter.environment.felles.azure_jwt_token_body";

public static final String ENVIRONMENT_FELLES_PEP_ID = "no.nav.abac.attributter.environment.felles.pep_id";

public static final String RESOURCE_FELLES_RESOURCE_TYPE = "no.nav.abac.attributter.resource.felles.resource_type";
Expand Down

0 comments on commit 043b0ad

Please sign in to comment.