This is an automated email from the ASF dual-hosted git repository. lahirujayathilake pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
commit bbb3f1d45813e891c4868e24ffb3b3ce1c6ec07c Author: lahiruj <[email protected]> AuthorDate: Tue Sep 23 01:01:24 2025 -0400 AMIE account creation handler implementation --- .../amie/handler/RequestAccountCreateHandler.java | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/amie-decoder/src/main/java/org/apache/custos/amie/handler/RequestAccountCreateHandler.java b/amie-decoder/src/main/java/org/apache/custos/amie/handler/RequestAccountCreateHandler.java new file mode 100644 index 000000000..9fe14b712 --- /dev/null +++ b/amie-decoder/src/main/java/org/apache/custos/amie/handler/RequestAccountCreateHandler.java @@ -0,0 +1,96 @@ +/* + * 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.amie.handler; + +import com.fasterxml.jackson.databind.JsonNode; +import org.apache.custos.amie.client.AmieClient; +import org.apache.custos.amie.model.PacketEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import org.springframework.util.Assert; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * Handles the 'request_account_create' AMIE packet. + * <p> + * This transaction asks the local site to create an account for a user on a project. + * This includes creating a local user account with the specified project (a Unix account) if one does not exist. + * Upon successful processing sends a 'notify_account_create' reply back to AMIE. + */ +@Component +public class RequestAccountCreateHandler implements PacketHandler { + + private static final Logger LOGGER = LoggerFactory.getLogger(RequestAccountCreateHandler.class); + + private final AmieClient amieClient; + + public RequestAccountCreateHandler(AmieClient amieClient) { + this.amieClient = amieClient; + } + + @Override + public String supportsType() { + return "request_account_create"; + } + + @Override + public void handle(JsonNode packetJson, PacketEntity packetEntity) throws Exception { + LOGGER.info("Starting 'request_account_create' handler for packet amie_id [{}].", packetEntity.getAmieId()); + + JsonNode body = packetJson.path("body"); + String projectId = body.path("ProjectID").asText(); + String grantNumber = body.path("GrantNumber").asText(); + String userFirstName = body.path("UserFirstName").asText(); + String userLastName = body.path("UserLastName").asText(); + String userEmail = body.path("UserEmail").asText(); + + Assert.hasText(projectId, "'ProjectID' (the local project ID) must not be empty."); + Assert.hasText(userFirstName, "'UserFirstName' must not be empty."); + Assert.hasText(userLastName, "'UserLastName' must not be empty."); + LOGGER.info("Packet validated successfully for user [{} {}] on project [{}].", userFirstName, userLastName, projectId); + + // TODO invoke actual cluster's user provisioning service. For the time being generating a local user ID and a username + String localUserPersonId = UUID.randomUUID().toString(); + String localUsername = (userFirstName.charAt(0) + userLastName).toLowerCase(); + + LOGGER.info("Created local user account with PersonID [{}] and username [{}]", localUserPersonId, localUsername); + + // Build and send the 'notify_account_create' reply + Map<String, Object> replyBody = new HashMap<>(); + Map<String, Object> bodyContent = new HashMap<>(); + bodyContent.put("ProjectID", projectId); + bodyContent.put("UserPersonID", localUserPersonId); + + // User login name (Unix username) on the actual resource + bodyContent.put("UserRemoteSiteLogin", localUsername); + + bodyContent.put("GrantNumber", grantNumber); + + replyBody.put("type", "notify_account_create"); + replyBody.put("body", bodyContent); + + amieClient.replyToPacket(packetEntity.getAmieId(), replyBody); + + LOGGER.info("Successfully completed 'request_account_create' handler and sent reply for packet amie_id [{}].", packetEntity.getAmieId()); + } +}
