wip permissions

This commit is contained in:
John Woodlock
2012-11-15 16:36:49 +00:00
parent 81a549ae01
commit e046d86e06
6 changed files with 43 additions and 9 deletions
@@ -22,6 +22,7 @@ import org.mifosng.platform.exceptions.UnrecognizedQueryParamException;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosng.platform.makerchecker.service.PortfolioMakerCheckerReadPlatformService;
import org.mifosng.platform.makerchecker.service.PortfolioMakerCheckerWriteService;
import org.mifosng.platform.security.PlatformSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@@ -39,12 +40,18 @@ public class MakerCheckerApiResource {
@Autowired
private PortfolioApiJsonSerializerService apiJsonSerializerService;
private final String entityType = "MAKERCHECKER";
@Autowired
private PlatformSecurityContext context;
@GET
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public String retrieveCodes(@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(entityType);
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
@@ -23,6 +23,7 @@ import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosng.platform.organisation.service.OfficeReadPlatformService;
import org.mifosng.platform.organisation.service.OfficeWritePlatformService;
import org.mifosng.platform.security.PlatformSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@@ -44,11 +45,17 @@ public class OfficeTransactionsApiResource {
@Autowired
private PortfolioApiJsonSerializerService apiJsonSerializerService;
private final String entityType = "OFFICE";
@Autowired
private PlatformSecurityContext context;
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveOfficeTransactions(@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(entityType);
Set<String> typicalResponseParameters = new HashSet<String>(
Arrays.asList("id", "transactionDate", "fromOfficeId",
"fromOfficeName", "toOfficeId", "toOfficeIdName",
@@ -78,6 +85,8 @@ public class OfficeTransactionsApiResource {
@Produces({ MediaType.APPLICATION_JSON })
public String newOfficeTransactionDetails(@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(entityType);
Set<String> typicalResponseParameters = new HashSet<String>(
Arrays.asList("id", "transactionDate", "allowedOffices",
"currencyOptions"));
@@ -28,6 +28,7 @@ import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosng.platform.organisation.service.OfficeReadPlatformService;
import org.mifosng.platform.organisation.service.OfficeWritePlatformService;
import org.mifosng.platform.security.PlatformSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@@ -49,11 +50,17 @@ public class OfficesApiResource {
@Autowired
private PortfolioApiJsonSerializerService apiJsonSerializerService;
private final String entityType = "OFFICE";
@Autowired
private PlatformSecurityContext context;
@GET
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public String retrieveOffices(@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(entityType);
Set<String> typicalResponseParameters = new HashSet<String>(
Arrays.asList("id", "name", "nameDecorated", "externalId", "openingDate",
"hierarchy", "parentId", "parentName"));
@@ -75,6 +82,8 @@ public class OfficesApiResource {
@Produces({MediaType.APPLICATION_JSON})
public String retrieveOfficeTemplate(@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(entityType);
Set<String> typicalResponseParameters = new HashSet<String>(
Arrays.asList("id", "name", "nameDecorated", "externalId", "openingDate",
"hierarchy", "parentId", "parentName", "allowedParents"));
@@ -106,7 +115,9 @@ public class OfficesApiResource {
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public String retreiveOffice(@PathParam("officeId") final Long officeId, @Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(entityType);
Set<String> typicalResponseParameters = new HashSet<String>(
Arrays.asList("id", "name", "nameDecorated", "externalId", "openingDate",
"hierarchy", "parentId", "parentName"));
@@ -1,8 +1,10 @@
package org.mifosng.platform.makerchecker.service;
public interface PortfolioMakerCheckerWriteService {
//TODO - permissions on this to be done after development completes
Long logNewEntry(String taskName, String taskJson);
Long approveEntry(Long id);
}
@@ -6,12 +6,13 @@ import org.springframework.security.access.prepost.PreAuthorize;
public interface OfficeWritePlatformService {
@PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER')")
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'CREATE_OFFICE')")
Long createOffice(final OfficeCommand command);
@PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER')")
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'UPDATE_OFFICE')")
Long updateOffice(final OfficeCommand command);
@PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER')")
//TODO - complete permissions for office transactions when more functionality add or it is replaced by simple accounting equivalent (JPW)
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER')")
Long externalBranchMoneyTransfer(BranchMoneyTransferCommand command);
}
@@ -356,6 +356,10 @@ public class AppUser extends AbstractAuditableCustom<AppUser, Long> implements
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
} else if (entityType.equalsIgnoreCase("LOAN")) {
higherPermission = "PORTFOLIO_MANAGEMENT_SUPER_USER";
} else if (entityType.equalsIgnoreCase("OFFICE")) {
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
} else if (entityType.equalsIgnoreCase("OFFICETRANSACTION")) {
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
}
if (!(higherPermission.equals(""))) {