Example usage for org.springframework.security.acls.domain GrantedAuthoritySid GrantedAuthoritySid

List of usage examples for org.springframework.security.acls.domain GrantedAuthoritySid GrantedAuthoritySid

Introduction

In this page you can find the example usage for org.springframework.security.acls.domain GrantedAuthoritySid GrantedAuthoritySid.

Prototype

public GrantedAuthoritySid(GrantedAuthority grantedAuthority) 

Source Link

Usage

From source file:net.projectmonkey.spring.acl.util.SidUtil.java

public static Sid createSid(final String authority, final boolean principal) {
    Sid toReturn = null;//from  w w  w . j  av a  2s  .  c  om
    if (principal) {
        toReturn = new PrincipalSid(authority);
    } else {
        toReturn = new GrantedAuthoritySid(authority);
    }
    return toReturn;
}

From source file:org.jtalks.common.service.security.AclBuilderImpl.java

/**
 * {@inheritDoc}//from  w ww . java2  s. c om
 */
@Override
public AclBuilder role(String role) {
    sids.add(new GrantedAuthoritySid(role));
    return this;
}

From source file:org.jtalks.common.service.security.AclManagerImplTest.java

@BeforeClass
public void setUpClass() {
    sids.add(new GrantedAuthoritySid(ROLE));
    sids.add(new PrincipalSid(USERNAME));
    permissions.add(BasePermission.READ);
}

From source file:org.jtalks.common.security.acl.sids.JtalksSidFactory.java

/**
 * {@inheritDoc}/*  w  w  w .ja  v a  2 s .c om*/
 */
@Override
public List<? extends Sid> createGrantedAuthorities(Collection<? extends GrantedAuthority> grantedAuthorities) {
    List<Sid> sids = new ArrayList<Sid>();
    for (GrantedAuthority authority : grantedAuthorities) {
        sids.add(new GrantedAuthoritySid(authority));
    }
    return sids;
}

From source file:org.jtalks.common.service.security.AclManagerImplTest.java

@Test
public void testGrantOnObjectWithNotExistingAcl() throws Exception {
    ObjectIdentity objectIdentity = new ObjectIdentityImpl(target.getClass(), ID);
    MutableAcl objectAcl = new AclImpl(objectIdentity, 2L, mock(AclAuthorizationStrategy.class),
            mock(AuditLogger.class));
    when(aclService.readAclById(objectIdentity)).thenThrow(new NotFoundException(""));
    when(aclService.createAcl(objectIdentity)).thenReturn(objectAcl);

    manager.grant(sids, permissions, target);

    assertGranted(objectAcl, new PrincipalSid(USERNAME), BasePermission.READ, "Permission to user not granted");
    assertGranted(objectAcl, new GrantedAuthoritySid(ROLE), BasePermission.READ,
            "Permission to ROLE_USER not granted");
    verify(aclService).readAclById(objectIdentity);
    verify(aclService).createAcl(objectIdentity);
    verify(aclService).updateAcl(objectAcl);
}

From source file:net.projectmonkey.spring.acl.hbase.repository.AccessControlEntryValueTest.java

@Test
public void keyCreatedCorrectlyForGrantingPermissionAndNONPrincipal() {
    Sid sid = new GrantedAuthoritySid(AUTHORITY);
    AccessControlEntryValue underTest = new AccessControlEntryValue(ID, sid, PERMISSION, true);
    assertTrue(underTest.isGranting());//w w  w  .  j  av  a 2s.c  o  m
    assertTrue(ArrayUtils.isEquals(GRANTING_NON_PRINCIPAL_KEY_BYTES, underTest.getKey()));
    assertEquals(ID, underTest.getId());
    assertEquals(sid, underTest.getSid());
    assertEquals(AUTHORITY, underTest.getAuthority());
    assertEquals(PERMISSION, underTest.getPermission());
}

From source file:net.projectmonkey.spring.acl.hbase.repository.AclRecordTest.java

@Test
public void creatingRecordFromBytesWithNonPrincipalOwner() {
    NavigableMap<byte[], byte[]> familyMap = recordMap(String.class, false);
    AclRecord underTest = new AclRecord(ID.getBytes(), familyMap, new StringAclIdentifierConverter());

    ObjectIdentity identity = new ObjectIdentityImpl(TYPE, ID);

    assertEquals(identity, underTest.getIdentity());
    assertTrue(ArrayUtils.isEquals(ID.getBytes(), underTest.getKey()));
    assertTrue(ArrayUtils.isEquals(String.class.getName().getBytes(), underTest.getIdTypeBytes()));
    assertEquals(new GrantedAuthoritySid(SOME_PRINCIPAL), underTest.getOwner());
}

From source file:org.jtalks.common.service.security.AclManagerImplTest.java

@Test
public void testGrantOnObjectWithExistingAcl() throws Exception {
    ObjectIdentity objectIdentity = new ObjectIdentityImpl(target.getClass(), ID);
    MutableAcl objectAcl = new AclImpl(objectIdentity, 2L, mock(AclAuthorizationStrategy.class),
            mock(AuditLogger.class));
    when(aclService.readAclById(objectIdentity)).thenReturn(objectAcl);

    manager.grant(sids, permissions, target);

    assertGranted(objectAcl, new PrincipalSid(USERNAME), BasePermission.READ, "Permission to user not granted");
    assertGranted(objectAcl, new GrantedAuthoritySid(ROLE), BasePermission.READ,
            "Permission to ROLE_USER not granted");
    verify(aclService).readAclById(objectIdentity);
    verify(aclService).updateAcl(objectAcl);
}

From source file:es.ucm.fdi.dalgs.acl.service.AclObjectService.java

public boolean addACLToObject(Long id_object, String name_class) {

    Authentication authentication = null;
    ObjectIdentity objectIdentity = new ObjectIdentityImpl(name_class, id_object);

    // Create or update the relevant ACL
    MutableAcl acl = null;//from   w ww  .  ja  v a 2 s . c o  m
    try {
        acl = (MutableAcl) mutableAclService.readAclById(objectIdentity);
    } catch (NotFoundException nfe) {
        acl = mutableAclService.createAcl(objectIdentity);
    }

    try {
        authentication = SecurityContextHolder.getContext().getAuthentication();
        List<Sid> sids = sidRetrievalStrategy.getSids(authentication);
        acl = (MutableAcl) this.mutableAclService.readAclById(objectIdentity, sids);
    } catch (NotFoundException nfe) {
        acl = mutableAclService.createAcl(objectIdentity);
        return false;
    }

    if (authentication.getPrincipal() != "anonymousUser") {
        User user = (User) authentication.getPrincipal();

        acl.insertAce(0, BasePermission.ADMINISTRATION, new PrincipalSid(user.getUsername()), true);
        acl.insertAce(1, BasePermission.DELETE, new GrantedAuthoritySid("ROLE_ADMIN"), true);

    }
    acl.insertAce(0, BasePermission.ADMINISTRATION, new GrantedAuthoritySid("ROLE_ADMIN"), true);
    acl.insertAce(1, BasePermission.DELETE, new GrantedAuthoritySid("ROLE_ADMIN"), true);

    /*
     * // READ access for users with ROLE_USER acl.insertAce(2,
     * BasePermission.READ, new GrantedAuthoritySid( "ROLE_USER"), true);
     */
    return true;
}

From source file:net.projectmonkey.spring.acl.hbase.repository.AccessControlEntryValueTest.java

@Test
public void keyCreatedCorrectlyForDenyingPermissionAndNonPrincipal() {
    Sid sid = new GrantedAuthoritySid(AUTHORITY);
    AccessControlEntryValue underTest = new AccessControlEntryValue(ID, sid, PERMISSION, false);
    assertFalse(underTest.isGranting());
    assertTrue(ArrayUtils.isEquals(DENYING_NON_PRINCIPAL_KEY_BYTES, underTest.getKey()));
    assertEquals(ID, underTest.getId());
    assertEquals(sid, underTest.getSid());
    assertEquals(AUTHORITY, underTest.getAuthority());
    assertEquals(PERMISSION, underTest.getPermission());
}