You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ya...@apache.org on 2026/03/28 03:55:15 UTC
(airavata) 03/11: refactor: convert research-service from standalone Boot app to plain library
This is an automated email from the ASF dual-hosted git repository.
yasith pushed a commit to branch feat/spring-module-reorg
in repository https://gitbox.apache.org/repos/asf/airavata.git
commit c4660dc5dee330bf3408b602c2ce8340dd38cdcb
Author: yasithdev <ya...@icloud.com>
AuthorDate: Fri Mar 27 22:12:26 2026 -0500
refactor: convert research-service from standalone Boot app to plain library
---
.../research-framework/research-service/pom.xml | 33 ------
.../assembly/research-service-bin-assembly.xml | 76 -------------
.../airavata/research/service/AiravataService.java | 2 +-
.../service/ResearchServiceApplication.java | 34 ------
.../research/service/config/AuthzTokenFilter.java | 122 ---------------------
.../service/config/DevDataInitializer.java | 11 +-
.../research/service/config/OpenApiConfig.java | 90 ---------------
.../service/config/ResearchProperties.java | 28 +++++
.../service/config/ResearchServiceConfig.java | 15 +++
.../research/service/config/WebMvcConfig.java | 43 --------
.../service/controller/SessionController.java | 2 +-
.../research/service/handlers/ProjectHandler.java | 2 +-
.../service/handlers/ResearchHubHandler.java | 34 +++---
.../research/service/handlers/ResourceHandler.java | 2 +-
.../research/service/handlers/SessionHandler.java | 2 +-
.../research/service/model/UserContext.java | 62 -----------
.../src/main/resources/application.yml | 76 -------------
17 files changed, 69 insertions(+), 565 deletions(-)
diff --git a/modules/research-framework/research-service/pom.xml b/modules/research-framework/research-service/pom.xml
index 1c799544a1..d6796746f4 100644
--- a/modules/research-framework/research-service/pom.xml
+++ b/modules/research-framework/research-service/pom.xml
@@ -31,10 +31,6 @@ under the License.
<artifactId>research-service</artifactId>
<name>Airavata Research Service</name>
- <properties>
- <research.service.dist.name>apache-airavata-research-service-${project.version}</research.service.dist.name>
- </properties>
-
<dependencies>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
@@ -173,35 +169,10 @@ under the License.
</exclusion>
</exclusions>
</dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-actuator</artifactId>
- </dependency>
</dependencies>
<build>
<plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-assembly-plugin</artifactId>
- <executions>
- <execution>
- <id>research-service-distribution-package</id>
- <phase>package</phase>
- <goals>
- <goal>single</goal>
- </goals>
- <configuration>
- <tarLongFileMode>posix</tarLongFileMode>
- <finalName>${research.service.dist.name}</finalName>
- <descriptors>
- <descriptor>src/main/assembly/research-service-bin-assembly.xml</descriptor>
- </descriptors>
- <attach>false</attach>
- </configuration>
- </execution>
- </executions>
- </plugin>
<plugin>
<groupId>io.github.ascopes</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
@@ -235,10 +206,6 @@ under the License.
<release>17</release>
</configuration>
</plugin>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
diff --git a/modules/research-framework/research-service/src/main/assembly/research-service-bin-assembly.xml b/modules/research-framework/research-service/src/main/assembly/research-service-bin-assembly.xml
deleted file mode 100644
index 46bd0b32ff..0000000000
--- a/modules/research-framework/research-service/src/main/assembly/research-service-bin-assembly.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-
-<!--
-
- 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.
-
--->
-<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.2.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.2.0 http://maven.apache.org/xsd/assembly-2.2.0.xsd">
- <id>bin</id>
- <includeBaseDirectory>true</includeBaseDirectory>
- <baseDirectory>${research.service.dist.name}</baseDirectory>
- <formats>
- <format>tar.gz</format>
- </formats>
-
- <fileSets>
- <fileSet>
- <directory>src/main/resources/distribution/bin</directory>
- <outputDirectory>bin</outputDirectory>
- <fileMode>777</fileMode>
- <includes>
- <include>*.sh</include>
- </includes>
- </fileSet>
- <fileSet>
- <directory>src/main/resources/distribution/conf</directory>
- <outputDirectory>conf</outputDirectory>
- <includes>
- <include>application.yml</include>
- <include>airavata.p12</include>
- <include>log4j2.xml</include>
- </includes>
- </fileSet>
- <fileSet>
- <directory>./</directory>
- <outputDirectory>logs</outputDirectory>
- <excludes>
- <exclude>*/**</exclude>
- </excludes>
- </fileSet>
- <fileSet>
- <directory>target</directory>
- <outputDirectory>lib</outputDirectory>
- <includes>
- <include>*.jar</include>
- </includes>
- </fileSet>
- </fileSets>
-
- <dependencySets>
- <dependencySet>
- <useProjectArtifact>false</useProjectArtifact>
- <outputDirectory>lib</outputDirectory>
- <includes>
- <include>*</include>
- </includes>
- </dependencySet>
- </dependencySets>
-
-</assembly>
\ No newline at end of file
diff --git a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/AiravataService.java b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/AiravataService.java
index 67f8493ac6..2dc09ed6a5 100644
--- a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/AiravataService.java
+++ b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/AiravataService.java
@@ -21,7 +21,7 @@ package org.apache.airavata.research.service;
import org.apache.airavata.model.security.AuthzToken;
import org.apache.airavata.model.user.UserProfile;
-import org.apache.airavata.research.service.model.UserContext;
+import org.apache.airavata.common.security.UserContext;
import org.apache.airavata.security.profile.client.ProfileServiceClientFactory;
import org.apache.airavata.service.profile.user.cpi.UserProfileService;
import org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException;
diff --git a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/ResearchServiceApplication.java b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/ResearchServiceApplication.java
deleted file mode 100644
index c24f8e75c6..0000000000
--- a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/ResearchServiceApplication.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
-*
-* 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.airavata.research.service;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
-import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
-
-@SpringBootApplication
-@EnableJpaRepositories()
-@EnableJpaAuditing
-public class ResearchServiceApplication {
- public static void main(String[] args) {
- SpringApplication.run(ResearchServiceApplication.class, args);
- }
-}
diff --git a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/config/AuthzTokenFilter.java b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/config/AuthzTokenFilter.java
deleted file mode 100644
index fa55625547..0000000000
--- a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/config/AuthzTokenFilter.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
-*
-* 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.airavata.research.service.config;
-
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import jakarta.servlet.FilterChain;
-import jakarta.servlet.ServletException;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.util.Map;
-import org.apache.airavata.model.security.AuthzToken;
-import org.apache.airavata.model.user.UserProfile;
-import org.apache.airavata.research.service.AiravataService;
-import org.apache.airavata.research.service.model.UserContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-import org.springframework.web.filter.OncePerRequestFilter;
-
-@Component
-public class AuthzTokenFilter extends OncePerRequestFilter {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(AuthzTokenFilter.class);
- private static final String USERNAME_CLAIM = "userName";
- private static final String GATEWAY_CLAIM = "gatewayID";
-
- private final AiravataService airavataService;
-
- @Value("${airavata.research-hub.url}")
- private String csHubUrl;
-
- public AuthzTokenFilter(AiravataService airavataService) {
- this.airavataService = airavataService;
- }
-
- @Override
- protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {
- String path = request.getRequestURI();
-
- if (request.getMethod().equalsIgnoreCase("POST")
- || request.getMethod().equalsIgnoreCase("PUT")
- || request.getMethod().equalsIgnoreCase("PATCH")
- || request.getMethod().equalsIgnoreCase("DELETE")) {
- return false; // mutation requests should be authenticated
- }
-
- return path.startsWith("/swagger")
- || path.startsWith("/v2/api-docs")
- || path.startsWith("/v3/api-docs")
- || path.startsWith("/swagger-ui")
- || path.startsWith("/swagger-resources")
- || path.startsWith("/webjars/");
- }
-
- @Override
- protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
- throws ServletException, IOException {
- try {
- String authorizationHeader = request.getHeader("Authorization");
- String xClaimsHeader = request.getHeader("X-Claims");
-
- if (request.getMethod().equals("OPTIONS")) {
- filterChain.doFilter(request, response);
- return;
- }
-
- if (authorizationHeader != null && authorizationHeader.startsWith("Bearer ") && xClaimsHeader != null) {
- try {
- String accessToken = authorizationHeader.substring(7); // Remove "Bearer " prefix
- ObjectMapper objectMapper = new ObjectMapper();
- Map<String, String> claimsMap = objectMapper.readValue(xClaimsHeader, new TypeReference<>() {});
-
- AuthzToken authzToken = new AuthzToken();
- authzToken.setAccessToken(accessToken);
- authzToken.setClaimsMap(claimsMap);
- UserContext.setAuthzToken(authzToken);
-
- UserProfile userProfile = airavataService.getUserProfile(
- authzToken, getClaim(authzToken, USERNAME_CLAIM), getClaim(authzToken, GATEWAY_CLAIM));
- UserContext.setUser(userProfile);
- } catch (Exception e) {
- LOGGER.error("Invalid authorization data", e);
- response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Invalid authorization data");
- return;
- }
- }
-
- filterChain.doFilter(request, response);
- } finally {
- UserContext.clear();
- }
- }
-
- private static String getClaim(AuthzToken authzToken, String claimId) {
- return authzToken.getClaimsMap().entrySet().stream()
- .filter(entry -> entry.getKey().equalsIgnoreCase(claimId))
- .map(Map.Entry::getValue)
- .findFirst()
- .orElseThrow(() ->
- new IllegalArgumentException("Missing '" + claimId + "' claim in the authentication token"));
- }
-}
diff --git a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/config/DevDataInitializer.java b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/config/DevDataInitializer.java
index ceb321fbbf..8576d0b214 100644
--- a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/config/DevDataInitializer.java
+++ b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/config/DevDataInitializer.java
@@ -30,7 +30,6 @@ import org.apache.airavata.research.service.model.entity.Tag;
import org.apache.airavata.research.service.model.repo.ProjectRepository;
import org.apache.airavata.research.service.model.repo.ResourceRepository;
import org.apache.airavata.research.service.model.repo.TagRepository;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
@@ -42,15 +41,17 @@ public class DevDataInitializer implements CommandLineRunner {
private final ProjectRepository projectRepository;
private final ResourceRepository resourceRepository;
private final TagRepository tagRepository;
-
- @Value("${airavata.research-hub.dev-user}")
- private String devUserEmail;
+ private final ResearchProperties researchProperties;
public DevDataInitializer(
- ProjectRepository projectRepository, ResourceRepository resourceRepository, TagRepository tagRepository) {
+ ProjectRepository projectRepository,
+ ResourceRepository resourceRepository,
+ TagRepository tagRepository,
+ ResearchProperties researchProperties) {
this.projectRepository = projectRepository;
this.resourceRepository = resourceRepository;
this.tagRepository = tagRepository;
+ this.researchProperties = researchProperties;
}
private void createProject(
diff --git a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/config/OpenApiConfig.java b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/config/OpenApiConfig.java
deleted file mode 100644
index db49d784c5..0000000000
--- a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/config/OpenApiConfig.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
-*
-* 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.airavata.research.service.config;
-
-import io.swagger.v3.oas.models.OpenAPI;
-import io.swagger.v3.oas.models.info.Info;
-import io.swagger.v3.oas.models.media.StringSchema;
-import io.swagger.v3.oas.models.parameters.Parameter;
-import io.swagger.v3.oas.models.security.OAuthFlow;
-import io.swagger.v3.oas.models.security.OAuthFlows;
-import io.swagger.v3.oas.models.security.Scopes;
-import io.swagger.v3.oas.models.security.SecurityRequirement;
-import io.swagger.v3.oas.models.security.SecurityScheme;
-import org.springdoc.core.customizers.OpenApiCustomizer;
-import org.springdoc.core.models.GroupedOpenApi;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class OpenApiConfig {
-
- @Value("${airavata.openid.url}")
- private String openIdConfigURL;
-
- @Bean
- public GroupedOpenApi publicApi() {
- return GroupedOpenApi.builder()
- .group("public")
- .pathsToMatch("/api/**")
- .addOpenApiCustomizer(globalHeaderCustomizer())
- .build();
- }
-
- @Bean
- public OpenAPI researchServiceOpenAPI() {
- return new OpenAPI()
- .info(new Info().title("Research Service API").version("1.0.0"))
- .addSecurityItem(new SecurityRequirement().addList("oauth2-pkce"))
- .components(new io.swagger.v3.oas.models.Components()
- .addSecuritySchemes(
- "oauth2-pkce",
- new SecurityScheme()
- .type(SecurityScheme.Type.OAUTH2)
- .flows(new OAuthFlows()
- .authorizationCode(new OAuthFlow()
- .authorizationUrl(
- openIdConfigURL + "/protocol/openid-connect/auth")
- .tokenUrl(openIdConfigURL + "/protocol/openid-connect/token")
- .scopes(new Scopes()
- .addString("openid", "openid")
- .addString("email", "email"))))));
- }
-
- @Bean
- public OpenApiCustomizer globalHeaderCustomizer() {
- System.out.println("Applying global header customizer...");
- return openApi -> {
- Parameter claimsHeader = new Parameter()
- .in("header")
- .schema(new StringSchema())
- .name("X-Claims")
- .description("{userName: ..., gatewayID: ...}")
- .required(false);
-
- openApi.getPaths().values().forEach(pathItem -> {
- pathItem.readOperations().forEach(operation -> {
- operation.addParametersItem(claimsHeader);
- });
- });
- };
- }
-}
diff --git a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/config/ResearchProperties.java b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/config/ResearchProperties.java
new file mode 100644
index 0000000000..f289ecabe1
--- /dev/null
+++ b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/config/ResearchProperties.java
@@ -0,0 +1,28 @@
+package org.apache.airavata.research.service.config;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+@Component
+@ConfigurationProperties(prefix = "airavata.research")
+public class ResearchProperties {
+ private String hubUrl;
+ private String portalUrl;
+ private String devUrl;
+ private String devUser;
+ private String adminApiKey;
+ private int limit = 10;
+
+ public String getHubUrl() { return hubUrl; }
+ public void setHubUrl(String hubUrl) { this.hubUrl = hubUrl; }
+ public String getPortalUrl() { return portalUrl; }
+ public void setPortalUrl(String portalUrl) { this.portalUrl = portalUrl; }
+ public String getDevUrl() { return devUrl; }
+ public void setDevUrl(String devUrl) { this.devUrl = devUrl; }
+ public String getDevUser() { return devUser; }
+ public void setDevUser(String devUser) { this.devUser = devUser; }
+ public String getAdminApiKey() { return adminApiKey; }
+ public void setAdminApiKey(String adminApiKey) { this.adminApiKey = adminApiKey; }
+ public int getLimit() { return limit; }
+ public void setLimit(int limit) { this.limit = limit; }
+}
diff --git a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/config/ResearchServiceConfig.java b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/config/ResearchServiceConfig.java
new file mode 100644
index 0000000000..2ba233945c
--- /dev/null
+++ b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/config/ResearchServiceConfig.java
@@ -0,0 +1,15 @@
+package org.apache.airavata.research.service.config;
+
+import org.springframework.boot.autoconfigure.domain.EntityScan;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+
+@Configuration
+@ComponentScan(basePackages = "org.apache.airavata.research.service")
+@EntityScan(basePackages = "org.apache.airavata.research.service")
+@EnableJpaRepositories(basePackages = "org.apache.airavata.research.service")
+@EnableJpaAuditing
+public class ResearchServiceConfig {
+}
diff --git a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/config/WebMvcConfig.java b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/config/WebMvcConfig.java
deleted file mode 100644
index 06b393c56a..0000000000
--- a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/config/WebMvcConfig.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
-*
-* 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.airavata.research.service.config;
-
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.web.servlet.config.annotation.CorsRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-
-@Configuration
-public class WebMvcConfig implements WebMvcConfigurer {
-
- @Value("${airavata.research-portal.url}")
- private String deployedOrigin;
-
- @Value("${airavata.research-portal.dev-url}")
- private String devOrigin;
-
- @Override
- public void addCorsMappings(CorsRegistry registry) {
- registry.addMapping("/**")
- .allowedOrigins(deployedOrigin, devOrigin)
- .allowedMethods("GET", "POST", "OPTIONS", "PATCH", "DELETE", "PUT")
- .allowedHeaders("*");
- }
-}
diff --git a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/controller/SessionController.java b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/controller/SessionController.java
index 521acad8a5..4396f50c2a 100644
--- a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/controller/SessionController.java
+++ b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/controller/SessionController.java
@@ -24,7 +24,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import org.apache.airavata.research.service.enums.SessionStatusEnum;
import org.apache.airavata.research.service.handlers.SessionHandler;
-import org.apache.airavata.research.service.model.UserContext;
+import org.apache.airavata.common.security.UserContext;
import org.apache.airavata.research.service.model.entity.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ProjectHandler.java b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ProjectHandler.java
index 9fca965303..0106ebce34 100644
--- a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ProjectHandler.java
+++ b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ProjectHandler.java
@@ -28,7 +28,7 @@ import java.util.stream.Collectors;
import org.apache.airavata.research.service.dto.CreateProjectRequest;
import org.apache.airavata.research.service.enums.ResourceTypeEnum;
import org.apache.airavata.research.service.enums.StateEnum;
-import org.apache.airavata.research.service.model.UserContext;
+import org.apache.airavata.common.security.UserContext;
import org.apache.airavata.research.service.model.entity.DatasetResource;
import org.apache.airavata.research.service.model.entity.Project;
import org.apache.airavata.research.service.model.entity.RepositoryResource;
diff --git a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ResearchHubHandler.java b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ResearchHubHandler.java
index 3cecf1c512..c5a583c81c 100644
--- a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ResearchHubHandler.java
+++ b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ResearchHubHandler.java
@@ -25,14 +25,14 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.apache.airavata.research.service.enums.SessionStatusEnum;
-import org.apache.airavata.research.service.model.UserContext;
+import org.apache.airavata.common.security.UserContext;
import org.apache.airavata.research.service.model.entity.DatasetResource;
import org.apache.airavata.research.service.model.entity.Project;
import org.apache.airavata.research.service.model.entity.Session;
import org.apache.airavata.research.service.model.repo.ProjectRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
+import org.apache.airavata.research.service.config.ResearchProperties;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
@@ -53,29 +53,25 @@ public class ResearchHubHandler {
private final ProjectHandler projectHandler;
private final SessionHandler sessionHandler;
private final ProjectRepository projectRepository;
-
- @Value("${airavata.research-hub.url}")
- private String csHubUrl;
-
- @Value("${airavata.research-hub.adminApiKey}")
- private String adminApiKey;
-
- @Value("${airavata.research-hub.limit}")
- private int maxRHubSessions;
+ private final ResearchProperties researchProperties;
public ResearchHubHandler(
- ProjectHandler projectHandler, SessionHandler sessionHandler, ProjectRepository projectRepository) {
+ ProjectHandler projectHandler,
+ SessionHandler sessionHandler,
+ ProjectRepository projectRepository,
+ ResearchProperties researchProperties) {
this.projectHandler = projectHandler;
this.sessionHandler = sessionHandler;
this.projectRepository = projectRepository;
+ this.researchProperties = researchProperties;
}
public boolean stopSession(String sessionId) {
String userId = UserContext.userId();
- String url = String.format(SERVERS_API_URL, csHubUrl, userId, sessionId);
+ String url = String.format(SERVERS_API_URL, researchProperties.getHubUrl(), userId, sessionId);
HttpHeaders headers = new HttpHeaders();
- headers.set("Authorization", "token " + adminApiKey);
+ headers.set("Authorization", "token " + researchProperties.getAdminApiKey());
HttpEntity<Void> request = new HttpEntity<>(headers);
ResponseEntity<Void> response = new RestTemplate().exchange(url, HttpMethod.DELETE, request, Void.class);
@@ -90,10 +86,10 @@ public class ResearchHubHandler {
public boolean deleteSession(String sessionId) {
String userId = UserContext.userId();
- String url = String.format(SERVERS_API_URL, csHubUrl, userId, sessionId);
+ String url = String.format(SERVERS_API_URL, researchProperties.getHubUrl(), userId, sessionId);
HttpHeaders headers = new HttpHeaders();
- headers.set("Authorization", "token " + adminApiKey);
+ headers.set("Authorization", "token " + researchProperties.getAdminApiKey());
Map<String, Object> body = new HashMap<>();
body.put("remove", true);
@@ -113,7 +109,7 @@ public class ResearchHubHandler {
public String spinRHubSession(String projectId, String sessionName) {
String userId = UserContext.userId();
int alreadyCreated = sessionHandler.countSessionsByUserIdAndStatus(userId, SessionStatusEnum.CREATED);
- if (alreadyCreated >= maxRHubSessions) {
+ if (alreadyCreated >= researchProperties.getLimit()) {
throw new RuntimeException(
"Max number of active sessions (10) has already been reached. Please terminate or delete a session to continue.");
}
@@ -126,7 +122,7 @@ public class ResearchHubHandler {
String baseSpawnUrl = String.format(
RH_SPAWN_URL,
- csHubUrl,
+ researchProperties.getHubUrl(),
UserContext.userId(),
session.getId(),
project.getRepositoryResource().getRepositoryUrl());
@@ -153,7 +149,7 @@ public class ResearchHubHandler {
// TODO restrict this execution for owner
Session session = sessionHandler.findSession(sessionId);
- String sessionUrl = String.format(RH_SESSION_URL, csHubUrl, UserContext.userId(), session.getId());
+ String sessionUrl = String.format(RH_SESSION_URL, researchProperties.getHubUrl(), UserContext.userId(), session.getId());
LOGGER.debug("Generated the session url: {} for the user: {}", sessionUrl, UserContext.userId());
return sessionUrl;
}
diff --git a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ResourceHandler.java b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ResourceHandler.java
index d76b11aae6..02c30e963e 100644
--- a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ResourceHandler.java
+++ b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ResourceHandler.java
@@ -34,7 +34,7 @@ import org.apache.airavata.research.service.enums.PrivacyEnum;
import org.apache.airavata.research.service.enums.ResourceTypeEnum;
import org.apache.airavata.research.service.enums.StateEnum;
import org.apache.airavata.research.service.enums.StatusEnum;
-import org.apache.airavata.research.service.model.UserContext;
+import org.apache.airavata.common.security.UserContext;
import org.apache.airavata.research.service.model.entity.RepositoryResource;
import org.apache.airavata.research.service.model.entity.Resource;
import org.apache.airavata.research.service.model.entity.ResourceStar;
diff --git a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/SessionHandler.java b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/SessionHandler.java
index ae25f0caaf..6c1d442a44 100644
--- a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/SessionHandler.java
+++ b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/SessionHandler.java
@@ -23,7 +23,7 @@ import jakarta.persistence.EntityNotFoundException;
import java.util.List;
import java.util.UUID;
import org.apache.airavata.research.service.enums.SessionStatusEnum;
-import org.apache.airavata.research.service.model.UserContext;
+import org.apache.airavata.common.security.UserContext;
import org.apache.airavata.research.service.model.entity.Project;
import org.apache.airavata.research.service.model.entity.Session;
import org.apache.airavata.research.service.model.repo.SessionRepository;
diff --git a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/UserContext.java b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/UserContext.java
deleted file mode 100644
index b6c1b52887..0000000000
--- a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/UserContext.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
-*
-* 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.airavata.research.service.model;
-
-import org.apache.airavata.model.security.AuthzToken;
-import org.apache.airavata.model.user.UserProfile;
-
-public class UserContext {
-
- private static final ThreadLocal<AuthzToken> AUTHZ_TOKEN = new ThreadLocal<>();
- private static final ThreadLocal<UserProfile> CURRENT_USER = new ThreadLocal<>();
-
- public static AuthzToken authzToken() {
- return AUTHZ_TOKEN.get();
- }
-
- public static void setAuthzToken(AuthzToken token) {
- AUTHZ_TOKEN.set(token);
- }
-
- public static UserProfile user() {
- return CURRENT_USER.get();
- }
-
- public static void setUser(UserProfile user) {
- CURRENT_USER.set(user);
- }
-
- public static String userId() {
- return CURRENT_USER.get().getUserId();
- }
-
- public static String gatewayId() {
- return CURRENT_USER.get().getGatewayId();
- }
-
- public static boolean isAuthenticated() {
- return AUTHZ_TOKEN.get() != null;
- }
-
- public static void clear() {
- AUTHZ_TOKEN.remove();
- CURRENT_USER.remove();
- }
-}
diff --git a/modules/research-framework/research-service/src/main/resources/application.yml b/modules/research-framework/research-service/src/main/resources/application.yml
deleted file mode 100644
index 64657d99e0..0000000000
--- a/modules/research-framework/research-service/src/main/resources/application.yml
+++ /dev/null
@@ -1,76 +0,0 @@
-# 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.
-#
-
-grpc:
- server:
- port: 19908
-
-server:
- port: 18889
- address: localhost
-
-airavata:
- research-hub:
- url: http://localhost:20000
- dev-user: "airavata@apache.org"
- adminApiKey: "JUPYTER_ADMIN_API_KEY"
- limit: 10
- research-portal:
- url: http://localhost:5173
- dev-url: http://localhost:5173
- openid:
- url: "http://localhost:18080/realms/default"
- user-profile:
- server:
- url: localhost
- port: 8930
-
-spring:
- servlet:
- multipart:
- max-file-size: 200MB
- max-request-size: 200MB
- datasource:
- url: "jdbc:mariadb://localhost:13306/airavata"
- username: "airavata"
- password: "123456"
- driver-class-name: org.mariadb.jdbc.Driver
- hikari:
- pool-name: ResearchCatalogPool
- leak-detection-threshold: 20000
- jpa:
- hibernate:
- ddl-auto: update
- open-in-view: false
-
-springdoc:
- api-docs:
- enabled: true
- swagger-ui:
- path: /swagger-ui.html
- operationsSorter: alpha
- tagsSorter: alpha
- doc-expansion: none
- oauth:
- use-pkce-with-authorization-code-grant: true
- client-id: data-catalog-portal
-
-management:
- endpoints:
- web:
- exposure:
- include: health
-