use of org.motechproject.mds.util.SecurityMode in project motech by motech.
the class InstanceServiceImpl method validateCredentialsForReading.
private void validateCredentialsForReading(EntityDto entity) {
boolean authorized = false;
SecurityMode securityMode = entity.getSecurityMode();
SecurityMode readOnlySecurityMode = entity.getReadOnlySecurityMode();
if (securityMode != null) {
Set<String> securityMembers = entity.getSecurityMembers();
authorized = entity.hasAccessToEntityFromSecurityMode(securityMode, securityMembers);
if (!authorized) {
if (readOnlySecurityMode != null) {
Set<String> readOnlySecurityMembers = entity.getReadOnlySecurityMembers();
authorized = entity.hasAccessToEntityFromSecurityMode(readOnlySecurityMode, readOnlySecurityMembers);
if (isAuthorizedByReadAccessOrIsInstanceRestriction(authorized, readOnlySecurityMode, securityMode)) {
throw new SecurityException();
}
}
}
}
if (!authorized && readOnlySecurityMode != null) {
Set<String> readOnlySecurityMembers = entity.getReadOnlySecurityMembers();
authorized = entity.hasAccessToEntityFromSecurityMode(readOnlySecurityMode, readOnlySecurityMembers);
if (!authorized && !readOnlySecurityMode.isInstanceRestriction()) {
throw new SecurityException();
}
}
}
use of org.motechproject.mds.util.SecurityMode in project motech by motech.
the class InstanceServiceImpl method validateCredentials.
private void validateCredentials(EntityDto entity) {
boolean authorized;
SecurityMode securityMode = entity.getSecurityMode();
if (securityMode != null) {
Set<String> securityMembers = entity.getSecurityMembers();
authorized = entity.hasAccessToEntityFromSecurityMode(securityMode, securityMembers);
if (!authorized && !securityMode.isInstanceRestriction()) {
throw new SecurityException();
}
}
}
use of org.motechproject.mds.util.SecurityMode in project motech by motech.
the class EntityServiceImpl method editSecurityForDraft.
private void editSecurityForDraft(EntityDraft draft, DraftData draftData) {
List value = (List) draftData.getValue(DraftData.VALUE);
if (value != null) {
String securityModeName = (String) value.get(0);
SecurityMode securityMode = SecurityMode.getEnumByName(securityModeName);
String readOnlySecurityModeName = (String) value.get(2);
SecurityMode readOnlySecurityMode;
if (readOnlySecurityModeName != null) {
readOnlySecurityMode = SecurityMode.getEnumByName(readOnlySecurityModeName);
} else {
readOnlySecurityMode = null;
}
List<String> securityMembers = (List<String>) value.get(1);
if (securityMembers != null) {
draft.setSecurity(securityMode, securityMembers);
} else {
draft.setSecurityMode(securityMode);
}
List<String> readOnlySecurityMembers = (List<String>) value.get(3);
if (readOnlySecurityMembers != null) {
draft.setReadOnlySecurity(readOnlySecurityMode, readOnlySecurityMembers);
} else {
draft.setReadOnlySecurityMode(readOnlySecurityMode);
}
allEntityDrafts.update(draft);
}
}
use of org.motechproject.mds.util.SecurityMode in project motech by motech.
the class EntityServiceImpl method hasAccessToEntity.
private boolean hasAccessToEntity(Entity entity) {
SecurityMode mode = entity.getSecurityMode();
Set<String> members = entity.getSecurityMembers();
SecurityMode readOnlyMode = entity.getReadOnlySecurityMode();
Set<String> readOnlyMembers = entity.getReadOnlySecurityMembers();
return (mode == null && readOnlyMode == null) || (hasAccessToEntityFromSecurityMode(mode, members) || hasAccessToEntityFromSecurityMode(readOnlyMode, readOnlyMembers));
}
Aggregations