Skip to content

Commit

Permalink
Optimize required dependencies for modules (#3255)
Browse files Browse the repository at this point in the history
* Update dependency scopes

* Add JmsDataStoreConfiguration

* Update scopes

* Remove required dependency on spring security
  • Loading branch information
justin-tay authored Jul 28, 2024
1 parent 1fc5258 commit c68e373
Show file tree
Hide file tree
Showing 16 changed files with 319 additions and 183 deletions.
7 changes: 7 additions & 0 deletions elide-async/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,17 @@
</scm>

<dependencies>
<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-core</artifactId>
<version>7.1.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-graphql</artifactId>
<version>7.1.1-SNAPSHOT</version>
<scope>optional</scope>
</dependency>

<dependency>
Expand Down
61 changes: 56 additions & 5 deletions elide-core/src/main/java/com/yahoo/elide/core/security/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,76 @@
*/
package com.yahoo.elide.core.security;

import lombok.Getter;

import java.security.Principal;
import java.util.Objects;

/**
* Wrapper for opaque user passed in every request.
* The user associated with the request.
*/
public class User {
@Getter private final Principal principal;
private final Principal principal;

/**
* Constructor.
*
* @param principal the authenticated user
*/
public User(Principal principal) {
this.principal = principal;
}

/**
* Gets the user principal of the authenticated user.
*
* @param <T> the type of principal
* @return the principal
*/
@SuppressWarnings("unchecked")
public <T extends Principal> T getPrincipal() {
return (T) this.principal;
}

/**
* Gets the name of the authenticated user.
*
* @return the name of the authenticated user
*/
public String getName() {
return principal != null ? principal.getName() : null;
return this.principal != null ? this.principal.getName() : null;
}

/**
* Returns whether the authenticated user has the specified role.
*
* @param role the role to check for
* @return true if the authenticated user has the role
*/
public boolean isInRole(String role) {
return false;
}

@Override
public String toString() {
return "User [principal=" + principal + "]";
}

@Override
public int hashCode() {
return Objects.hash(principal);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
User other = (User) obj;
return Objects.equals(principal, other.principal);
}
}
2 changes: 2 additions & 0 deletions elide-datastore/elide-datastore-aggregation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@
<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-graphql</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-datastore-multiplex</artifactId>
<version>7.1.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>

<dependency>
Expand Down
4 changes: 4 additions & 0 deletions elide-datastore/elide-datastore-jms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-client-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.jms</groupId>
<artifactId>jakarta.jms-api</artifactId>
Expand Down
7 changes: 6 additions & 1 deletion elide-graphql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,23 @@
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-extended-scalars</artifactId>
</dependency>
<!-- javadoc -->
<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- com.yahoo.elide.graphql.subscriptions.websocket -->
<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-client-api</artifactId>
<scope>provided</scope>
</dependency>

<!-- com.yahoo.elide.graphql.subscriptions.hooks -->
<dependency>
<groupId>jakarta.jms</groupId>
<artifactId>jakarta.jms-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
Expand Down
11 changes: 10 additions & 1 deletion elide-quarkus/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<version>7.1.1-SNAPSHOT</version>
<artifactId>elide-quarkus-extension-parent</artifactId>
<packaging>pom</packaging>
<name>Elide Quarkus Extension - Parent</name>
Expand Down Expand Up @@ -69,6 +68,11 @@
<artifactId>elide-core</artifactId>
<version>${elide.version}</version>
</dependency>
<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-graphql</artifactId>
<version>${elide.version}</version>
</dependency>
<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-datastore-aggregation</artifactId>
Expand All @@ -79,6 +83,11 @@
<artifactId>elide-datastore-jpa</artifactId>
<version>${elide.version}</version>
</dependency>
<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-datastore-multiplex</artifactId>
<version>${elide.version}</version>
</dependency>
<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-swagger</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions elide-quarkus/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-core</artifactId>
</dependency>
<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-graphql</artifactId>
</dependency>
<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-datastore-aggregation</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,8 @@ public static class ApiDocsConfiguration {
public ApiDocsController.ApiDocsRegistrations apiDocsRegistrations(RefreshableElide elide,
ElideConfigProperties settings, ServerProperties serverProperties,
OpenApiDocumentCustomizer customizer) {
return buildApiDocsRegistrations(elide, settings, serverProperties.getServlet().getContextPath(),
customizer);
return ApiDocs.buildApiDocsRegistrations(elide, settings,
serverProperties.getServlet().getContextPath(), customizer);
}

@Bean
Expand Down Expand Up @@ -804,8 +804,8 @@ public static class ApiDocsConfiguration {
public ApiDocsController.ApiDocsRegistrations apiDocsRegistrations(RefreshableElide elide,
ElideConfigProperties settings, ServerProperties serverProperties,
OpenApiDocumentCustomizer customizer) {
return buildApiDocsRegistrations(elide, settings, serverProperties.getServlet().getContextPath(),
customizer);
return ApiDocs.buildApiDocsRegistrations(elide, settings,
serverProperties.getServlet().getContextPath(), customizer);
}

@Bean
Expand Down Expand Up @@ -1162,58 +1162,65 @@ public static RefreshableElide buildRefreshableElide(ElideSettingsBuilder elideS
return new RefreshableElide(elide);
}

public static ApiDocsController.ApiDocsRegistrations buildApiDocsRegistrations(RefreshableElide elide,
ElideConfigProperties settings, String contextPath, OpenApiDocumentCustomizer customizer) {
String jsonApiPath = settings.getJsonApi() != null ? settings.getJsonApi().getPath() : "";

EntityDictionary dictionary = elide.getElide().getElideSettings().getEntityDictionary();

List<ApiDocsRegistration> registrations = new ArrayList<>();
dictionary.getApiVersions().stream().forEach(apiVersion -> {
Supplier<OpenAPI> document = () -> {
OpenApiBuilder builder = new OpenApiBuilder(dictionary, openApi -> {
if (ApiDocsControllerProperties.Version.OPENAPI_3_1.equals(settings.getApiDocs().getVersion())) {
openApi.specVersion(SpecVersion.V31).openapi("3.1.0");
/**
* ApiDocs holder class to make swagger optional.
*/
public static class ApiDocs {
public static ApiDocsController.ApiDocsRegistrations buildApiDocsRegistrations(RefreshableElide elide,
ElideConfigProperties settings, String contextPath, OpenApiDocumentCustomizer customizer) {
String jsonApiPath = settings.getJsonApi() != null ? settings.getJsonApi().getPath() : "";

EntityDictionary dictionary = elide.getElide().getElideSettings().getEntityDictionary();

List<ApiDocsRegistration> registrations = new ArrayList<>();
dictionary.getApiVersions().stream().forEach(apiVersion -> {
Supplier<OpenAPI> document = () -> {
OpenApiBuilder builder = new OpenApiBuilder(dictionary, openApi -> {
if (ApiDocsControllerProperties.Version.OPENAPI_3_1
.equals(settings.getApiDocs().getVersion())) {
openApi.specVersion(SpecVersion.V31).openapi("3.1.0");
}
}).apiVersion(apiVersion).supportLegacyFilterDialect(false);
if (!EntityDictionary.NO_VERSION.equals(apiVersion)) {
if (settings.getApiVersioningStrategy().getPath().isEnabled()) {
// Path needs to be set
builder.basePath("/" + settings.getApiVersioningStrategy().getPath().getVersionPrefix()
+ apiVersion);
} else if (settings.getApiVersioningStrategy().getHeader().isEnabled()) {
// Header needs to be set
builder.globalParameter(new Parameter().in("header")
.name(settings.getApiVersioningStrategy().getHeader().getHeaderName()[0])
.required(true)
.schema(new StringSchema().addEnumItem(apiVersion)));
} else if (settings.getApiVersioningStrategy().getParameter().isEnabled()) {
// Header needs to be set
builder.globalParameter(new Parameter().in("query")
.name(settings.getApiVersioningStrategy().getParameter().getParameterName())
.required(true).schema(new StringSchema().addEnumItem(apiVersion)));
}
}
}).apiVersion(apiVersion).supportLegacyFilterDialect(false);
if (!EntityDictionary.NO_VERSION.equals(apiVersion)) {
if (settings.getApiVersioningStrategy().getPath().isEnabled()) {
// Path needs to be set
builder.basePath(
"/" + settings.getApiVersioningStrategy().getPath().getVersionPrefix() + apiVersion);
} else if (settings.getApiVersioningStrategy().getHeader().isEnabled()) {
// Header needs to be set
builder.globalParameter(new Parameter().in("header")
.name(settings.getApiVersioningStrategy().getHeader().getHeaderName()[0]).required(true)
.schema(new StringSchema().addEnumItem(apiVersion)));
} else if (settings.getApiVersioningStrategy().getParameter().isEnabled()) {
// Header needs to be set
builder.globalParameter(new Parameter().in("query")
.name(settings.getApiVersioningStrategy().getParameter().getParameterName())
.required(true).schema(new StringSchema().addEnumItem(apiVersion)));
String url = contextPath != null ? contextPath : "";
url = url + jsonApiPath;
if (url.isBlank()) {
url = "/";
}
}
String url = contextPath != null ? contextPath : "";
url = url + jsonApiPath;
if (url.isBlank()) {
url = "/";
}
OpenAPI openApi = builder.build();
openApi.addServersItem(new Server().url(url));
if (!EntityDictionary.NO_VERSION.equals(apiVersion)) {
Info info = openApi.getInfo();
if (info == null) {
info = new Info();
openApi.setInfo(info);
OpenAPI openApi = builder.build();
openApi.addServersItem(new Server().url(url));
if (!EntityDictionary.NO_VERSION.equals(apiVersion)) {
Info info = openApi.getInfo();
if (info == null) {
info = new Info();
openApi.setInfo(info);
}
info.setVersion(apiVersion);
}
info.setVersion(apiVersion);
}
customizer.customize(openApi);
return openApi;
};
registrations.add(new ApiDocsRegistration("", SingletonSupplier.of(document), apiVersion));
});
return new ApiDocsController.ApiDocsRegistrations(registrations);
customizer.customize(openApi);
return openApi;
};
registrations.add(new ApiDocsRegistration("", SingletonSupplier.of(document), apiVersion));
});
return new ApiDocsController.ApiDocsRegistrations(registrations);
}
}

/**
Expand Down
Loading

0 comments on commit c68e373

Please sign in to comment.