Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Im 457 merge develop in im 384 #216

Merged
merged 44 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
33159dc
Merge branch 'develop' into IM-457-Merge-develop-in-IM-384
kristinaBc3 Oct 17, 2024
5313679
IM-457 Merge hub authentication changes into develop
kristinaBc3 Oct 17, 2024
92da5b1
IM-457 Add missing pom.xml file to the repository. Accidentally omitt…
kristinaBc3 Oct 18, 2024
ab9705d
Merge branch 'IM-457-Merge-develop-in-IM-384' of github.com:integrate…
kristinaBc3 Oct 22, 2024
1d64b66
IM-459 feat: add support for multiple WebSecurity configurations base…
kristinaBc3 Oct 22, 2024
74173ce
IM-457 fix: retrieve username correctly from Keycloak SecurityContext…
kristinaBc3 Oct 22, 2024
073b38f
Merge branch 'develop' into IM-457-Merge-develop-in-IM-384
kristinaBc3 Oct 28, 2024
acee3cc
IM-384 refactor: remove unnecessary @Order annotation and adjust secu…
kristinaBc3 Oct 28, 2024
6016ad9
Merge branch 'IM-459-New-Configure-keycloak-in-remote-engine' into IM…
kristinaBc3 Oct 28, 2024
f8cb2dd
Merge branch 'IM-457-Merge-develop-in-IM-384' into IM-459-New-Configu…
kristinaBc3 Oct 28, 2024
63a50fa
IM-459 feat: Working on OAuth2 adapter roles and add API for env vari…
kristinaBc3 Nov 12, 2024
86f1587
Merge branch 'develop' into IM-459-New-Configure-keycloak-in-remote-e…
kristinaBc3 Nov 12, 2024
d03ff16
IM-459 feat: Add filters to OAuth2 adapter to set user in Authenticat…
kristinaBc3 Nov 14, 2024
f576510
Merge branch 'develop' into IM-457-Merge-develop-in-IM-384
kristinaBc3 Nov 14, 2024
b1e1386
Merge branch 'IM-457-Merge-develop-in-IM-384' into IM-459-New-Configu…
kristinaBc3 Nov 14, 2024
9f69087
IM-459 Use Klab_Authorization header instead Authorization and add se…
kristinaBc3 Nov 20, 2024
1c64fea
IM-459 Delete password from RemoteUserAuthenticationRequest and allow…
kristinaBc3 Nov 20, 2024
e0dcde1
Merge branch 'IM-457-Merge-develop-in-IM-384' of github.com:integrate…
kristinaBc3 Nov 20, 2024
182ab89
Merge remote-tracking branch 'origin/IM-459-New-Configure-keycloak-in…
kristinaBc3 Nov 20, 2024
7dc7978
Merge branch 'develop' into IM-457-Merge-develop-in-IM-384
kristinaBc3 Nov 22, 2024
af71039
IM-457 Changes after merge develop
kristinaBc3 Nov 23, 2024
7fe7364
IM-457 Problems with @Secured(Roles.SESSION)
kristinaBc3 Nov 23, 2024
fd80fa6
IM-457 Add klab_Authorization to EnginePublicController
kristinaBc3 Nov 23, 2024
5de28d0
IM-457 Add auditory fields to Agreement.java
kristinaBc3 Nov 23, 2024
50b1603
IM-457 fix: Fix error (setPassword) not exists
kristinaBc3 Nov 23, 2024
5e502e7
IM-457 feat: add Roles.SESSION in WebSecurityContext to allow session…
kristinaBc3 Nov 25, 2024
2f77434
IM-457 Fix error and clean code
kristinaBc3 Nov 26, 2024
a105232
IM-457 Add k.hub.frontend changes
kristinaBc3 Nov 29, 2024
5b9f87b
IM-457 feat: Add k.engine.frontend and k.explorer to klab
kristinaBc3 Nov 29, 2024
cb4e18b
IM-457 Add Authorization header tu hubToken method
kristinaBc3 Dec 2, 2024
509045e
IM-457 Add activeProfile to environments controlles to use in k.explorer
kristinaBc3 Dec 2, 2024
8e24001
Add k.explorer frontend changes
kristinaBc3 Dec 2, 2024
819e787
IM-457 Add k.Hub frontend changes
kristinaBc3 Dec 2, 2024
ede5b75
IM-457 Add EngineProperties to Modeler. Manage activeProfiles.
kristinaBc3 Dec 4, 2024
fe76935
IM-457 Add logger to try to see an error and format files. docker build
kristinaBc3 Dec 10, 2024
5a7bef3
IM-502 refactor: replace Klab_Authorization with klab-authorization
kristinaBc3 Dec 11, 2024
ad5e3b9
IM-502 Add k.explorer changes
kristinaBc3 Dec 11, 2024
79bac61
IM-502 Avoid keycloak account API call error in k.engine
kristinaBc3 Dec 12, 2024
3d60745
IM-502 Avoid keycloak account API call error in k.engine
kristinaBc3 Dec 12, 2024
9446faf
IM-502 Fix k.explorer logout URI
kristinaBc3 Dec 12, 2024
ac7c89b
Merge branch 'IM-502-Error-in-K.Explorer-while-trying-to-perform-logg…
kristinaBc3 Dec 12, 2024
765c9d8
IM-457 Clean code in WebSecurityConfig
kristinaBc3 Dec 12, 2024
c361dc3
Merge remote-tracking branch 'origin/develop' into IM-457-Merge-devel…
kristinaBc3 Dec 16, 2024
6c3a35c
IM-457 Fix conflicts in develop merge. Prevent recharging pages befor…
kristinaBc3 Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ public static interface HUB {
* Base URL path for custom properties related to a single user.
*/
public static final String USER_ID_CUSTOM_PROPERTIES = USER_BASE_ID + "/custom-properties";
/**
* URL path for get SPA pages
*/
public static final String UI = "/ui/*";

public static interface PARAMETERS {
/**
Expand Down Expand Up @@ -1279,6 +1283,11 @@ public interface VIEW {
}

}

/**
* URL path for get SPA pages
*/
public static final String UI = "/ui/*";

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.integratedmodelling.klab.api.auth;

/**
* Defines constants for common HTTP headers.
*
* <p>This interface provides a set of predefined header names used
* in HTTP requests and responses. These constants can be used to
* avoid hardcoding string values and reduce errors.</p>
*
* @author Kristina
*/

public interface KlabHttpHeaders {

/**
* Designed to send session information with requests.
**/
public static final String KLAB_AUTHORIZATION = "klab-authorization";

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
*/
public class RemoteUserAuthenticationRequest extends UserAuthenticationRequest {

private String token;
/**
private String token;
/**
* @return the token
*/
public String getToken() {
Expand Down Expand Up @@ -47,6 +47,6 @@ public boolean equals(Object obj) {

@Override
public String toString() {
return "RemoteUserAuthenticationRequest [username=" + getUsername() + ", password=" + getPassword() + ", token="+getToken()+"]";
return "RemoteUserAuthenticationRequest [username=" + getUsername() + ", token="+getToken()+"]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,18 @@

public class UserAuthenticationRequest {

private String username;
private String password;
private boolean remote = false;
private String username;

public String getUsername() {
return username;
}
private boolean remote = false;

public void setUsername(String username) {
public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public boolean isRemote() {
return remote;
}
Expand All @@ -34,7 +26,7 @@ public void setRemote(boolean jwtToken) {

@Override
public int hashCode() {
return Objects.hash(remote, password, username);
return Objects.hash(remote, username);
}

@Override
Expand All @@ -46,12 +38,12 @@ public boolean equals(Object obj) {
return false;
}
UserAuthenticationRequest other = (UserAuthenticationRequest) obj;
return remote == other.remote && Objects.equals(password, other.password) && Objects.equals(username, other.username);
return remote == other.remote && Objects.equals(username, other.username);
}

@Override
public String toString() {
return "UserAuthenticationRequest [username=" + username + ", password=" + password + ", remote=" + remote + "]";
return "UserAuthenticationRequest [username=" + username + ", remote=" + remote + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static String getSessionTokenForDefaultAdministrator(int port) throws URI
URI uri = new URI(baseUrl);
HttpHeaders headers = new HttpHeaders();
UserAuthenticationRequest auth= new UserAuthenticationRequest();
auth.setPassword("password");

auth.setUsername("system");
HttpEntity<?> request = new HttpEntity<>(auth, headers);
RestTemplate restTemplate = new RestTemplate();
Expand Down
16 changes: 15 additions & 1 deletion klab.engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,21 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-resource-server</artifactId>
<version>${spring-security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
<version>${spring-security.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>org.integratedmodelling</groupId>
Expand All @@ -573,7 +588,6 @@
<artifactId>jopt-simple </artifactId>
<version>4.6</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.eclipse.xtext/org.eclipse.xtext -->
<dependency>
<groupId>org.eclipse.xtext</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.integratedmodelling.klab.engine.rest.api;

import javax.validation.constraints.NotEmpty;


import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

@Component
@ConfigurationProperties("engine")
public class EngineProperties {

public EnvProperties env;

public EnvProperties getEnv() {
return env;
}

public void setEnv(EnvProperties env) {
this.env = env;
}

@Validated
public static class EnvProperties {

@NotEmpty
private String appBaseUrl;

@NotEmpty
private String keycloakUrl;

public String getAppBaseUrl() {
return appBaseUrl;
}

public void setAppBaseUrl(String appBaseUrl) {
this.appBaseUrl = appBaseUrl;
}

public String getKeycloakUrl() {
return keycloakUrl;
}

public void setKeycloakUrl(String keycloakUrl) {
this.keycloakUrl = keycloakUrl;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.integratedmodelling.klab.engine.rest.controllers.base;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.integratedmodelling.klab.engine.rest.api.EngineProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.ObjectMapper;

@RestController
public class EnvironmentController {

@Autowired
private EngineProperties engineProperties;

private static final String APP_BASE_URL = "APP_BASE_URL";
private static final String KEYCLOAK_URL = "KEYCLOAK_URL";
private static final String ACTIVE_PROFILE = "ACTIVE_PROFILE";

private static final String ENGINE_REMOTE = "engine.remote";
private static final String ENGINE_LOCAL = "engine.local";

@GetMapping(value = "/engine/environments")
public void getEnvironmentVariables(HttpServletRequest request, HttpServletResponse response) throws IOException {

response.setContentType("text/javascript;utf-8");

List<String> activeProfiles = Pattern.compile(",").splitAsStream(System.getProperty("spring.profiles.active", "unknown"))
.collect(Collectors.toList());

String activeProfile = activeProfiles.contains(ENGINE_REMOTE) ? ENGINE_REMOTE : ENGINE_LOCAL;

/*
* Get engine properties
*/
Map<String, String> kHubEnvironmentVariables = new HashMap<>();

if (activeProfile.equals(ENGINE_REMOTE)) {
kHubEnvironmentVariables = Map.ofEntries(Map.entry(APP_BASE_URL, engineProperties.env.getAppBaseUrl()),
Map.entry(KEYCLOAK_URL, engineProperties.env.getKeycloakUrl()), Map.entry(ACTIVE_PROFILE, activeProfile));
} else {
kHubEnvironmentVariables = Map.ofEntries(Map.entry(ACTIVE_PROFILE, activeProfile));
}

ObjectMapper objectMapper = new ObjectMapper();
String jsonValue = objectMapper.writeValueAsString(kHubEnvironmentVariables);

System.out.println(jsonValue);

response.getWriter().append("var __ENV__= " + jsonValue + ";");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
*/
@RestController
@CrossOrigin(origins = "*")
@Secured(Roles.PUBLIC)
//@Secured(Roles.PUBLIC)
public class KlabController {

@RequestMapping(value = API.ENGINE.RESOURCE.GET_PROJECT_RESOURCE, method = RequestMethod.GET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.integratedmodelling.klab.api.API;
import org.integratedmodelling.klab.api.PublicAPI;
import org.integratedmodelling.klab.api.auth.IUserIdentity;
import org.integratedmodelling.klab.api.auth.KlabHttpHeaders;
import org.integratedmodelling.klab.api.auth.Roles;
import org.integratedmodelling.klab.api.data.ILocator;
import org.integratedmodelling.klab.api.data.adapters.IResourceAdapter;
Expand Down Expand Up @@ -60,6 +61,7 @@
import org.integratedmodelling.klab.utils.NumberUtils;
import org.springframework.http.MediaType;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -79,8 +81,8 @@ public class EnginePublicController implements API.PUBLIC {
@RequestMapping(value = CREATE_CONTEXT, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public TicketResponse.Ticket contextRequest(@RequestBody ContextRequest request,
@RequestHeader(name = "Authorization") String session) {

@RequestHeader(name = KlabHttpHeaders.KLAB_AUTHORIZATION) String session) {
Session s = Authentication.INSTANCE.getIdentity(session, Session.class);
if (s == null) {
throw new KlabIllegalStateException("create context: invalid session ID");
Expand Down Expand Up @@ -109,7 +111,7 @@ public TicketResponse.Ticket contextRequest(@RequestBody ContextRequest request,
@RequestMapping(value = OBSERVE_IN_CONTEXT, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public TicketResponse.Ticket observationRequest(@RequestBody ObservationRequest request,
@RequestHeader(name = "Authorization") String session, @PathVariable String context) {
@RequestHeader(name = KlabHttpHeaders.KLAB_AUTHORIZATION) String session, @PathVariable String context) {

Session s = Authentication.INSTANCE.getIdentity(session, Session.class);

Expand Down Expand Up @@ -143,7 +145,7 @@ public TicketResponse.Ticket observationRequest(@RequestBody ObservationRequest

@RequestMapping(value = SUBMIT_ESTIMATE, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public TicketResponse.Ticket submitEstimate(@RequestHeader(name = "Authorization") String session,
public TicketResponse.Ticket submitEstimate(@RequestHeader(name = KlabHttpHeaders.KLAB_AUTHORIZATION) String session,
@PathVariable String estimate) {

Session s = Authentication.INSTANCE.getIdentity(session, Session.class);
Expand All @@ -163,6 +165,7 @@ public TicketResponse.Ticket submitEstimate(@RequestHeader(name = "Authorization
}

if (est.contextRequest != null) {
//TODO only 1 sessioin parameter
return contextRequest(est.contextRequest, session);
}

Expand All @@ -173,11 +176,11 @@ public TicketResponse.Ticket submitEstimate(@RequestHeader(name = "Authorization
MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_PDF_VALUE, MediaType.IMAGE_PNG_VALUE, "text/csv", "image/tiff",
"application/vnd.ms-excel", "application/octet-stream",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})
public void exportData(@PathVariable String export, @RequestHeader(name = "Authorization") String session,
public void exportData(@PathVariable String export, @RequestHeader(name = KlabHttpHeaders.KLAB_AUTHORIZATION) String session,
@PathVariable String observation, @RequestHeader(name = "Accept") String format,
@RequestParam(required = false) String view, @RequestParam(required = false) String viewport,
@RequestParam(required = false) String locator, HttpServletResponse response) throws IOException {

Session s = Authentication.INSTANCE.getIdentity(session, Session.class);
if (s == null) {
throw new KlabIllegalStateException("observe in context: invalid session ID");
Expand Down Expand Up @@ -385,7 +388,7 @@ private void outputImage(IObservation obs, HttpServletResponse response, Export

@RequestMapping(value = TICKET_INFO, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public TicketResponse.Ticket getTicketInfo(@RequestHeader(name = "Authorization") String session,
public TicketResponse.Ticket getTicketInfo(@RequestHeader(name = KlabHttpHeaders.KLAB_AUTHORIZATION) String session,
@PathVariable String ticket) {

Session s = Authentication.INSTANCE.getIdentity(session, Session.class);
Expand Down
Loading