-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FINERACT-2021: refactor the note GET end-points to eliminate manual s…
…erialization with GSON. - Implemented a new custom module for the note API. - Used Spring Web-MVC annotations instead of JAX-RS. - Dispensed the redundant query parameters like "fields, prettyPrint ..etc" - Implemented a new `CommonWebConfiguration` for establishing the security configurations (not complete yet). - Implemented configuration modules (core, starter, configuration) for configuring the note module. - Implemented a new `docker-compose-api-v3.yml` configuration file.
- Loading branch information
Showing
22 changed files
with
681 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
description = 'The new generation of the API layer (v3): Common Configuration' | ||
|
||
group = 'org.apache.fineract.v3.common' | ||
|
||
archivesBaseName = 'fineract-custom-common-configuration' | ||
|
||
apply from: 'dependencies.gradle' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
dependencies { | ||
implementation(project(':fineract-core')) | ||
implementation(project(':fineract-provider')) | ||
implementation('org.springframework.boot:spring-boot-starter-web') | ||
implementation('org.springframework.boot:spring-boot-starter-security') | ||
compileOnly('org.springframework.boot:spring-boot-autoconfigure') | ||
} |
129 changes: 129 additions & 0 deletions
129
...ion/src/main/java/org/apache/fineract/v3/common/configuration/CommonWebConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/** | ||
* 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.fineract.v3.common.configuration; | ||
|
||
import static org.springframework.security.web.util.matcher.AntPathRequestMatcher.antMatcher; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.fineract.infrastructure.businessdate.service.BusinessDateReadPlatformService; | ||
import org.apache.fineract.infrastructure.cache.service.CacheWritePlatformService; | ||
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; | ||
import org.apache.fineract.infrastructure.core.config.FineractProperties; | ||
import org.apache.fineract.infrastructure.core.domain.FineractRequestContextHolder; | ||
import org.apache.fineract.infrastructure.core.filters.CorrelationHeaderFilter; | ||
import org.apache.fineract.infrastructure.core.filters.IdempotencyStoreFilter; | ||
import org.apache.fineract.infrastructure.core.filters.IdempotencyStoreHelper; | ||
import org.apache.fineract.infrastructure.core.filters.RequestResponseFilter; | ||
import org.apache.fineract.infrastructure.core.serialization.ToApiJsonSerializer; | ||
import org.apache.fineract.infrastructure.core.service.MDCWrapper; | ||
import org.apache.fineract.infrastructure.instancemode.filter.FineractInstanceModeApiFilter; | ||
import org.apache.fineract.infrastructure.security.data.PlatformRequestLog; | ||
import org.apache.fineract.infrastructure.security.filter.TenantAwareBasicAuthenticationFilter; | ||
import org.apache.fineract.infrastructure.security.service.BasicAuthTenantDetailsService; | ||
import org.apache.fineract.notification.service.UserNotificationService; | ||
import org.springframework.boot.autoconfigure.web.ServerProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.security.authentication.AuthenticationManager; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.http.SessionCreationPolicy; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
import org.springframework.security.web.access.ExceptionTranslationFilter; | ||
import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint; | ||
import org.springframework.security.web.context.SecurityContextHolderFilter; | ||
|
||
@Slf4j | ||
@Configuration | ||
@RequiredArgsConstructor | ||
public class CommonWebConfiguration { | ||
|
||
private final FineractProperties fineractProperties; | ||
|
||
private final ServerProperties serverProperties; | ||
|
||
private final BasicAuthenticationEntryPoint basicAuthenticationEntryPoint; | ||
|
||
private final AuthenticationManager authenticationManagerBean; | ||
|
||
private final ToApiJsonSerializer<PlatformRequestLog> toApiJsonSerializer; | ||
|
||
private final ConfigurationDomainService configurationDomainService; | ||
|
||
private final CacheWritePlatformService cacheWritePlatformService; | ||
|
||
private final UserNotificationService userNotificationService; | ||
|
||
private final BasicAuthTenantDetailsService basicAuthTenantDetailsService; | ||
|
||
private final BusinessDateReadPlatformService businessDateReadPlatformService; | ||
|
||
private final MDCWrapper mdcWrapper; | ||
|
||
private final FineractRequestContextHolder fineractRequestContextHolder; | ||
|
||
private final IdempotencyStoreHelper idempotencyStoreHelper; | ||
|
||
@Bean | ||
@Order(1) | ||
public SecurityFilterChain v3FilterChain(HttpSecurity http) throws Exception { | ||
http.securityMatcher(antMatcher("/v3/**")).authorizeHttpRequests((auth) -> { | ||
auth.requestMatchers(antMatcher(HttpMethod.OPTIONS, "/v3/**")).permitAll().requestMatchers(antMatcher("/v3/**")) | ||
.fullyAuthenticated(); | ||
}).httpBasic((httpBasic) -> httpBasic.authenticationEntryPoint(basicAuthenticationEntryPoint)) | ||
.sessionManagement((smc) -> smc.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) | ||
.addFilterBefore(tenantAwareBasicAuthenticationFilter(), SecurityContextHolderFilter.class) | ||
.addFilterAfter(requestResponseFilter(), ExceptionTranslationFilter.class) | ||
.addFilterAfter(correlationHeaderFilter(), RequestResponseFilter.class) | ||
.addFilterAfter(fineractInstanceModeApiFilter(), CorrelationHeaderFilter.class) | ||
.addFilterAfter(idempotencyStoreFilter(), FineractInstanceModeApiFilter.class); | ||
|
||
if (serverProperties.getSsl().isEnabled()) { | ||
http.requiresChannel(channel -> channel.requestMatchers(antMatcher("/v3/**")).requiresSecure()); | ||
} | ||
|
||
return http.build(); | ||
} | ||
|
||
public RequestResponseFilter requestResponseFilter() { | ||
return new RequestResponseFilter(); | ||
} | ||
|
||
public FineractInstanceModeApiFilter fineractInstanceModeApiFilter() { | ||
return new FineractInstanceModeApiFilter(fineractProperties); | ||
} | ||
|
||
public IdempotencyStoreFilter idempotencyStoreFilter() { | ||
return new IdempotencyStoreFilter(fineractRequestContextHolder, idempotencyStoreHelper, fineractProperties); | ||
} | ||
|
||
public CorrelationHeaderFilter correlationHeaderFilter() { | ||
return new CorrelationHeaderFilter(fineractProperties, mdcWrapper); | ||
} | ||
|
||
public TenantAwareBasicAuthenticationFilter tenantAwareBasicAuthenticationFilter() { | ||
TenantAwareBasicAuthenticationFilter filter = new TenantAwareBasicAuthenticationFilter(authenticationManagerBean, | ||
basicAuthenticationEntryPoint, toApiJsonSerializer, configurationDomainService, cacheWritePlatformService, | ||
userNotificationService, basicAuthTenantDetailsService, businessDateReadPlatformService); | ||
filter.setRequestMatcher(antMatcher("/v3/**")); | ||
return filter; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
custom/v3/common/configuration/src/main/resources/application-v3.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
debug=true | ||
|
||
# note | ||
fineract.note.enabled=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
SPRING_PROFILES_ACTIVE=v3,test,diagnostics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
description = 'The new generation of the API layer (v3): Note Api' | ||
|
||
group = 'org.apache.fineract.v3.note' | ||
|
||
archivesBaseName = 'fineract-custom-note-api' | ||
|
||
apply from: 'dependencies.gradle' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
dependencies { | ||
implementation(project(':fineract-core')) | ||
implementation(project(':fineract-provider')) | ||
implementation('org.springframework.boot:spring-boot-starter-web') | ||
implementation('org.springframework.boot:spring-boot-starter') | ||
implementation('io.swagger.core.v3:swagger-annotations-jakarta') | ||
} |
93 changes: 93 additions & 0 deletions
93
custom/v3/note/api/src/main/java/org/apache/fineract/v3/note/api/NotesQueriesApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* 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.fineract.v3.note.api; | ||
|
||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; | ||
import static org.springframework.http.MediaType.APPLICATION_PROBLEM_JSON_VALUE; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import java.util.Collection; | ||
import lombok.RequiredArgsConstructor; | ||
import org.apache.fineract.portfolio.note.data.NoteData; | ||
import org.apache.fineract.portfolio.note.domain.NoteType; | ||
import org.apache.fineract.portfolio.note.exception.NoteResourceNotSupportedException; | ||
import org.apache.fineract.portfolio.note.service.NoteReadPlatformService; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping(value = "/v3/{resourceType}/{resourceId}/notes", produces = { APPLICATION_JSON_VALUE, APPLICATION_PROBLEM_JSON_VALUE }) | ||
@Tag(name = "Notes", description = "Notes API allows to retrieve notes for supported resources. (Queries)") | ||
@RequiredArgsConstructor | ||
public class NotesQueriesApi { | ||
|
||
private final NoteReadPlatformService noteReadService; | ||
|
||
@GetMapping | ||
@Operation(summary = "Retrieve a Resource's description", description = """ | ||
Retrieves a Resource's Notes | ||
Note: Notes are returned in descending createOn order. | ||
Example Requests: | ||
clients/2/notes | ||
groups/2/notes""") | ||
public Collection<NoteData> retrieveNotesByResource(@PathVariable("resourceType") final String resourceType, | ||
@PathVariable("resourceId") final Long resourceId) { | ||
|
||
final NoteType noteType = NoteType.fromApiUrl(resourceType); | ||
|
||
if (noteType == null) { | ||
throw new NoteResourceNotSupportedException(resourceType); | ||
} | ||
|
||
return noteReadService.retrieveNotesByResource(resourceId, noteType.getValue()); | ||
} | ||
|
||
@GetMapping("/{noteId}") | ||
@Operation(summary = "Retrieve a Resource Note", description = """ | ||
Retrieves a Resource Note | ||
Example Requests: | ||
clients/1/notes/76 | ||
groups/1/notes/20 | ||
clients/1/notes/76 | ||
groups/1/notes/20""") | ||
public NoteData retrieveNote(@PathVariable("resourceType") final String resourceType, @PathVariable("resourceId") final Long resourceId, | ||
@PathVariable("noteId") final Long noteId) { | ||
|
||
final NoteType noteType = NoteType.fromApiUrl(resourceType); | ||
|
||
if (noteType == null) { | ||
throw new NoteResourceNotSupportedException(resourceType); | ||
} | ||
|
||
return this.noteReadService.retrieveNote(noteId, resourceId, noteType.getValue()); | ||
} | ||
} |
Oops, something went wrong.