Skip to content

Commit

Permalink
WIP for #240
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Oct 11, 2024
1 parent a15d4e5 commit ce2f4a8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions server/src/main/java/access/provision/Provisioning.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class Provisioning {
private final String graphClientId;
private final String graphSecret;
private final String graphTenant;
private final String institutionGUID;

public Provisioning(Map<String, Object> provider) {
this.id = (String) provider.get("id");
Expand All @@ -47,6 +48,7 @@ public Provisioning(Map<String, Object> provider) {
this.graphClientId = (String) provider.get("graph_client_id");
this.graphSecret = (String) provider.get("graph_secret");
this.graphTenant = (String) provider.getOrDefault("graph_tenant", "common");
this.institutionGUID = (String) provider.get("coin:institution_guid");
this.invariant();

}
Expand All @@ -67,6 +69,11 @@ private void invariant() {
assert graphSecret != null: "graphSecret is null";
}
}
switch (this.scimUserIdentifier) {
case eduID -> {
assert institutionGUID != null : "institutionGUID is null";
}
}
}

public boolean isApplicableForGroupRequest() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package access.provision;

import access.eduid.EduID;
import access.eduid.EduIDProvision;
import access.exception.RemoteException;
import access.manage.Manage;
import access.manage.ManageIdentifier;
Expand Down Expand Up @@ -58,6 +60,7 @@ public class ProvisioningServiceDefault implements ProvisioningService {
private final GraphClient graphClient;
private final EvaClient evaClient;
private final KeyStore keyStore;
private final EduID eduID;

@Autowired
public ProvisioningServiceDefault(UserRoleRepository userRoleRepository,
Expand All @@ -66,6 +69,7 @@ public ProvisioningServiceDefault(UserRoleRepository userRoleRepository,
Manage manage,
ObjectMapper objectMapper,
KeyStore keyStore,
EduID eduID,
@Value("${voot.group_urn_domain}") String groupUrnPrefix,
@Value("${config.eduid-idp-schac-home-organization}") String eduidIdpSchacHomeOrganization,
@Value("${config.server-url}") String serverBaseURL) {
Expand All @@ -76,6 +80,7 @@ public ProvisioningServiceDefault(UserRoleRepository userRoleRepository,
this.objectMapper = objectMapper;
this.keyStore = keyStore;
this.groupUrnPrefix = groupUrnPrefix;
this.eduID = eduID;
this.graphClient = new GraphClient(serverBaseURL, eduidIdpSchacHomeOrganization, keyStore, objectMapper);
this.evaClient = new EvaClient(keyStore);
// Otherwise, we can't use method PATCH
Expand All @@ -94,7 +99,13 @@ public Optional<GraphResponse> newUserRequest(User user) {
.filter(provisioning -> this.remoteProvisionedUserRepository.findByManageProvisioningIdAndUser(provisioning.getId(), user)
.isEmpty())
.forEach(provisioning -> {
String userRequest = prettyJson(new UserRequest(user, provisioning));
UserRequest request = new UserRequest(user, provisioning);
if (provisioning.getScimUserIdentifier().equals(ScimUserIdentifier.eduID) &&
request.getExternalId().equals(user.getEduId())) {
//No fallback for failure
this.eduID.provisionEduid(new EduIDProvision(user.getEduId(), provisioning.getInstitutionGUID()));
}
String userRequest = prettyJson(request);
Optional<ProvisioningResponse> provisioningResponse = this.newRequest(provisioning, userRequest, user);
provisioningResponse.ifPresent(response -> {
if (!response.isErrorResponse() && StringUtils.hasText(response.remoteIdentifier())) {
Expand Down

0 comments on commit ce2f4a8

Please sign in to comment.