Search in sources :

Example 1 with SecurityException

use of org.motechproject.mds.exception.object.SecurityException 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 SecurityException

use of org.motechproject.mds.exception.object.SecurityException 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)

Aggregations

SecurityException (org.motechproject.mds.exception.object.SecurityException)2 SecurityMode (org.motechproject.mds.util.SecurityMode)2