-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrerer mot MS Graph for bruker og grupper info.
Ved feilende kall mot Graph, returneres det mocket data for å ikke forstyrre testing i Q1.
- Loading branch information
Showing
7 changed files
with
183 additions
and
42 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
9 changes: 9 additions & 0 deletions
9
web/src/main/java/no/nav/ung/sak/web/app/tjenester/microsoftgraph/MSGraphBruker.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,9 @@ | ||
package no.nav.ung.sak.web.app.tjenester.microsoftgraph; | ||
|
||
import com.microsoft.graph.models.Group; | ||
import com.microsoft.graph.models.User; | ||
|
||
import java.util.List; | ||
|
||
public record MSGraphBruker(User bruker, List<Group> grupper) { | ||
} |
35 changes: 35 additions & 0 deletions
35
...main/java/no/nav/ung/sak/web/app/tjenester/microsoftgraph/MicrosoftGraphClientConfig.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,35 @@ | ||
package no.nav.ung.sak.web.app.tjenester.microsoftgraph; | ||
|
||
import com.azure.identity.ClientSecretCredential; | ||
import com.azure.identity.ClientSecretCredentialBuilder; | ||
import com.microsoft.graph.serviceclient.GraphServiceClient; | ||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.inject.Inject; | ||
import no.nav.k9.felles.konfigurasjon.konfig.KonfigVerdi; | ||
|
||
@Dependent | ||
public class MicrosoftGraphClientConfig { | ||
private final GraphServiceClient graphClient; | ||
|
||
final String[] scopes = new String[] { "https://graph.microsoft.com/.default" }; | ||
|
||
@Inject | ||
public MicrosoftGraphClientConfig( | ||
@KonfigVerdi(value = "AZURE_APP_CLIENT_ID") String clientId, | ||
@KonfigVerdi(value = "AZURE_APP_CLIENT_SECRET") String clientSecret, | ||
@KonfigVerdi(value = "AZURE_APP_TENANT_ID") String tenantId | ||
) { | ||
|
||
final ClientSecretCredential credential = new ClientSecretCredentialBuilder() | ||
.tenantId(tenantId) | ||
.clientId(clientId) | ||
.clientSecret(clientSecret) | ||
.build(); | ||
|
||
this.graphClient = new GraphServiceClient(credential, scopes); | ||
} | ||
|
||
public GraphServiceClient getGraphClient() { | ||
return graphClient; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...src/main/java/no/nav/ung/sak/web/app/tjenester/microsoftgraph/MicrosoftGraphTjeneste.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,46 @@ | ||
package no.nav.ung.sak.web.app.tjenester.microsoftgraph; | ||
|
||
import com.microsoft.graph.models.DirectoryObject; | ||
import com.microsoft.graph.models.Group; | ||
import com.microsoft.graph.models.GroupCollectionResponse; | ||
import com.microsoft.graph.models.User; | ||
import com.microsoft.graph.serviceclient.GraphServiceClient; | ||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.inject.Inject; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@Dependent | ||
public class MicrosoftGraphTjeneste { | ||
|
||
private final GraphServiceClient graphClient; | ||
|
||
|
||
@Inject | ||
public MicrosoftGraphTjeneste(MicrosoftGraphClientConfig microsoftGraphClientConfig) { | ||
this.graphClient = microsoftGraphClientConfig.getGraphClient(); | ||
} | ||
|
||
public MSGraphBruker getUserInfoFromGraph(String userPrincipalName) { | ||
User user = graphClient.users().byUserId(userPrincipalName).get(); | ||
|
||
return new MSGraphBruker(user, getUserGroupsFromGraph(userPrincipalName)); | ||
} | ||
|
||
public List<Group> getUserGroupsFromGraph(String userPrincipalName) { | ||
GroupCollectionResponse groupCollectionResponse = graphClient | ||
.users() | ||
.byUserId(userPrincipalName) | ||
.memberOf() | ||
.graphGroup() | ||
.get(); | ||
|
||
return Objects.requireNonNull(groupCollectionResponse.getValue()) | ||
.stream() | ||
.filter(Objects::nonNull) | ||
.map(DirectoryObject.class::cast) | ||
.map(Group.class::cast) | ||
.toList(); | ||
} | ||
} |
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