Example usage for org.springframework.security.acls.model MutableAcl insertAce

List of usage examples for org.springframework.security.acls.model MutableAcl insertAce

Introduction

In this page you can find the example usage for org.springframework.security.acls.model MutableAcl insertAce.

Prototype

void insertAce(int atIndexLocation, Permission permission, Sid sid, boolean granting) throws NotFoundException;

Source Link

Usage

From source file:com.sshdemo.common.security.acl.service.EwcmsAclService.java

@Override
public void addPermission(Object object, Sid sid, Permission permission) {
    ObjectIdentity objectIdentity = new ObjectIdentityImpl(object);

    MutableAcl acl = getMutableAcl(objectIdentity);
    acl.insertAce(acl.getEntries().size(), permission, sid, Boolean.TRUE);
    updateAcl(acl);//from ww  w.  j a va2 s. c  o m
}

From source file:org.bremersee.common.acl.test.AclServiceTests.java

@Test
public void testAcl() {
    LOG.info("Testing ...");

    RunAsUtil.runAs("tester", getRunAsRoles(), () -> {
        MutableAcl acl = aclService.createAcl(new ObjectIdentityImpl("TestObject", "100"));
        acl.setOwner(new PrincipalSid("tester"));
        acl.setEntriesInheriting(false);
        acl.setParent(null);//from w  w w.  jav a2 s.co  m
        acl.insertAce(acl.getEntries().size(), BasePermission.READ, new PrincipalSid("friend"), true);
        acl = aclService.updateAcl(acl);
        return acl;
    });

    MutableAcl acl = (MutableAcl) aclService.readAclById(new ObjectIdentityImpl("TestObject", "100"));
    LOG.info("Acl: " + acl);

    boolean friendCanRead = permissionEvaluator.hasPermission(
            new RunAsAuthentication("friend", new String[] { "ROLE_USER" }), "100", "TestObject", "READ");

    LOG.info("Successful? " + friendCanRead);
    TestCase.assertEquals(true, friendCanRead);

}

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

@Test
public void testRevoke() {
    ObjectIdentity objectIdentity = new ObjectIdentityImpl(target.getClass(), ID);
    MutableAcl objectAcl = new AclImpl(objectIdentity, 2L, mock(AclAuthorizationStrategy.class),
            mock(AuditLogger.class));
    objectAcl.insertAce(objectAcl.getEntries().size(), BasePermission.READ, new PrincipalSid(USERNAME), true);
    objectAcl.insertAce(objectAcl.getEntries().size(), BasePermission.READ, new GrantedAuthoritySid(ROLE),
            true);//  w  ww . ja v a 2s . c o  m
    when(aclService.readAclById(objectIdentity)).thenReturn(objectAcl);

    manager.revoke(sids, permissions, target);

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

From source file:com.cedac.security.acls.mongo.MongoMutableAclServiceTests.java

@Test
@ShouldMatchDataSet/*  w  w w.j  a v a  2s .co m*/
public void updateAcl_addEntries() {
    MutableAcl acl = (MutableAcl) fixture
            .readAclById(new ObjectIdentityImpl("com.cedac.smartresidence.profile.domain.Device", "1.1.2"));
    acl.insertAce(0, BasePermission.READ, new GrantedAuthoritySid("ROLE_USER"), true);
    acl.insertAce(1, BasePermission.WRITE, new GrantedAuthoritySid("ROLE_USER"), true);

    fixture.updateAcl(acl);
}

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

@Test
public void testDelete() throws Exception {
    ObjectIdentity objectIdentity = new ObjectIdentityImpl(target.getClass(), ID);
    MutableAcl objectAcl = new AclImpl(objectIdentity, 2L, mock(AclAuthorizationStrategy.class),
            mock(AuditLogger.class));
    objectAcl.insertAce(objectAcl.getEntries().size(), BasePermission.READ, new PrincipalSid(USERNAME), true);
    objectAcl.insertAce(objectAcl.getEntries().size(), BasePermission.READ, new GrantedAuthoritySid(ROLE),
            true);// w w w .j av  a  2 s  . co  m
    objectAcl.insertAce(objectAcl.getEntries().size(), BasePermission.DELETE, new GrantedAuthoritySid(ROLE),
            true);
    when(aclService.readAclById(objectIdentity)).thenReturn(objectAcl);

    manager.delete(sids, permissions, target);

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

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

@Test
public void update() {
    ObjectIdentityImpl id = new ObjectIdentityImpl(HBaseACLRepository.class, "id1");
    MutableAcl acl1 = underTest.create(id);
    assertNotNull(acl1);//from w  w  w  .  ja v a  2  s .c om
    assertTrue(underTest.isThereAnAclFor(id));

    acl1.insertAce(0, BasePermission.CREATE, new PrincipalSid(SOME_PRINCIPAL), true);
    underTest.update(acl1);

    Acl returned = underTest.getAclById(id);

    List<AccessControlEntry> entries = returned.getEntries();
    assertEquals(1, entries.size());
}

From source file:de.iew.services.impl.AclEditorServiceImpl.java

public void grantAuthorityPermissionAt(MutableAcl acl, int index, Permission permission,
        Object securityIdentity) {
    Sid sid = makeAuthoritySid(securityIdentity);

    acl.insertAce(index, permission, sid, true);
    this.aclService.updateAcl(acl);
}

From source file:de.iew.services.impl.AclEditorServiceImpl.java

public void grantPrincipalPermissionAt(MutableAcl acl, int index, Permission permission,
        Object securityIdentity) {
    Sid sid = makePrincipalSid(securityIdentity);

    acl.insertAce(index, permission, sid, true);
    this.aclService.updateAcl(acl);
}

From source file:sample.contact.service.impl.MenuServiceImpl.java

public void addPermission(Menu menu, Sid recipient, Permission permission) {
    MutableAcl acl;
    ObjectIdentity oid = new ObjectIdentityImpl(Menu.class, menu.getId());

    try {/*from w w w .j  ava  2s  . c o m*/
        acl = (MutableAcl) mutableAclService.readAclById(oid);
    } catch (NotFoundException nfe) {
        acl = mutableAclService.createAcl(oid);
    }

    acl.insertAce(acl.getEntries().size(), permission, recipient, true);
    mutableAclService.updateAcl(acl);

    logger.debug("Added permission " + permission + " for Sid " + recipient + " menu " + menu);
}

From source file:org.createnet.raptor.auth.service.services.AclManagerService.java

@Retryable(maxAttempts = 3, value = AclManagerException.class, backoff = @Backoff(delay = 200, multiplier = 3))
private void isPermissionGranted(Permission permission, Sid sid, MutableAcl acl) {
    try {/*ww  w .ja v  a  2  s . c om*/
        try {
            acl.isGranted(Arrays.asList(permission), Arrays.asList(sid), false);
        } catch (NotFoundException e) {
            acl.insertAce(acl.getEntries().size(), permission, sid, true);
        }
    } catch (Exception e) {
        log.warn("Failed to add ACE: {}", e.getMessage());
        throw new AclManagerException(e);
    }
}