Search in sources :

Example 1 with SecurityMode

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();
        }
    }
}
Also used : SecurityMode(org.motechproject.mds.util.SecurityMode) SecurityException(org.motechproject.mds.exception.object.SecurityException)

Example 2 with SecurityMode

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();
        }
    }
}
Also used : SecurityMode(org.motechproject.mds.util.SecurityMode) SecurityException(org.motechproject.mds.exception.object.SecurityException)

Example 3 with SecurityMode

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);
    }
}
Also used : SecurityMode(org.motechproject.mds.util.SecurityMode) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with SecurityMode

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));
}
Also used : SecurityMode(org.motechproject.mds.util.SecurityMode)

Aggregations

SecurityMode (org.motechproject.mds.util.SecurityMode)4 SecurityException (org.motechproject.mds.exception.object.SecurityException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1