You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by is...@apache.org on 2023/02/08 20:40:14 UTC
[airavata-custos] branch baremetal updated: support user search in scim
This is an automated email from the ASF dual-hosted git repository.
isjarana pushed a commit to branch baremetal
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
The following commit(s) were added to refs/heads/baremetal by this push:
new 50519787b support user search in scim
new af2257c75 Merge pull request #348 from isururanawaka/baremetal
50519787b is described below
commit 50519787b9c6106f922bd21b7bbdcbdc35aa461a
Author: Isuru Ranawaka <ir...@gmail.com>
AuthorDate: Wed Feb 8 15:39:38 2023 -0500
support user search in scim
---
.../custos/scim/exception/CustosSCIMException.java | 32 +++++++++++
.../apache/custos/scim/resource/UserResource.java | 16 +++++-
.../scim/resource/manager/ResourceManager.java | 65 +++++++++++++++++++---
3 files changed, 102 insertions(+), 11 deletions(-)
diff --git a/custos-services/custos-integration-services/scim-service/src/main/java/org/apache/custos/scim/exception/CustosSCIMException.java b/custos-services/custos-integration-services/scim-service/src/main/java/org/apache/custos/scim/exception/CustosSCIMException.java
new file mode 100644
index 000000000..60b57b4e9
--- /dev/null
+++ b/custos-services/custos-integration-services/scim-service/src/main/java/org/apache/custos/scim/exception/CustosSCIMException.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.custos.scim.exception;
+
+public class CustosSCIMException extends RuntimeException {
+
+ public CustosSCIMException(String message) {
+ super(message);
+ }
+
+ public CustosSCIMException(String message, Throwable throwable) {
+ super(message, throwable);
+ }
+
+}
diff --git a/custos-services/custos-integration-services/scim-service/src/main/java/org/apache/custos/scim/resource/UserResource.java b/custos-services/custos-integration-services/scim-service/src/main/java/org/apache/custos/scim/resource/UserResource.java
index d0196dda1..dd9b4cd9e 100644
--- a/custos-services/custos-integration-services/scim-service/src/main/java/org/apache/custos/scim/resource/UserResource.java
+++ b/custos-services/custos-integration-services/scim-service/src/main/java/org/apache/custos/scim/resource/UserResource.java
@@ -222,11 +222,23 @@ public class UserResource extends AbstractResource {
@PostMapping(value = {"/.search"}, produces = {"application/json", "application/scim+json"}, consumes = {"application/scim+json"})
public ResponseEntity getUsersByPost(@RequestBody String resourceString, @RequestHeader(value = Constants.AUTHORIZATION) String authorizationHeader) {
- authHandler.validateAndConfigure(authorizationHeader, false);
+ Optional<AuthClaim> claim = authHandler.validateAndConfigure(authorizationHeader, false);
+
+
+ JSONObject newObj = new JSONObject();
+ JSONObject custosExtention = new JSONObject(resourceString);
+ if (claim.isPresent()) {
+ newObj.put(Constants.CLIENT_ID, claim.get().getIamAuthId());
+ newObj.put(Constants.CLIENT_SEC, claim.get().getIamAuthSecret());
+ newObj.put(Constants.TENANT_ID, String.valueOf(claim.get().getTenantId()));
+ newObj.put(Constants.ACCESS_TOKEN, authHandler.getToken(authorizationHeader));
+ }
+
+ custosExtention.put(Constants.CUSTOS_EXTENSION, newObj);
UserResourceManager userResourceManager = new UserResourceManager();
- SCIMResponse response = userResourceManager.listWithPOST(resourceString, resourceManager);
+ SCIMResponse response = userResourceManager.listWithPOST(custosExtention.toString(), resourceManager);
return buildResponse(response);
diff --git a/custos-services/custos-integration-services/scim-service/src/main/java/org/apache/custos/scim/resource/manager/ResourceManager.java b/custos-services/custos-integration-services/scim-service/src/main/java/org/apache/custos/scim/resource/manager/ResourceManager.java
index ae4999975..0a9d7613e 100644
--- a/custos-services/custos-integration-services/scim-service/src/main/java/org/apache/custos/scim/resource/manager/ResourceManager.java
+++ b/custos-services/custos-integration-services/scim-service/src/main/java/org/apache/custos/scim/resource/manager/ResourceManager.java
@@ -19,12 +19,14 @@
package org.apache.custos.scim.resource.manager;
+import io.grpc.Status;
import org.apache.custos.credential.store.client.CredentialStoreServiceClient;
import org.apache.custos.iam.admin.client.IamAdminServiceClient;
import org.apache.custos.iam.service.*;
import org.apache.custos.identity.client.IdentityClient;
import org.apache.custos.identity.service.AuthToken;
import org.apache.custos.identity.service.GetUserManagementSATokenRequest;
+import org.apache.custos.scim.exception.CustosSCIMException;
import org.apache.custos.scim.utils.Constants;
import org.apache.custos.user.profile.client.UserProfileClient;
import org.apache.custos.user.profile.service.UserProfile;
@@ -173,21 +175,21 @@ public class ResourceManager implements UserManager {
try {
return this.convert(userRepresentation);
- } catch (InternalErrorException e) {
- String msg = "Error occurred while converting user representation to charon";
- throw new CharonException(msg, e);
+ } catch (InternalErrorException | NotFoundException e) {
+ String msg = "Error occurred while converting user representation";
+ throw new CustosSCIMException(msg, e);
}
} else {
String msg = "User not successfully registered";
LOGGER.error(msg);
- throw new RuntimeException(msg);
+ throw new CustosSCIMException(msg);
}
} else {
String msg = "Token not found ";
LOGGER.error(msg);
- throw new RuntimeException(msg);
+ throw new CustosSCIMException(msg);
}
}
@@ -304,7 +306,52 @@ public class ResourceManager implements UserManager {
@Override
public List<Object> listUsersWithPost(SearchRequest searchRequest, Map<String, Boolean> map) throws CharonException, NotImplementedException, BadRequestException {
- throw new NotImplementedException("Method not implemented");
+
+// Object obj = map.get(Constants.CUSTOS_EXTENSION);
+// String clientId = ((String) ((JSONObject) obj).get(Constants.CLIENT_ID));
+// String clientSec = ((String) ((JSONObject) obj).get(Constants.CLIENT_SEC));
+// String decodedId = ((String) ((JSONObject) obj).get(Constants.ID));
+// String tenantId = ((String) ((JSONObject) obj).get(Constants.TENANT_ID));
+//
+// long tenant = Long.valueOf(tenantId);
+//
+// GetUserManagementSATokenRequest userManagementSATokenRequest = GetUserManagementSATokenRequest
+// .newBuilder()
+// .setClientId(clientId)
+// .setClientSecret(clientSec)
+// .setTenantId(tenant)
+// .build();
+// AuthToken token = identityClient.getUserManagementSATokenRequest(userManagementSATokenRequest);
+//
+// if (token != null && token.getAccessToken() != null) {
+//
+// UserSearchMetadata metada = UserSearchMetadata.newBuilder().setUsername(decodedId).build();
+//
+// UserSearchRequest request = UserSearchRequest
+// .newBuilder()
+// .setTenantId(tenant)
+// .setAccessToken(token.getAccessToken())
+// .setUser(metada)
+// .build();
+//
+// UserRepresentation userRep = iamAdminServiceClient.getUser(request);
+//
+// if (userRep == null || userRep.getUsername().equals("")) {
+// throw new NotFoundException("User not found");
+// }
+//
+// try {
+// return convert(userRep);
+// } catch (InternalErrorException e) {
+// throw new CharonException(SCIMConstants.USER);
+// }
+//
+// } else {
+// String msg = "Token not found ";
+// LOGGER.error(msg);
+// throw new NotFoundException(msg);
+// }
+ return null;
}
@Override
@@ -674,7 +721,7 @@ public class ResourceManager implements UserManager {
}
- private User convert(UserRepresentation representation) throws BadRequestException, CharonException, InternalErrorException {
+ private User convert(UserRepresentation representation) throws BadRequestException, CharonException, InternalErrorException, NotFoundException {
//obtain the json encoder
JSONEncoder encoder = getEncoder();
@@ -716,7 +763,7 @@ public class ResourceManager implements UserManager {
}
- private String getUser(UserRepresentation representation) {
+ private String getUser(UserRepresentation representation) throws NotFoundException {
JSONObject object = new JSONObject();
object.put("id", representation.getUsername());
object.put("externalId", representation.getUsername());
@@ -730,7 +777,7 @@ public class ResourceManager implements UserManager {
Instant instant = Instant.ofEpochMilli(Double.doubleToLongBits(representation.getCreationTime()));
JSONObject meta = new JSONObject();
meta.put("created", instant.toString());
- String location = "https://custos.scigap.org:32036/scim/v2/Users/" + representation.getUsername();
+ String location = AbstractResourceManager.getResourceEndpointURL(SCIMConstants.USER_ENDPOINT)+ representation.getUsername();
meta.put("location", location);
meta.put("resourceType", SCIMConstants.USER);