Don't Allow other office user to Update the client
Restrict other office user to update group or client details
This commit is contained in:
+32
@@ -0,0 +1,32 @@
|
|||||||
|
package org.mifosplatform.infrastructure.core.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link RuntimeException} thrown when the authenticated user don't have
|
||||||
|
* enough permissions to access.
|
||||||
|
*/
|
||||||
|
public abstract class AbstractPlatformAccessDeniedException extends RuntimeException {
|
||||||
|
|
||||||
|
private final String globalisationMessageCode;
|
||||||
|
private final String defaultUserMessage;
|
||||||
|
private final Object[] defaultUserMessageArgs;
|
||||||
|
|
||||||
|
public AbstractPlatformAccessDeniedException(final String globalisationMessageCode, final String defaultUserMessage,
|
||||||
|
final Object... defaultUserMessageArgs) {
|
||||||
|
this.globalisationMessageCode = globalisationMessageCode;
|
||||||
|
this.defaultUserMessage = defaultUserMessage;
|
||||||
|
this.defaultUserMessageArgs = defaultUserMessageArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGlobalisationMessageCode() {
|
||||||
|
return this.globalisationMessageCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDefaultUserMessage() {
|
||||||
|
return this.defaultUserMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object[] getDefaultUserMessageArgs() {
|
||||||
|
return this.defaultUserMessageArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package org.mifosplatform.infrastructure.security.exception;
|
||||||
|
|
||||||
|
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformAccessDeniedException;
|
||||||
|
|
||||||
|
public class PermissionDeniedException extends AbstractPlatformAccessDeniedException {
|
||||||
|
|
||||||
|
public PermissionDeniedException(final String code, final String defaultMessage, final Long userId) {
|
||||||
|
super(code, defaultMessage, userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -389,5 +389,9 @@ public final class Client extends AbstractPersistable<Long> {
|
|||||||
public void setDisplayName(String displayName) {
|
public void setDisplayName(String displayName) {
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Office getOffice() {
|
||||||
|
return this.office;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+14
-1
@@ -16,6 +16,7 @@ import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
|||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||||
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
|
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
|
||||||
|
import org.mifosplatform.infrastructure.security.exception.PermissionDeniedException;
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.mifosplatform.organisation.office.domain.Office;
|
import org.mifosplatform.organisation.office.domain.Office;
|
||||||
import org.mifosplatform.organisation.office.domain.OfficeRepository;
|
import org.mifosplatform.organisation.office.domain.OfficeRepository;
|
||||||
@@ -32,6 +33,7 @@ import org.mifosplatform.portfolio.group.domain.GroupRepository;
|
|||||||
import org.mifosplatform.portfolio.group.exception.GroupNotFoundException;
|
import org.mifosplatform.portfolio.group.exception.GroupNotFoundException;
|
||||||
import org.mifosplatform.portfolio.note.domain.Note;
|
import org.mifosplatform.portfolio.note.domain.Note;
|
||||||
import org.mifosplatform.portfolio.note.domain.NoteRepository;
|
import org.mifosplatform.portfolio.note.domain.NoteRepository;
|
||||||
|
import org.mifosplatform.useradministration.domain.AppUser;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -160,11 +162,22 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
|||||||
public CommandProcessingResult updateClient(final Long clientId, final JsonCommand command) {
|
public CommandProcessingResult updateClient(final Long clientId, final JsonCommand command) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
context.authenticatedUser();
|
AppUser user =context.authenticatedUser();
|
||||||
|
|
||||||
this.fromApiJsonDeserializer.validateForUpdate(command.json());
|
this.fromApiJsonDeserializer.validateForUpdate(command.json());
|
||||||
|
|
||||||
final Client clientForUpdate = this.clientRepository.findOneWithNotFoundDetection(clientId);
|
final Client clientForUpdate = this.clientRepository.findOneWithNotFoundDetection(clientId);
|
||||||
|
final String clientHierarchy = clientForUpdate.getOffice().getHierarchy();
|
||||||
|
|
||||||
|
//Don't allow other office user to update
|
||||||
|
final Office loginUserOffice = user.getOffice();
|
||||||
|
final String userHierarchy = loginUserOffice.getHierarchy();
|
||||||
|
|
||||||
|
if (!clientHierarchy.startsWith(userHierarchy)) {
|
||||||
|
final String code = "error.msg.not.enough.permissions.to.access.resource";
|
||||||
|
final String defaultMessage = "The User with id "+user.getId()+" don't have permission to update this client";
|
||||||
|
throw new PermissionDeniedException(code, defaultMessage, user.getId());
|
||||||
|
}
|
||||||
|
|
||||||
final Map<String, Object> changes = clientForUpdate.update(command);
|
final Map<String, Object> changes = clientForUpdate.update(command);
|
||||||
|
|
||||||
|
|||||||
@@ -370,4 +370,8 @@ public final class Group extends AbstractPersistable<Long> {
|
|||||||
public void setParent(final Group parent) {
|
public void setParent(final Group parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Office getOffice() {
|
||||||
|
return this.office;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+15
@@ -21,6 +21,7 @@ import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
|||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||||
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
|
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
|
||||||
|
import org.mifosplatform.infrastructure.security.exception.PermissionDeniedException;
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.mifosplatform.organisation.office.domain.Office;
|
import org.mifosplatform.organisation.office.domain.Office;
|
||||||
import org.mifosplatform.organisation.office.domain.OfficeRepository;
|
import org.mifosplatform.organisation.office.domain.OfficeRepository;
|
||||||
@@ -45,6 +46,7 @@ import org.mifosplatform.portfolio.loanaccount.domain.Loan;
|
|||||||
import org.mifosplatform.portfolio.loanaccount.domain.LoanRepository;
|
import org.mifosplatform.portfolio.loanaccount.domain.LoanRepository;
|
||||||
import org.mifosplatform.portfolio.note.domain.Note;
|
import org.mifosplatform.portfolio.note.domain.Note;
|
||||||
import org.mifosplatform.portfolio.note.domain.NoteRepository;
|
import org.mifosplatform.portfolio.note.domain.NoteRepository;
|
||||||
|
import org.mifosplatform.useradministration.domain.AppUser;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -213,8 +215,21 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
private CommandProcessingResult updateGroupingType(final Long groupId, final JsonCommand command, final GroupTypes groupingType) {
|
private CommandProcessingResult updateGroupingType(final Long groupId, final JsonCommand command, final GroupTypes groupingType) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
AppUser user = this.context.authenticatedUser();
|
||||||
final Group groupForUpdate = this.groupRepository.findOneWithNotFoundDetection(groupId);
|
final Group groupForUpdate = this.groupRepository.findOneWithNotFoundDetection(groupId);
|
||||||
final Long officeId = groupForUpdate.officeId();
|
final Long officeId = groupForUpdate.officeId();
|
||||||
|
final Office groupOffice = groupForUpdate.getOffice();
|
||||||
|
final String groupHierarchy = groupOffice.getHierarchy();
|
||||||
|
|
||||||
|
//Don't allow other office user to update
|
||||||
|
final Office loginUserOffice = this.context.authenticatedUser().getOffice();
|
||||||
|
final String userHierarchy = loginUserOffice.getHierarchy();
|
||||||
|
|
||||||
|
if (!groupHierarchy.startsWith(userHierarchy)) {
|
||||||
|
final String code = "error.msg.not.enough.permissions.to.access.resource";
|
||||||
|
final String defaultMessage = "The User with id "+user.getId()+" don't have permission to update this "+ groupingType.getValue();
|
||||||
|
throw new PermissionDeniedException(code, defaultMessage, user.getId());
|
||||||
|
}
|
||||||
|
|
||||||
final Map<String, Object> actualChanges = groupForUpdate.update(command);
|
final Map<String, Object> actualChanges = groupForUpdate.update(command);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user