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

Feature/574 api data provider #586

Merged
merged 2 commits into from
May 21, 2024
Merged
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
1 change: 0 additions & 1 deletion api-rest/src/main/resources/application-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ app:
url: jdbc:postgresql://localhost:5432/homidb
username: homi2022
password: homi2022
schemas:
connectionProperties:
ssl: false
envProperties: # Not used yet
Expand Down
9 changes: 5 additions & 4 deletions api-rest/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
app:
version: 1.0.0-SNAPSHOT
name: db2rest
version: @project.version@
name: @project.name@


server:
Expand Down Expand Up @@ -40,8 +40,9 @@ db2rest:
- a
- b
data:
file: ${user.home}/git/db2rest/auth/auth-sample.yml
api-endpoint:
# file: ${user.home}/git/db2rest/auth/auth-sample.yml
api-endpoint: 'https://api.npoint.io/25e777e70e3a62289dc7'
api-key: 123

unKeyDev:
enabled: ${UNKEY_DEV_ENABLED:false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.homihq.db2rest.auth.jwt.JwtAuthProvider;
import com.homihq.db2rest.auth.jwt.JwtProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -20,20 +21,23 @@

import java.util.List;

@Slf4j
@Configuration
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "db2rest.auth", name="enabled" , havingValue = "true")
public class AuthConfiguration {

private final JwtProperties jwtProperties;


@Bean("authAntPathMatcher")
public AntPathMatcher authAntPathMatcher() {
return new AntPathMatcher();
}

@Bean
public AuthFilter authFilter(AuthDataProperties authDataProperties, ObjectMapper objectMapper) {
log.info("** Auth enabled. Initializing auth components.");
List<AbstractAuthProvider> authProviders = List.of(jwtAuthProvider(authDataProperties));

return new AuthFilter(authProviders, objectMapper);
Expand All @@ -55,11 +59,14 @@ public JwtAuthProvider jwtAuthProvider(AuthDataProperties authDataProperties) {
public AuthDataProvider authDataProvider(AuthDataProperties authDataProperties) {

if(authDataProperties.isFileProvider()) {
log.info("Initializing file auth data provider");
return new FileAuthDataProvider(authDataProperties.getFile());
}
else if(authDataProperties.isFileProvider()){
else if(authDataProperties.isApiDataProvider()){
log.info("Initializing API auth data provider");
return new ApiAuthDataProvider(authDataProperties.getApiEndpoint(), authDataProperties.getApiKey());
}
log.info("No auth data provider");
return new NoAuthdataProvider();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ public ApiAuthDataProvider(String apiEndPoint, String apiKey) {
.build();

authDataSource =
restClient.post()
restClient.get()
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.body(AuthDataSource.class);

log.info("Auth data - {}", authDataSource);
}

@Override
Expand Down
Loading