-
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.
EE10: Persistence + Flytte tokenvalidering til SAM. Fjerne SubjectHan…
…dler (#1319) * Flytte tokenvalidering fra Login til SAM. Fjerne SubjectHandler * Forenkle SAM vs validering litt til * Videre forenkling * Rydde litt * Resten av EE10
- Loading branch information
Showing
26 changed files
with
261 additions
and
695 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
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: 0 additions & 18 deletions
18
felles/sikkerhet/src/main/java/no/nav/vedtak/sikkerhet/TokenCallback.java
This file was deleted.
Oops, something went wrong.
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
31 changes: 0 additions & 31 deletions
31
felles/sikkerhet/src/main/java/no/nav/vedtak/sikkerhet/context/JettySubjectHandler.java
This file was deleted.
Oops, something went wrong.
92 changes: 0 additions & 92 deletions
92
felles/sikkerhet/src/main/java/no/nav/vedtak/sikkerhet/context/SubjectHandler.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 |
---|---|---|
@@ -1,92 +0,0 @@ | ||
package no.nav.vedtak.sikkerhet.context; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.security.auth.Subject; | ||
|
||
import no.nav.vedtak.exception.TekniskException; | ||
import no.nav.vedtak.sikkerhet.context.containers.ConsumerId; | ||
import no.nav.vedtak.sikkerhet.context.containers.SluttBruker; | ||
import no.nav.vedtak.sikkerhet.kontekst.Groups; | ||
import no.nav.vedtak.sikkerhet.kontekst.IdentType; | ||
|
||
public abstract class SubjectHandler { | ||
public abstract Subject getSubject(); | ||
|
||
public static SubjectHandler getSubjectHandler() { | ||
return new JettySubjectHandler(); | ||
} | ||
|
||
public String getUid() { | ||
return getUid(getSubject()); | ||
} | ||
|
||
public static String getUid(Subject subject) { | ||
return Optional.ofNullable(getSluttBruker(subject)) | ||
.map(SluttBruker::getName) | ||
.orElse(null); | ||
} | ||
|
||
public SluttBruker getSluttBruker() { | ||
return getSluttBruker(getSubject()); | ||
} | ||
|
||
public static SluttBruker getSluttBruker(Subject subject) { | ||
return Optional.ofNullable(subject) | ||
.map(s -> s.getPrincipals(SluttBruker.class)) | ||
.map(SubjectHandler::getTheOnlyOneInSet) | ||
.orElse(null); | ||
} | ||
|
||
public IdentType getIdentType() { | ||
return Optional.ofNullable(getSubject()) | ||
.map(s -> s.getPrincipals(SluttBruker.class)) | ||
.map(SubjectHandler::getTheOnlyOneInSet) | ||
.map(SluttBruker::getIdentType) | ||
.orElse(null); | ||
} | ||
|
||
public Set<Groups> getGrupper() { | ||
return Optional.ofNullable(getSubject()) | ||
.map(s -> s.getPrincipals(SluttBruker.class)) | ||
.map(SubjectHandler::getTheOnlyOneInSet) | ||
.map(SluttBruker::getGrupper) | ||
.orElse(Set.of()); | ||
} | ||
|
||
public String getConsumerId() { | ||
return getConsumerId(getSubject()); | ||
} | ||
|
||
public static String getConsumerId(Subject subject) { | ||
return Optional.ofNullable(subject) | ||
.map(s -> s.getPrincipals(ConsumerId.class)) | ||
.map(SubjectHandler::getTheOnlyOneInSet) | ||
.filter(Objects::nonNull) | ||
.map(ConsumerId::getConsumerId) | ||
.orElse(null); | ||
} | ||
|
||
private static <T> T getTheOnlyOneInSet(Set<T> set) { | ||
if (set.isEmpty()) { | ||
return null; | ||
} | ||
|
||
if (set.size() == 1) { | ||
return set.iterator().next(); | ||
} | ||
|
||
// logging class names to the log to help debug. Cannot log actual objects, | ||
// since then ID_tokens may be logged | ||
Set<String> classNames = set.stream() | ||
.map(Object::getClass) | ||
.map(Class::getName) | ||
.collect(Collectors.toSet()); | ||
throw new TekniskException("F-327190", | ||
String.format("Forventet ingen eller ett element, men fikk %s elementer av type %s", set.size(), classNames)); | ||
} | ||
|
||
} | ||
21 changes: 0 additions & 21 deletions
21
...es/sikkerhet/src/main/java/no/nav/vedtak/sikkerhet/context/ThreadLocalSubjectHandler.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.