2017-10-18 1 views
0

Wie kann ich Benutzerzugriff im Frühjahr Sicherheit ACL mit MutableAclService löschen. wird dieser Code ist okSo entfernen Sie AccessControlEntry (acl_entry) für bestimmte Sid in Spring Security acl?

private void deleteEntry(Long id){ 

     ObjectIdentity objectIdentity = new ObjectIdentityImpl(OrganizationStructure.class, id); 

     Sid user = new PrincipalSid("admin"); 
     Permission p1 = BasePermission.READ; 

     try { 
      MutableAcl acl = (MutableAcl) mutableAclService.readAclById(objectIdentity); 
      acl.getEntries().forEach(c->{ 
       System.out.println(c.toString()); 
       if(c.getSid().equals(user)) 
        acl.getEntries().remove(c); 
      }); 
      mutableAclService.updateAcl(acl); 

     } catch (NotFoundException nfe) { 
     } 

    } 

Antwort

1

Nach Versuch finde ich, wie kann ich Eintrag

private void deleteEntry(Long id) { 
     ObjectIdentity objectIdentity = new ObjectIdentityImpl(OrganizationStructure.class, id); 
     Sid user = new PrincipalSid(SecurityUtility.getAuthenticatedUser().getUsername()); 
     try { 
      MutableAcl acl = (MutableAcl) mutableAclService.readAclById(objectIdentity); 
      Consumer<AccessControlEntry> style = (AccessControlEntry p) -> System.out.println("id:"+p.getSid()); 
      acl.getEntries().forEach(style); 

      for (int i = 0; i < acl.getEntries().size(); i++) { 
       if (acl.getEntries().get(i).getSid().toString().equals(user.toString())) { 
        acl.deleteAce(i); 
        break; 
       } 
      } 

      acl.getEntries().forEach(style); 
      mutableAclService.updateAcl(acl); 
     } catch (NotFoundException nfe) { 
     } 

    } 
entfernen
Verwandte Themen