Java Code Examples for org.springframework.security.acls.model.AccessControlEntry#getSid()

The following examples show how to use org.springframework.security.acls.model.AccessControlEntry#getSid() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccessService.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
public List<String> getAllAclSids(Acl acl, String type) {
    if (null == acl) {
        return Collections.emptyList();
    }

    List<String> result = new ArrayList<>();
    for (AccessControlEntry ace : acl.getEntries()) {
        String name = null;
        if (type.equalsIgnoreCase(MetadataConstants.TYPE_USER) && ace.getSid() instanceof PrincipalSid) {
            name = ((PrincipalSid) ace.getSid()).getPrincipal();
        }
        if (type.equalsIgnoreCase(MetadataConstants.TYPE_GROUP) && ace.getSid() instanceof GrantedAuthoritySid) {
            name = ((GrantedAuthoritySid) ace.getSid()).getGrantedAuthority();
        }
        if (!StringUtils.isBlank(name)) {
            result.add(name);
        }
    }
    return result;
}
 
Example 2
Source File: AccessService.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private Map<String, Integer> getProjectPermission(String project) {
    Map<String, Integer> SidWithPermission = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

    String uuid = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv()).getProject(project).getUuid();
    AclEntity ae = getAclEntity(AclEntityType.PROJECT_INSTANCE, uuid);
    Acl acl = getAcl(ae);
    if (acl != null && acl.getEntries() != null) {
        List<AccessControlEntry> aces = acl.getEntries();
        for (AccessControlEntry ace : aces) {
            Sid sid = ace.getSid();
            if (sid instanceof PrincipalSid) {
                String principal = ((PrincipalSid) sid).getPrincipal();
                SidWithPermission.put(principal, ace.getPermission().getMask());
            }
            if (sid instanceof GrantedAuthoritySid) {
                String grantedAuthority = ((GrantedAuthoritySid) sid).getGrantedAuthority();
                SidWithPermission.put(grantedAuthority, ace.getPermission().getMask());
            }
        }
    }
    return SidWithPermission;
}
 
Example 3
Source File: MigrationService.java    From kylin with Apache License 2.0 6 votes vote down vote up
public List<String> getCubeAdmins(CubeInstance cubeInstance) {
    ProjectInstance prjInstance = cubeInstance.getProjectInstance();
    AclEntity ae = accessService.getAclEntity("ProjectInstance", prjInstance.getUuid());
    logger.info("ProjectUUID : " + prjInstance.getUuid());
    Acl acl = accessService.getAcl(ae);

    String mailSuffix = KylinConfig.getInstanceFromEnv().getNotificationMailSuffix();
    List<String> cubeAdmins = Lists.newArrayList();
    if (acl != null) {
        for (AccessControlEntry ace : acl.getEntries()) {
            if (ace.getPermission().getMask() == 16) {
                PrincipalSid ps = (PrincipalSid) ace.getSid();
                cubeAdmins.add(ps.getPrincipal() + mailSuffix);
            }
        }
    }

    if (cubeAdmins.isEmpty()) {
        throw new BadRequestException("Cube access list is null, please add at least one role in it.");
    }
    return cubeAdmins;
}
 
Example 4
Source File: AccessService.java    From kylin with Apache License 2.0 6 votes vote down vote up
public List<String> getAllAclSids(Acl acl, String type) {
    if (null == acl) {
        return Collections.emptyList();
    }

    List<String> result = new ArrayList<>();
    for (AccessControlEntry ace : acl.getEntries()) {
        String name = null;
        if (type.equalsIgnoreCase(MetadataConstants.TYPE_USER) && ace.getSid() instanceof PrincipalSid) {
            name = ((PrincipalSid) ace.getSid()).getPrincipal();
        }
        if (type.equalsIgnoreCase(MetadataConstants.TYPE_GROUP) && ace.getSid() instanceof GrantedAuthoritySid) {
            name = ((GrantedAuthoritySid) ace.getSid()).getGrantedAuthority();
        }
        if (!StringUtils.isBlank(name)) {
            result.add(name);
        }
    }
    return result;
}
 
Example 5
Source File: AccessService.java    From kylin with Apache License 2.0 6 votes vote down vote up
private Map<String, Integer> getProjectPermission(String project) {
    Map<String, Integer> SidWithPermission = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

    String uuid = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv()).getProject(project).getUuid();
    AclEntity ae = getAclEntity(AclEntityType.PROJECT_INSTANCE, uuid);
    Acl acl = getAcl(ae);
    if (acl != null && acl.getEntries() != null) {
        List<AccessControlEntry> aces = acl.getEntries();
        for (AccessControlEntry ace : aces) {
            Sid sid = ace.getSid();
            if (sid instanceof PrincipalSid) {
                String principal = ((PrincipalSid) sid).getPrincipal();
                SidWithPermission.put(principal, ace.getPermission().getMask());
            }
            if (sid instanceof GrantedAuthoritySid) {
                String grantedAuthority = ((GrantedAuthoritySid) sid).getGrantedAuthority();
                SidWithPermission.put(grantedAuthority, ace.getPermission().getMask());
            }
        }
    }
    return SidWithPermission;
}
 
Example 6
Source File: LegacyAceInfo.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
public LegacyAceInfo(AccessControlEntry ace) {
    super();
    this.sidInfo = new SidInfo(ace.getSid());
    this.permissionMask = ace.getPermission().getMask();
}
 
Example 7
Source File: TenantBasedPermissionGrantedStrategy.java    From haven-platform with Apache License 2.0 4 votes vote down vote up
@Override
public PermissionData getPermission(Acl acl, List<Sid> sids) {
    Assert.notNull(tenantsService, "tenantsService is null");
    Assert.notNull(userDetailsService, "userDetailsService is null");

    final Sid ownerSid = acl.getOwner();
    final String ownerTenantId = getTenantFromSid(ownerSid);
    if(ownerTenantId == MultiTenancySupport.NO_TENANT) {
        throw new RuntimeException("Can not retrieve tenant from acl owner: acl.objectIdentity=" + acl.getObjectIdentity().getIdentifier());
    }

    final String currentPrincipalTenant = getPrincipalSidTenant(sids);

    PermissionGrantingContext pgc = new PermissionGrantingContext(this, ownerSid, currentPrincipalTenant);
    // below code based on DefaultPermissionGrantingStrategy
    final List<AccessControlEntry> aces = acl.getEntries();
    pgc.setHasAces(!aces.isEmpty());

    PermissionData.Builder pb = PermissionData.builder();
    pb.add(defaultBehavior.getPermission(pgc));

    // !! not use foreach here
    for(int aceIndex = 0; aceIndex < aces.size(); ++ aceIndex) {
        AccessControlEntry ace = aces.get(aceIndex);
        Sid aceSid = ace.getSid();
        final String aceTenant = getTenantFromSid(aceSid);
        for(int sidIndex = 0; sidIndex < sids.size(); ++sidIndex) {
            final Sid sid = sids.get(sidIndex);
            pgc.setCurrentSid(sid);

            //root SIDs consume all ACE
            if(aceTenant != null && !pgc.getCurrentTenants().contains(aceTenant)) {
                continue;
            }
            if(!compareSids(sid, aceSid)) {
                continue;
            }

            Permission acep = ace.getPermission();
            if(ace.isGranting()) {
                pb.add(acep);
            } else {
                pb.remove(acep);
            }
        }
    }
    //TODO handle ACL inheriting
    return pb.build();
}
 
Example 8
Source File: LegacyAceInfo.java    From kylin with Apache License 2.0 4 votes vote down vote up
public LegacyAceInfo(AccessControlEntry ace) {
    super();
    this.sidInfo = new SidInfo(ace.getSid());
    this.permissionMask = ace.getPermission().getMask();
}
 
Example 9
Source File: AclService.java    From Kylin with Apache License 2.0 4 votes vote down vote up
public AceInfo(AccessControlEntry ace) {
    super();
    this.sidInfo = new SidInfo(ace.getSid());
    this.permissionMask = ace.getPermission().getMask();
}