Search in sources :

Example 1 with IAclEntry

use of org.pentaho.platform.api.engine.IAclEntry in project pentaho-platform by pentaho.

the class PentahoBasicAclVoter method hasAccess.

public boolean hasAccess(final IPentahoSession session, final IAclHolder holder, final int mask) {
    Authentication auth = getAuthentication(session);
    // If we're not authenticated, default to no access and return.
    if (auth == null) {
        return false;
    }
    // admins can do anything they want!
    if (isPentahoAdministrator(session)) {
        return true;
    }
    IAclEntry[] effectiveAcls = getEffectiveAcls(session, holder);
    if ((effectiveAcls == null) || (effectiveAcls.length == 0)) {
        return false;
    }
    for (IAclEntry element : effectiveAcls) {
        IPentahoBasicAclEntry acl = (IPentahoBasicAclEntry) element;
        if (acl.isPermitted(mask)) {
            return true;
        }
    }
    return false;
}
Also used : IAclEntry(org.pentaho.platform.api.engine.IAclEntry) Authentication(org.springframework.security.core.Authentication) IPentahoBasicAclEntry(org.pentaho.platform.api.engine.IPentahoBasicAclEntry)

Example 2 with IAclEntry

use of org.pentaho.platform.api.engine.IAclEntry in project pentaho-platform by pentaho.

the class PentahoUserOverridesVoter method getEffectiveAcls.

@Override
public IAclEntry[] getEffectiveAcls(final IPentahoSession session, final IAclHolder holder) {
    Authentication auth = getAuthentication(session);
    // User is un-authenticated. Return no access controls.
    if (auth == null) {
        return null;
    }
    IAclEntry[] objectAcls = super.getEffectiveAcls(session, holder);
    if (objectAcls == null) {
        return null;
    }
    Object principal = auth.getPrincipal();
    String userName = null;
    if (principal instanceof UserDetails) {
        userName = ((UserDetails) principal).getUsername();
    } else {
        userName = principal.toString();
    }
    for (IAclEntry element : objectAcls) {
        // First, search for the user name in the objectAcls. If it's there,
        // then that
        // overrides anything else. It's the only acl returned.
        IPentahoBasicAclEntry entry = (IPentahoBasicAclEntry) element;
        String recipient = entry.getRecipient().toString();
        // ACL.
        if (recipient.equals(userName)) {
            return new IAclEntry[] { entry };
        }
    }
    // settings.
    return objectAcls;
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) IAclEntry(org.pentaho.platform.api.engine.IAclEntry) Authentication(org.springframework.security.core.Authentication) IPentahoBasicAclEntry(org.pentaho.platform.api.engine.IPentahoBasicAclEntry)

Example 3 with IAclEntry

use of org.pentaho.platform.api.engine.IAclEntry in project pentaho-platform by pentaho.

the class PentahoAllowAllAclVoter method getEffectiveAcls.

public IAclEntry[] getEffectiveAcls(final IPentahoSession session, final IAclHolder holder) {
    // Returns all the ACLs on the object which indicates that the
    // user has all the necessary acls to access the object.
    List allAcls = holder.getEffectiveAccessControls();
    IAclEntry[] acls = new IAclEntry[allAcls.size()];
    acls = (IAclEntry[]) allAcls.toArray(acls);
    return acls;
}
Also used : IAclEntry(org.pentaho.platform.api.engine.IAclEntry) List(java.util.List)

Example 4 with IAclEntry

use of org.pentaho.platform.api.engine.IAclEntry in project pentaho-platform by pentaho.

the class PentahoBasicAclVoter method getEffectiveAcl.

public PentahoAclEntry getEffectiveAcl(final IPentahoSession session, final IAclHolder holder) {
    // First, get all the ACLs on the object that apply to the user.
    IAclEntry[] effectiveAcls = getEffectiveAcls(session, holder);
    PentahoAclEntry entry = new PentahoAclEntry();
    entry.setMask(IPentahoAclEntry.PERM_NOTHING);
    // indicates their access.
    if ((effectiveAcls != null) && (effectiveAcls.length > 0)) {
        int[] allAcls = new int[effectiveAcls.length];
        for (int i = 0; i < effectiveAcls.length; i++) {
            allAcls[i] = ((IPentahoAclEntry) effectiveAcls[i]).getMask();
        }
        entry.addPermissions(allAcls);
        return entry;
    } else {
        return entry;
    }
}
Also used : IAclEntry(org.pentaho.platform.api.engine.IAclEntry) IPentahoAclEntry(org.pentaho.platform.api.engine.IPentahoAclEntry) PentahoAclEntry(org.pentaho.platform.engine.security.acls.PentahoAclEntry)

Example 5 with IAclEntry

use of org.pentaho.platform.api.engine.IAclEntry in project pentaho-platform by pentaho.

the class PentahoBasicAclVoter method getEffectiveAcls.

public IAclEntry[] getEffectiveAcls(final IPentahoSession session, final IAclHolder holder) {
    Authentication auth = getAuthentication(session);
    if (auth == null) {
        // No user, so no ACLs.
        return null;
    }
    List allAcls = holder.getEffectiveAccessControls();
    IAclEntry[] acls = new IAclEntry[allAcls.size()];
    acls = (IAclEntry[]) allAcls.toArray(acls);
    PentahoGrantedAuthorityEffectiveAclsResolver resolver = new PentahoGrantedAuthorityEffectiveAclsResolver();
    IAclEntry[] resolvedAcls = resolver.resolveEffectiveAcls(acls, auth);
    return resolvedAcls;
}
Also used : IAclEntry(org.pentaho.platform.api.engine.IAclEntry) Authentication(org.springframework.security.core.Authentication) PentahoGrantedAuthorityEffectiveAclsResolver(org.pentaho.platform.engine.security.acls.PentahoGrantedAuthorityEffectiveAclsResolver) List(java.util.List)

Aggregations

IAclEntry (org.pentaho.platform.api.engine.IAclEntry)5 Authentication (org.springframework.security.core.Authentication)3 List (java.util.List)2 IPentahoBasicAclEntry (org.pentaho.platform.api.engine.IPentahoBasicAclEntry)2 IPentahoAclEntry (org.pentaho.platform.api.engine.IPentahoAclEntry)1 PentahoAclEntry (org.pentaho.platform.engine.security.acls.PentahoAclEntry)1 PentahoGrantedAuthorityEffectiveAclsResolver (org.pentaho.platform.engine.security.acls.PentahoGrantedAuthorityEffectiveAclsResolver)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1