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

Enhance example and docs and upgrade Elide #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
520 changes: 508 additions & 12 deletions README.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.2</version>
<version>3.3.4</version>
</parent>

<properties>
Expand All @@ -25,12 +25,12 @@
<jar.finalName>elide-spring-boot</jar.finalName>
<java.version>17</java.version>

<elide.version>7.1.0</elide.version>
<elide.version>7.1.2</elide.version>

<springdoc.version>2.6.0</springdoc.version>
<logback-access-spring-boot-starter.version>4.2.2</logback-access-spring-boot-starter.version>
<logback-access-spring-boot-starter.version>4.3.0</logback-access-spring-boot-starter.version>

<maven-surefire-plugin.version>3.3.1</maven-surefire-plugin.version>
<maven-surefire-plugin.version>3.5.0</maven-surefire-plugin.version>
</properties>

<dependencyManagement>
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/example/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ImportRuntimeHints;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
Expand All @@ -20,7 +19,6 @@
* Example app using elide-spring.
*/
@SpringBootApplication
@EntityScan
@ImportRuntimeHints(AppRuntimeHints.class)
@OpenAPIDefinition(info = @Info(title = "My Title"), security = @SecurityRequirement(name = "bearerAuth"))
@SecurityScheme(
Expand Down
36 changes: 0 additions & 36 deletions src/main/java/example/OpenApiConfiguration.java

This file was deleted.

45 changes: 45 additions & 0 deletions src/main/java/example/config/AppSecurityProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2020, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/

package example.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

import lombok.Data;

/**
* Configuration properties for application security.
*/
@Data
@ConfigurationProperties(prefix = "app.security")
public class AppSecurityProperties {
/**
* Whether to enable security.
*/
private boolean enabled = false;

/**
* A list of origins for which cross-origin requests are allowed.
*/
private String origin = "*";

/**
* For demonstration purposes.
*/
@Data
public static class IdObfuscation {
/**
* Turns on/off id obfuscation.
*/
private boolean enabled = false;

private String password = "";

private String salt = "";
}

private IdObfuscation idObfuscation = new IdObfuscation();
}
109 changes: 109 additions & 0 deletions src/main/java/example/config/ElideConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package example.config;

import java.util.HashMap;
import java.util.Map;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.security.crypto.encrypt.AesBytesEncryptor;

import com.yahoo.elide.core.security.obfuscation.IdObfuscator;
import com.yahoo.elide.spring.datastore.config.DataStoreBuilderCustomizer;
import com.yahoo.elide.spring.security.obfuscation.BytesEncryptorIdObfuscator;

import example.datastore.OperationDataStore;
import example.datastore.SpringDataDataStore;
import example.exception.TransactionExceptionMapper;
import example.model.ArtifactGroupPage;
import example.model.ArtifactGroupStream;
import example.model.Mail;
import example.repository.ArtifactGroupRepository;
import example.service.JacksonSpringDataCursorEncoder;
import example.service.QueryService;
import example.service.SpringDataCursorEncoder;
import jakarta.validation.Validator;

/**
* Configuration for Elide.
*/
@Configuration
@EnableConfigurationProperties(AppSecurityProperties.class)
public class ElideConfiguration {
/**
* Creates the {@link OperationDataStore}.
*
* @return the builder
*/
@Bean
DataStoreBuilderCustomizer operationDataStoreBuilderCustomizer(Validator validator) {
return builder -> {
builder.dataStore(new OperationDataStore(validator, Mail.class));
};
}

/**
* Creates the {@link SpringDataDataStore}.
*
* @return the builder
*/
@Bean
DataStoreBuilderCustomizer springDataDataStoreBuilderCustomizer(QueryService queryService,
SpringDataCursorEncoder cursorEncoder) {
return builder -> {
builder.dataStore(new SpringDataDataStore(queryService, cursorEncoder));
};
}

/**
* Creates the {@link QueryService}.
*
* @return the service
*/
@Bean
QueryService queryService(ArtifactGroupRepository artifactGroupRepository) {
Map<Class<?>, JpaSpecificationExecutor<?>> repositories = new HashMap<>();
repositories.put(ArtifactGroupStream.class, artifactGroupRepository);
repositories.put(ArtifactGroupPage.class, artifactGroupRepository);
return new QueryService(repositories);
}

/**
* Creates the {@link SpringDataCursorEncoder}.
*
* @return the cursor encoder
*/
@Bean
SpringDataCursorEncoder springDataCursorEncoder() {
return new JacksonSpringDataCursorEncoder();
}

/**
* Configures a id obfuscator.
*
* For demonstration purposes.
*
* @param securityConfigProperties the configuration
* @return the id obfuscator
*/
@Bean
@ConditionalOnProperty(prefix = "app.security.id-obfuscation", name = "enabled", havingValue = "true")
IdObfuscator idObfuscator(AppSecurityProperties securityConfigProperties) {
String password = securityConfigProperties.getIdObfuscation().getPassword();
String salt = securityConfigProperties.getIdObfuscation().getSalt();
AesBytesEncryptor bytesEncryptor = new AesBytesEncryptor(password, salt);
return new BytesEncryptorIdObfuscator(bytesEncryptor);
}

/**
* Configures an exception mapper.
*
* @return the exception mapper
*/
@Bean
TransactionExceptionMapper transactionExceptionMapper() {
return new TransactionExceptionMapper();
}
}
36 changes: 36 additions & 0 deletions src/main/java/example/config/OpenApiConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package example.config;

import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* OpenApiConfiguration.
*/
@Configuration
public class OpenApiConfiguration {
@Bean
GroupedOpenApi api() {
return GroupedOpenApi.builder()
.group("default")
.pathsToMatch("/**")
.pathsToExclude("/api/v1/**", "/api/v2/**")
.build();
}

@Bean
GroupedOpenApi apiV1() {
return GroupedOpenApi.builder()
.group("v1")
.pathsToMatch("/api/v1/**")
.build();
}

@Bean
GroupedOpenApi apiV2() {
return GroupedOpenApi.builder()
.group("v2")
.pathsToMatch("/api/v2/**")
.build();
}
}
17 changes: 0 additions & 17 deletions src/main/java/example/config/SecurityConfigProperties.java

This file was deleted.

Loading