From 7ad484bc2e9b1fab4b0e60f6dae68f6b56d4b2d5 Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Wed, 9 May 2012 14:26:53 +0100 Subject: [PATCH] support offices in resource-oriented way, add better error handling support for unauthenticated user use case. --- .../platform/ImportPlatformServiceImpl.java | 4 +- .../platform/ReadPlatformServiceImpl.java | 4 +- ...WritePlatformServiceJpaRepositoryImpl.java | 4 +- .../api/FlexibleReportingApiResource.java | 43 +-- .../platform/api/LoanProductApiResource.java | 263 +++++++++--------- .../platform/api/OfficeApiResource.java | 151 ++++++++++ .../UnAuthenticatedUserExceptionMapper.java | 31 +++ .../ClientNotAuthenticatedException.java | 5 - .../UnAuthenticatedUserException.java | 10 + .../ApplicationConfigurationResource.java | 14 +- .../mifosng/platform/rest/ClientResource.java | 18 +- .../mifosng/platform/rest/ImportResource.java | 8 +- .../platform/rest/LoanProductResource.java | 10 +- .../mifosng/platform/rest/LoanResource.java | 38 +-- .../mifosng/platform/rest/OfficeResource.java | 10 +- .../ProtectedFlexibleReportingResource.java | 4 +- .../rest/UserAdmistrationResource.java | 34 +-- 17 files changed, 400 insertions(+), 251 deletions(-) create mode 100644 mifosng-provider/src/main/java/org/mifosng/platform/api/OfficeApiResource.java create mode 100644 mifosng-provider/src/main/java/org/mifosng/platform/api/errorhandling/UnAuthenticatedUserExceptionMapper.java delete mode 100644 mifosng-provider/src/main/java/org/mifosng/platform/exceptions/ClientNotAuthenticatedException.java create mode 100644 mifosng-provider/src/main/java/org/mifosng/platform/exceptions/UnAuthenticatedUserException.java diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformServiceImpl.java index 38bc5dc78..09af3b15d 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformServiceImpl.java @@ -34,7 +34,7 @@ import org.mifosng.platform.client.domain.Client; import org.mifosng.platform.client.domain.ClientRepository; import org.mifosng.platform.currency.domain.MonetaryCurrency; import org.mifosng.platform.currency.domain.Money; -import org.mifosng.platform.exceptions.ClientNotAuthenticatedException; +import org.mifosng.platform.exceptions.UnAuthenticatedUserException; import org.mifosng.platform.loan.domain.AmortizationMethod; import org.mifosng.platform.loan.domain.DefaultLoanLifecycleStateMachine; import org.mifosng.platform.loan.domain.InterestCalculationPeriodMethod; @@ -99,7 +99,7 @@ public class ImportPlatformServiceImpl implements ImportPlatformService { } if (currentUser == null) { - throw new ClientNotAuthenticatedException(); + throw new UnAuthenticatedUserException(); } return currentUser; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/ReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/ReadPlatformServiceImpl.java index 9e808899f..2b8a94374 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/ReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/ReadPlatformServiceImpl.java @@ -54,7 +54,7 @@ import org.mifosng.platform.currency.domain.ApplicationCurrency; import org.mifosng.platform.currency.domain.ApplicationCurrencyRepository; import org.mifosng.platform.currency.domain.Money; import org.mifosng.platform.exceptions.ApplicationDomainRuleException; -import org.mifosng.platform.exceptions.ClientNotAuthenticatedException; +import org.mifosng.platform.exceptions.UnAuthenticatedUserException; import org.mifosng.platform.loan.domain.AmortizationMethod; import org.mifosng.platform.loan.domain.Loan; import org.mifosng.platform.loan.domain.LoanRepository; @@ -122,7 +122,7 @@ public class ReadPlatformServiceImpl implements ReadPlatformService { } if (currentUser == null) { - throw new ClientNotAuthenticatedException(); + throw new UnAuthenticatedUserException(); } return currentUser; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/WritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/WritePlatformServiceJpaRepositoryImpl.java index ee49af334..be114e646 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/WritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/WritePlatformServiceJpaRepositoryImpl.java @@ -44,7 +44,7 @@ import org.mifosng.platform.currency.domain.ApplicationCurrencyRepository; import org.mifosng.platform.currency.domain.MonetaryCurrency; import org.mifosng.platform.currency.domain.Money; import org.mifosng.platform.exceptions.ApplicationDomainRuleException; -import org.mifosng.platform.exceptions.ClientNotAuthenticatedException; +import org.mifosng.platform.exceptions.UnAuthenticatedUserException; import org.mifosng.platform.exceptions.InvalidSignupException; import org.mifosng.platform.exceptions.NewDataValidationException; import org.mifosng.platform.exceptions.NoAuthorizationException; @@ -601,7 +601,7 @@ public class WritePlatformServiceJpaRepositoryImpl implements } if (currentUser == null) { - throw new ClientNotAuthenticatedException(); + throw new UnAuthenticatedUserException(); } return currentUser; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/FlexibleReportingApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/FlexibleReportingApiResource.java index dc6fc2c60..c6761e7d3 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/FlexibleReportingApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/FlexibleReportingApiResource.java @@ -9,8 +9,6 @@ import java.util.Set; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.Consumes; import javax.ws.rs.GET; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.OPTIONS; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -19,7 +17,6 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.ResponseBuilder; import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.UriInfo; @@ -28,7 +25,7 @@ import org.mifosng.data.ErrorResponseList; import org.mifosng.data.reports.GenericResultset; import org.mifosng.platform.ReadPlatformService; import org.mifosng.platform.exceptions.ApplicationDomainRuleException; -import org.mifosng.platform.exceptions.ClientNotAuthenticatedException; +import org.mifosng.platform.exceptions.UnAuthenticatedUserException; import org.mifosng.platform.exceptions.NewDataValidationException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,34 +44,6 @@ public class FlexibleReportingApiResource { @Autowired private ReadPlatformService readPlatformService; - private String _corsHeaders; - - private Response makeCORS(ResponseBuilder req, String returnMethod) { - ResponseBuilder rb = req - .header("Access-Control-Allow-Origin", "*") - .header("Access-Control-Allow-Methods", "GET, POST, OPTIONS"); - - if (!"".equals(returnMethod)) { - rb.header("Access-Control-Allow-Headers", returnMethod); - } - - return rb.build(); - } - - private Response makeCORS(ResponseBuilder req) { - return makeCORS(req, _corsHeaders); - } - - // This OPTIONS request/response is necessary - // if you consumes other format than text/plain or - // if you use other HTTP verbs than GET and POST - @OPTIONS - @Path("/flexireport") - public Response corsMyResource(@HeaderParam("Access-Control-Request-Headers") String requestH) { - _corsHeaders = requestH; - return makeCORS(Response.ok(), requestH); - } - @GET @Path("flexireport") @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @@ -107,7 +76,7 @@ public class FlexibleReportingApiResource { // JSONWithPadding paddedResult = new JSONWithPadding(result, // callbackName); - return makeCORS(Response.ok().entity(result)); + return Response.ok().entity(result).build(); } @GET @@ -134,7 +103,7 @@ public class FlexibleReportingApiResource { GenericResultset result = this.readPlatformService.retrieveGenericResultset(rptDB, name, type, extractedQueryParams); return Response.ok().entity(result).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -146,10 +115,4 @@ public class FlexibleReportingApiResource { throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build()); } } - - @GET - @Path("forceauth") - public Response hackToForceAuthentication() { - return Response.ok().build(); - } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/LoanProductApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/LoanProductApiResource.java index 8b4b03d83..64735aed7 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/LoanProductApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/LoanProductApiResource.java @@ -25,7 +25,6 @@ import org.mifosng.data.command.UpdateLoanProductCommand; import org.mifosng.platform.ReadPlatformService; import org.mifosng.platform.WritePlatformService; import org.mifosng.platform.exceptions.ApplicationDomainRuleException; -import org.mifosng.platform.exceptions.ClientNotAuthenticatedException; import org.mifosng.platform.exceptions.NewDataValidationException; import org.mifosng.platform.user.domain.AppUser; import org.mifosng.platform.user.domain.AppUserRepository; @@ -53,8 +52,12 @@ import org.springframework.stereotype.Component; * 4. Only 'produce'ing JSON by limiting to @Produces({MediaType.APPLICATION_JSON}) * 5. The java object returned is LoanProductData and LoanProductList when list of products returned. * These java objects are annotated with @XmlRootElement so JAXB reader/writers will automatically translate to JSON format. - * 6. @GET /loanproducts/{productId} results in loan product of that identifier or appropiate error response + * 6. @GET /loanproducts/{productId} results in loan product of that identifier or appropriate error response + * 7. @POST /loanproducts with correct request body creates new loan product + * 8. @PUT /loanproducts/{productId} updates loan product of that identifier + * 9. Using /resource/template pattern for UI specific function of get 'data with defaults' for new resource. */ + @Path("/v1/loanproducts") @Component @Scope("singleton") @@ -76,109 +79,13 @@ public class LoanProductApiResource { SecurityContext context = SecurityContextHolder.getContext(); context.setAuthentication(auth); } - - @GET - @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - @Produces({MediaType.APPLICATION_JSON}) - public Response retrieveAllLoanProducts() { - - try { - hardcodeUserIntoSecurityContext(); - - Collection products = this.readPlatformService.retrieveAllLoanProducts(); - - return Response.ok().entity(new LoanProductList(products)).build(); - } catch (ClientNotAuthenticatedException e) { - throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); - } catch (AccessDeniedException e) { - ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); - ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse)); - throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build()); - } catch (ApplicationDomainRuleException e) { - throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build()); - } catch (NewDataValidationException e) { - throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build()); - } - } - - @GET - @Path("{productId}") - @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - @Produces({ MediaType.APPLICATION_JSON}) - public Response retrieveLoanProductDetails(@PathParam("productId") final Long productId) { - - try { - hardcodeUserIntoSecurityContext(); - - LoanProductData loanProduct = this.readPlatformService.retrieveLoanProduct(productId); - - return Response.ok().entity(loanProduct).build(); - } catch (ClientNotAuthenticatedException e) { - throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); - } catch (AccessDeniedException e) { - ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); - ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse)); - throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build()); - } catch (ApplicationDomainRuleException e) { - throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build()); - } catch (NewDataValidationException e) { - throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build()); - } - } - -// example POST request -// http://localhost:8085/mifosng-provider/api/v1/loanproducts/ -// Content-Type: application/json -// { -// "name": "test", -// "description": "test", -// "commonLoanProperties": { -// "currencyCode": "USD", -// "digitsAfterDecimal": 2, -// "principal": 100000, -// "repaymentEvery": 1, -// "repaymentFrequency": 2, -// "numberOfRepayments": 12, -// "amortizationMethod": 1, -// "inArrearsToleranceAmount": 1000, -// "interestRatePerPeriod": 2, -// "interestRateFrequencyMethod": 2, -// "interestMethod": 0, -// "interestCalculationPeriodMethod": 1 -// } -// } - @POST - @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - @Produces({ MediaType.APPLICATION_JSON}) - public Response createLoanProduct(CreateLoanProductCommand command) { - - try { - hardcodeUserIntoSecurityContext(); - - EntityIdentifier entityIdentifier = this.writePlatformService.createLoanProduct(command); - - return Response.ok().entity(entityIdentifier).build(); - } catch (ClientNotAuthenticatedException e) { - throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); - } catch (AccessDeniedException e) { - ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); - ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse)); - throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build()); - } catch (ApplicationDomainRuleException e) { - throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build()); - } catch (NewDataValidationException e) { - throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build()); - } - } - -// example PUT request -// http://localhost:8085/mifosng-provider/api/v1/loanproducts/ -// Content-Type: application/json + + // example POST request + // http://localhost:8085/mifosng-provider/api/v1/loanproducts/ + // Content-Type: application/json // { -// "id": 7, // "name": "test", // "description": "test", -// "externalId": "", // "commonLoanProperties": { // "currencyCode": "USD", // "digitsAfterDecimal": 2, @@ -194,19 +101,18 @@ public class LoanProductApiResource { // "interestCalculationPeriodMethod": 1 // } // } - @PUT + @POST @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - @Produces({ MediaType.APPLICATION_JSON }) - public Response updateLoanProduct(final UpdateLoanProductCommand command) { + @Produces({ MediaType.APPLICATION_JSON}) + public Response createLoanProduct(CreateLoanProductCommand command) { try { + // TODO - move CreateLoanProductCommand and UpdateLoanProductCommand into one. hardcodeUserIntoSecurityContext(); - EntityIdentifier entityIdentifier = this.writePlatformService.updateLoanProduct(command); - + EntityIdentifier entityIdentifier = this.writePlatformService.createLoanProduct(command); + return Response.ok().entity(entityIdentifier).build(); - } catch (ClientNotAuthenticatedException e) { - throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse)); @@ -218,27 +124,120 @@ public class LoanProductApiResource { } } -// -// @GET -// @Path("empty") -// @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) -// @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) -// public Response retrieveNewLoanProductDetails() { -// -// try { -// LoanProductData loanProduct = this.readPlatformService.retrieveNewLoanProductDetails(); -// -// return Response.ok().entity(loanProduct).build(); -// } catch (ClientNotAuthenticatedException e) { -// throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); -// } catch (AccessDeniedException e) { -// ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); -// ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse)); -// throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build()); -// } catch (ApplicationDomainRuleException e) { -// throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build()); -// } catch (NewDataValidationException e) { -// throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build()); -// } -// } + @GET + @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @Produces({MediaType.APPLICATION_JSON}) + public Response retrieveAllLoanProducts() { + + try { + hardcodeUserIntoSecurityContext(); + + Collection products = this.readPlatformService.retrieveAllLoanProducts(); + + return Response.ok().entity(new LoanProductList(products)).build(); + } catch (AccessDeniedException e) { + ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); + ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse)); + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build()); + } catch (ApplicationDomainRuleException e) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build()); + } catch (NewDataValidationException e) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build()); + } + } + + /* + * see http://stackoverflow.com/questions/5250074/what-uri-can-be-used-to-request-a-default-resource + */ + @GET + @Path("template") + @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @Produces({ MediaType.APPLICATION_JSON}) + public Response retrieveNewLoanProductDetails() { + + try { + hardcodeUserIntoSecurityContext(); + + LoanProductData loanProduct = this.readPlatformService.retrieveNewLoanProductDetails(); + + return Response.ok().entity(loanProduct).build(); + } catch (AccessDeniedException e) { + ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); + ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse)); + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build()); + } catch (ApplicationDomainRuleException e) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build()); + } catch (NewDataValidationException e) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build()); + } + } + + @GET + @Path("{productId}") + @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @Produces({ MediaType.APPLICATION_JSON}) + public Response retrieveLoanProductDetails(@PathParam("productId") final Long productId) { + + try { + hardcodeUserIntoSecurityContext(); + + LoanProductData loanProduct = this.readPlatformService.retrieveLoanProduct(productId); + + return Response.ok().entity(loanProduct).build(); + } catch (AccessDeniedException e) { + ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); + ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse)); + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build()); + } catch (ApplicationDomainRuleException e) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build()); + } catch (NewDataValidationException e) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build()); + } + } + + // example PUT request + // http://localhost:8085/mifosng-provider/api/v1/loanproducts/ + // Content-Type: application/json +// { +// "id": 7, +// "name": "test", +// "description": "test", +// "externalId": "", +// "commonLoanProperties": { +// "currencyCode": "USD", +// "digitsAfterDecimal": 2, +// "principal": 100000, +// "repaymentEvery": 1, +// "repaymentFrequency": 2, +// "numberOfRepayments": 12, +// "amortizationMethod": 1, +// "inArrearsToleranceAmount": 1000, +// "interestRatePerPeriod": 2, +// "interestRateFrequencyMethod": 2, +// "interestMethod": 0, +// "interestCalculationPeriodMethod": 1 +// } +// } + @PUT + @Path("{productId}") + @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @Produces({ MediaType.APPLICATION_JSON }) + public Response updateLoanProduct(@PathParam("productId") final Long productId, final UpdateLoanProductCommand command) { + + try { + hardcodeUserIntoSecurityContext(); + + EntityIdentifier entityIdentifier = this.writePlatformService.updateLoanProduct(command); + + return Response.ok().entity(entityIdentifier).build(); + } catch (AccessDeniedException e) { + ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); + ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse)); + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build()); + } catch (ApplicationDomainRuleException e) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build()); + } catch (NewDataValidationException e) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build()); + } + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/OfficeApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/OfficeApiResource.java new file mode 100644 index 000000000..0c0c6985e --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/OfficeApiResource.java @@ -0,0 +1,151 @@ +package org.mifosng.platform.api; + +import java.util.Arrays; +import java.util.Collection; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + +import org.mifosng.data.EntityIdentifier; +import org.mifosng.data.ErrorResponse; +import org.mifosng.data.ErrorResponseList; +import org.mifosng.data.OfficeData; +import org.mifosng.data.OfficeList; +import org.mifosng.data.command.OfficeCommand; +import org.mifosng.platform.ReadPlatformService; +import org.mifosng.platform.WritePlatformService; +import org.mifosng.platform.exceptions.ApplicationDomainRuleException; +import org.mifosng.platform.exceptions.NewDataValidationException; +import org.mifosng.platform.user.domain.AppUser; +import org.mifosng.platform.user.domain.AppUserRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContext; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Component; + +@Path("/v1/offices") +@Component +@Scope("singleton") +public class OfficeApiResource { + + @Autowired + private ReadPlatformService readPlatformService; + + @Autowired + private WritePlatformService writePlatformService; + + @Autowired + private AppUserRepository appUserRepository; + + private void hardcodeUserIntoSecurityContext() { + AppUser currentUser = this.appUserRepository.findOne(Long.valueOf(1)); + + Authentication auth = new UsernamePasswordAuthenticationToken(currentUser, currentUser, currentUser.getAuthorities()); + SecurityContext context = SecurityContextHolder.getContext(); + context.setAuthentication(auth); + } + + @GET + @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @Produces({MediaType.APPLICATION_JSON}) + public Response retrieveOffices() { + + try { + hardcodeUserIntoSecurityContext(); + + Collection offices = this.readPlatformService.retrieveAllOffices(); + + return Response.ok().entity(new OfficeList(offices)).build(); + } catch (AccessDeniedException e) { + ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); + ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse)); + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build()); + } catch (ApplicationDomainRuleException e) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build()); + } catch (NewDataValidationException e) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build()); + } + } + + @POST + @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @Produces({ MediaType.APPLICATION_JSON}) + public Response createOffice(final OfficeCommand command) { + + try { + hardcodeUserIntoSecurityContext(); + + Long officeId = this.writePlatformService.createOffice(command); + + return Response.ok().entity(new EntityIdentifier(officeId)).build(); + } catch (AccessDeniedException e) { + ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); + ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse)); + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build()); + } catch (ApplicationDomainRuleException e) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build()); + } catch (NewDataValidationException e) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build()); + } + } + + @GET + @Path("{officeId}") + @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @Produces({ MediaType.APPLICATION_JSON}) + public Response retreiveOffice(@PathParam("officeId") final Long officeId) { + + try { + hardcodeUserIntoSecurityContext(); + + OfficeData office = this.readPlatformService.retrieveOffice(officeId); + + return Response.ok().entity(office).build(); + } catch (AccessDeniedException e) { + ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); + ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse)); + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build()); + } catch (ApplicationDomainRuleException e) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build()); + } catch (NewDataValidationException e) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build()); + } + } + + @PUT + @Path("{officeId}") + @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @Produces({ MediaType.APPLICATION_JSON}) + public Response updateOffice(@PathParam("officeId") final Long officeId, final OfficeCommand command) { + + try { + hardcodeUserIntoSecurityContext(); + + command.setId(officeId); + Long entityId = this.writePlatformService.updateOffice(command); + + return Response.ok().entity(new EntityIdentifier(entityId)).build(); + } catch (AccessDeniedException e) { + ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); + ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse)); + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build()); + } catch (ApplicationDomainRuleException e) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build()); + } catch (NewDataValidationException e) { + throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build()); + } + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/errorhandling/UnAuthenticatedUserExceptionMapper.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/errorhandling/UnAuthenticatedUserExceptionMapper.java new file mode 100644 index 000000000..2ae2a2645 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/errorhandling/UnAuthenticatedUserExceptionMapper.java @@ -0,0 +1,31 @@ +package org.mifosng.platform.api.errorhandling; + +import java.util.Arrays; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; + +import org.mifosng.data.ErrorResponse; +import org.mifosng.data.ErrorResponseList; +import org.mifosng.platform.exceptions.UnAuthenticatedUserException; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +/** + * An {@link ExceptionMapper} to map {@link UnAuthenticatedUserException} thrown by platform into a HTTP API friendly format. + */ +@Provider +@Component +@Scope("singleton") +public class UnAuthenticatedUserExceptionMapper implements ExceptionMapper { + + @Override + public Response toResponse(UnAuthenticatedUserException exception) { + ErrorResponse errorResponse = new ErrorResponse("error.msg.not.authorized", "id"); + ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse)); + + return Response.status(Status.UNAUTHORIZED).entity(list).build(); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/ClientNotAuthenticatedException.java b/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/ClientNotAuthenticatedException.java deleted file mode 100644 index 32305f733..000000000 --- a/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/ClientNotAuthenticatedException.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.mifosng.platform.exceptions; - -public class ClientNotAuthenticatedException extends RuntimeException { - // no added behaviour -} diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/UnAuthenticatedUserException.java b/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/UnAuthenticatedUserException.java new file mode 100644 index 000000000..84cc541bf --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/UnAuthenticatedUserException.java @@ -0,0 +1,10 @@ +package org.mifosng.platform.exceptions; + +import org.springframework.security.core.context.SecurityContext; + +/** + * A {@link RuntimeException} that is thrown in the case where no authenticated user exists within the platform {@link SecurityContext}. + */ +public class UnAuthenticatedUserException extends RuntimeException { + // no added behaviour +} diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/rest/ApplicationConfigurationResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/rest/ApplicationConfigurationResource.java index 023ebf750..9b5d178c0 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/rest/ApplicationConfigurationResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/rest/ApplicationConfigurationResource.java @@ -23,7 +23,7 @@ import org.mifosng.data.command.UpdateOrganisationCurrencyCommand; import org.mifosng.platform.ReadPlatformService; import org.mifosng.platform.WritePlatformService; import org.mifosng.platform.exceptions.ApplicationDomainRuleException; -import org.mifosng.platform.exceptions.ClientNotAuthenticatedException; +import org.mifosng.platform.exceptions.UnAuthenticatedUserException; import org.mifosng.platform.exceptions.NewDataValidationException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; @@ -63,7 +63,7 @@ public class ApplicationConfigurationResource { this.writePlatformService.updateOrganisationCurrencies(command); return Response.ok().entity(command).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -87,7 +87,7 @@ public class ApplicationConfigurationResource { .retrieveAllPlatformCurrencies(); return Response.ok().entity(new CurrencyList(currencyOptions)).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -111,7 +111,7 @@ public class ApplicationConfigurationResource { .retrieveLoanAmortizationMethodOptions(); return Response.ok().entity(new EnumOptionList(options)).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -135,7 +135,7 @@ public class ApplicationConfigurationResource { .retrieveLoanInterestMethodOptions(); return Response.ok().entity(new EnumOptionList(options)).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -159,7 +159,7 @@ public class ApplicationConfigurationResource { .retrieveRepaymentFrequencyOptions(); return Response.ok().entity(new EnumOptionList(options)).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -182,7 +182,7 @@ public class ApplicationConfigurationResource { List options = this.readPlatformService.retrieveInterestFrequencyOptions(); return Response.ok().entity(new EnumOptionList(options)).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/rest/ClientResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/rest/ClientResource.java index e93906edd..572456afc 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/rest/ClientResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/rest/ClientResource.java @@ -27,7 +27,7 @@ import org.mifosng.data.command.NoteCommand; import org.mifosng.platform.ReadPlatformService; import org.mifosng.platform.WritePlatformService; import org.mifosng.platform.exceptions.ApplicationDomainRuleException; -import org.mifosng.platform.exceptions.ClientNotAuthenticatedException; +import org.mifosng.platform.exceptions.UnAuthenticatedUserException; import org.mifosng.platform.exceptions.NewDataValidationException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; @@ -55,7 +55,7 @@ public class ClientResource { Collection clients = this.readPlatformService.retrieveAllIndividualClients(); return Response.ok().entity(new ClientList(clients)).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -78,7 +78,7 @@ public class ClientResource { ClientData clientData = this.readPlatformService.retrieveNewClientDetails(); return Response.ok().entity(clientData).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -101,7 +101,7 @@ public class ClientResource { Long clientId = this.writePlatformService.enrollClient(command); return Response.ok().entity(new EntityIdentifier(clientId)).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -124,7 +124,7 @@ public class ClientResource { ClientData clientData = this.readPlatformService.retrieveIndividualClient(clientId); return Response.ok().entity(clientData).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -148,7 +148,7 @@ public class ClientResource { .retrieveClientAccountDetails(clientId); return Response.ok().entity(clientAccount).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -171,7 +171,7 @@ public class ClientResource { EntityIdentifier identifier = this.writePlatformService.addClientNote(command); return Response.ok().entity(identifier).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -194,7 +194,7 @@ public class ClientResource { Collection notes = this.readPlatformService.retrieveAllClientNotes(clientId); return Response.ok().entity(new NoteDataList(notes)).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -217,7 +217,7 @@ public class ClientResource { NoteData note = this.readPlatformService.retrieveClientNote(clientId, noteId); return Response.ok().entity(note).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportResource.java index 545d8da46..75038514f 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportResource.java @@ -14,7 +14,7 @@ import org.mifosng.data.command.ImportClientCommand; import org.mifosng.data.command.ImportLoanCommand; import org.mifosng.data.command.ImportLoanRepaymentsCommand; import org.mifosng.platform.ImportPlatformService; -import org.mifosng.platform.exceptions.ClientNotAuthenticatedException; +import org.mifosng.platform.exceptions.UnAuthenticatedUserException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -36,7 +36,7 @@ public class ImportResource { this.importPlatformService.importClients(command); return Response.ok().build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { ErrorResponse err = new ErrorResponse("client.not.authenticated", "authentication", ""); throw new WebApplicationException(Response @@ -53,7 +53,7 @@ public class ImportResource { this.importPlatformService.importLoans(command); return Response.ok().build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { ErrorResponse err = new ErrorResponse("client.not.authenticated", "authentication", ""); throw new WebApplicationException(Response @@ -70,7 +70,7 @@ public class ImportResource { this.importPlatformService.importLoanRepayments(command); return Response.ok().build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { ErrorResponse err = new ErrorResponse("client.not.authenticated", "authentication", ""); throw new WebApplicationException(Response diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/rest/LoanProductResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/rest/LoanProductResource.java index e142e148c..5c5948a34 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/rest/LoanProductResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/rest/LoanProductResource.java @@ -24,7 +24,7 @@ import org.mifosng.data.command.UpdateLoanProductCommand; import org.mifosng.platform.ReadPlatformService; import org.mifosng.platform.WritePlatformService; import org.mifosng.platform.exceptions.ApplicationDomainRuleException; -import org.mifosng.platform.exceptions.ClientNotAuthenticatedException; +import org.mifosng.platform.exceptions.UnAuthenticatedUserException; import org.mifosng.platform.exceptions.NewDataValidationException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; @@ -64,7 +64,7 @@ public class LoanProductResource { EntityIdentifier entityIdentifier = this.writePlatformService.createLoanProduct(command); return Response.ok().entity(entityIdentifier).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -86,7 +86,7 @@ public class LoanProductResource { try { EntityIdentifier entityIdentifier = this.writePlatformService.updateLoanProduct(command); return Response.ok().entity(entityIdentifier).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -109,7 +109,7 @@ public class LoanProductResource { LoanProductData loanProduct = this.readPlatformService.retrieveLoanProduct(productId); return Response.ok().entity(loanProduct).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -132,7 +132,7 @@ public class LoanProductResource { LoanProductData loanProduct = this.readPlatformService.retrieveNewLoanProductDetails(); return Response.ok().entity(loanProduct).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/rest/LoanResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/rest/LoanResource.java index bf9305dcd..d3d259faf 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/rest/LoanResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/rest/LoanResource.java @@ -35,7 +35,7 @@ import org.mifosng.platform.ReadPlatformService; import org.mifosng.platform.ReadPlatformServiceImpl; import org.mifosng.platform.WritePlatformService; import org.mifosng.platform.exceptions.ApplicationDomainRuleException; -import org.mifosng.platform.exceptions.ClientNotAuthenticatedException; +import org.mifosng.platform.exceptions.UnAuthenticatedUserException; import org.mifosng.platform.exceptions.NewDataValidationException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -71,7 +71,7 @@ public class LoanResource { NewLoanWorkflowStepOneData workflowData = this.readPlatformService.retrieveClientAndProductDetails(clientId, null); return Response.ok().entity(workflowData).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -94,7 +94,7 @@ public class LoanResource { NewLoanWorkflowStepOneData workflowData = this.readPlatformService.retrieveClientAndProductDetails(clientId, productId); return Response.ok().entity(workflowData).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -117,7 +117,7 @@ public class LoanResource { LoanSchedule loanSchedule = this.calculationPlatformService.calculateLoanSchedule(command); return Response.ok().entity(loanSchedule).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -140,7 +140,7 @@ public class LoanResource { EntityIdentifier identifier = this.writePlatformService.submitLoanApplication(command); return Response.ok().entity(identifier).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -163,7 +163,7 @@ public class LoanResource { LoanAccountData loanAccount = this.readPlatformService.retrieveLoanAccountDetails(loanId); return Response.ok().entity(loanAccount).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -194,7 +194,7 @@ public class LoanResource { EntityIdentifier identifier = this.writePlatformService.deleteLoan(loanId); return Response.ok().entity(identifier).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -225,7 +225,7 @@ public class LoanResource { EntityIdentifier identifier = this.writePlatformService.approveLoanApplication(command); return Response.ok().entity(identifier).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -248,7 +248,7 @@ public class LoanResource { EntityIdentifier identifier = this.writePlatformService.undoLoanApproval(command); return Response.ok().entity(identifier).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -271,7 +271,7 @@ public class LoanResource { EntityIdentifier identifier = this.writePlatformService.rejectLoan(command); return Response.ok().entity(identifier).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -294,7 +294,7 @@ public class LoanResource { EntityIdentifier identifier = this.writePlatformService.withdrawLoan(command); return Response.ok().entity(identifier).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -317,7 +317,7 @@ public class LoanResource { EntityIdentifier identifier = this.writePlatformService.disburseLoan(command); return Response.ok().entity(identifier).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -340,7 +340,7 @@ public class LoanResource { EntityIdentifier identifier = this.writePlatformService.undloLoanDisbursal(command); return Response.ok().entity(identifier).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -363,7 +363,7 @@ public class LoanResource { LoanRepaymentData loanRepaymentData = this.readPlatformService.retrieveNewLoanRepaymentDetails(loanId); return Response.ok().entity(loanRepaymentData).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -386,7 +386,7 @@ public class LoanResource { LoanRepaymentData loanRepaymentData = this.readPlatformService.retrieveLoanRepaymentDetails(loanId, repaymentId); return Response.ok().entity(loanRepaymentData).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -409,7 +409,7 @@ public class LoanResource { EntityIdentifier identifier = this.writePlatformService.makeLoanRepayment(command); return Response.ok().entity(identifier).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -443,7 +443,7 @@ public class LoanResource { EntityIdentifier identifier = this.writePlatformService.adjustLoanTransaction(command); return Response.ok().entity(identifier).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -477,7 +477,7 @@ public class LoanResource { LoanRepaymentData loanRepaymentData = this.readPlatformService.retrieveNewLoanWaiverDetails(loanId); return Response.ok().entity(loanRepaymentData).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -500,7 +500,7 @@ public class LoanResource { EntityIdentifier identifier = this.writePlatformService.waiveLoanAmount(command); return Response.ok().entity(identifier).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/rest/OfficeResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/rest/OfficeResource.java index 7e558b5b0..77facddad 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/rest/OfficeResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/rest/OfficeResource.java @@ -23,7 +23,7 @@ import org.mifosng.data.command.OfficeCommand; import org.mifosng.platform.ReadPlatformService; import org.mifosng.platform.WritePlatformService; import org.mifosng.platform.exceptions.ApplicationDomainRuleException; -import org.mifosng.platform.exceptions.ClientNotAuthenticatedException; +import org.mifosng.platform.exceptions.UnAuthenticatedUserException; import org.mifosng.platform.exceptions.NewDataValidationException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; @@ -51,7 +51,7 @@ public class OfficeResource { Collection offices = this.readPlatformService.retrieveAllOffices(); return Response.ok().entity(new OfficeList(offices)).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -74,7 +74,7 @@ public class OfficeResource { OfficeData office = this.readPlatformService.retrieveOffice(officeId); return Response.ok().entity(office).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -97,7 +97,7 @@ public class OfficeResource { Long officeId = this.writePlatformService.createOffice(command); return Response.ok().entity(new EntityIdentifier(officeId)).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -120,7 +120,7 @@ public class OfficeResource { Long officeId = this.writePlatformService.updateOffice(command); return Response.ok().entity(new EntityIdentifier(officeId)).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/rest/ProtectedFlexibleReportingResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/rest/ProtectedFlexibleReportingResource.java index 6f3af0ea3..e09c7a021 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/rest/ProtectedFlexibleReportingResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/rest/ProtectedFlexibleReportingResource.java @@ -28,7 +28,7 @@ import org.mifosng.data.ErrorResponseList; import org.mifosng.data.reports.GenericResultset; import org.mifosng.platform.ReadPlatformService; import org.mifosng.platform.exceptions.ApplicationDomainRuleException; -import org.mifosng.platform.exceptions.ClientNotAuthenticatedException; +import org.mifosng.platform.exceptions.UnAuthenticatedUserException; import org.mifosng.platform.exceptions.NewDataValidationException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -134,7 +134,7 @@ public class ProtectedFlexibleReportingResource { GenericResultset result = this.readPlatformService.retrieveGenericResultset(rptDB, name, type, extractedQueryParams); return Response.ok().entity(result).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/rest/UserAdmistrationResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/rest/UserAdmistrationResource.java index 0dba773bc..e337604cb 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/rest/UserAdmistrationResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/rest/UserAdmistrationResource.java @@ -34,7 +34,7 @@ import org.mifosng.data.command.UserCommand; import org.mifosng.platform.ReadPlatformService; import org.mifosng.platform.WritePlatformService; import org.mifosng.platform.exceptions.ApplicationDomainRuleException; -import org.mifosng.platform.exceptions.ClientNotAuthenticatedException; +import org.mifosng.platform.exceptions.UnAuthenticatedUserException; import org.mifosng.platform.exceptions.NewDataValidationException; import org.mifosng.platform.infrastructure.PlatformEmailSendException; import org.mifosng.platform.infrastructure.UsernameAlreadyExistsException; @@ -65,7 +65,7 @@ public class UserAdmistrationResource { Collection users = this.readPlatformService.retrieveAllUsers(); return Response.ok().entity(new UserList(users)).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -88,7 +88,7 @@ public class UserAdmistrationResource { AppUserData newUser = this.readPlatformService.retrieveNewUserDetails(); return Response.ok().entity(newUser).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -125,7 +125,7 @@ public class UserAdmistrationResource { throw new WebApplicationException(Response .status(Status.BAD_REQUEST) .entity(new ErrorResponseList(allErrors)).build()); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -148,7 +148,7 @@ public class UserAdmistrationResource { this.writePlatformService.deleteUser(userId); return Response.ok().build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -171,7 +171,7 @@ public class UserAdmistrationResource { AppUserData user = this.readPlatformService.retrieveUser(userId); return Response.ok().entity(user).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -194,7 +194,7 @@ public class UserAdmistrationResource { Long userId = this.writePlatformService.updateUser(command); return Response.ok().entity(new EntityIdentifier(userId)).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -217,7 +217,7 @@ public class UserAdmistrationResource { AppUserData user = this.readPlatformService.retrieveCurrentUser(); return Response.ok().entity(user).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -240,7 +240,7 @@ public class UserAdmistrationResource { Long userId = this.writePlatformService.updateCurrentUser(command); return Response.ok().entity(new EntityIdentifier(userId)).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -267,7 +267,7 @@ public class UserAdmistrationResource { Long userId = this.writePlatformService.updateCurrentUserPassword(command); return Response.ok().entity(new EntityIdentifier(userId)).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -289,7 +289,7 @@ public class UserAdmistrationResource { try { Collection roles = this.readPlatformService.retrieveAllRoles(); return Response.ok().entity(new RoleList(roles)).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -315,7 +315,7 @@ public class UserAdmistrationResource { role.setAvailablePermissions(allPermissions); return Response.ok().entity(role).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -344,7 +344,7 @@ public class UserAdmistrationResource { role.setAvailablePermissions(availablePermissions); return Response.ok().entity(role).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -368,7 +368,7 @@ public class UserAdmistrationResource { this.writePlatformService.updateRole(command); return Response.ok().entity(new EntityIdentifier(roleId)).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -391,7 +391,7 @@ public class UserAdmistrationResource { Long roleId = this.writePlatformService.createRole(command); return Response.ok().entity(new EntityIdentifier(roleId)).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -418,7 +418,7 @@ public class UserAdmistrationResource { .ok() .entity(new EnumOptionList(new ArrayList( options))).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); @@ -441,7 +441,7 @@ public class UserAdmistrationResource { Collection permissions = this.readPlatformService.retrieveAllPermissions(); return Response.ok().entity(new PermissionList(permissions)).build(); - } catch (ClientNotAuthenticatedException e) { + } catch (UnAuthenticatedUserException e) { throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build()); } catch (AccessDeniedException e) { ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id");