Search in sources :

Example 1 with PrincipalSid

use of org.springframework.security.acls.domain.PrincipalSid in project spring-security by spring-projects.

the class AdminPermissionController method addPermission.

/**
	 * Handles submission of the "add permission" form.
	 */
@RequestMapping(value = "/secure/addPermission.htm", method = RequestMethod.POST)
public String addPermission(AddPermission addPermission, BindingResult result, ModelMap model) {
    addPermissionValidator.validate(addPermission, result);
    if (result.hasErrors()) {
        model.put("recipients", listRecipients());
        model.put("permissions", listPermissions());
        return "addPermission";
    }
    PrincipalSid sid = new PrincipalSid(addPermission.getRecipient());
    Permission permission = permissionFactory.buildFromMask(addPermission.getPermission());
    try {
        contactManager.addPermission(addPermission.getContact(), sid, permission);
    } catch (DataAccessException existingPermission) {
        existingPermission.printStackTrace();
        result.rejectValue("recipient", "err.recipientExistsForContact", "Addition failure.");
        model.put("recipients", listRecipients());
        model.put("permissions", listPermissions());
        return "addPermission";
    }
    return "redirect:/secure/index.htm";
}
Also used : Permission(org.springframework.security.acls.model.Permission) BasePermission(org.springframework.security.acls.domain.BasePermission) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) DataAccessException(org.springframework.dao.DataAccessException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with PrincipalSid

use of org.springframework.security.acls.domain.PrincipalSid in project spring-security by spring-projects.

the class AdminPermissionController method deletePermission.

/**
	 * Deletes a permission
	 */
@RequestMapping(value = "/secure/deletePermission.htm")
public ModelAndView deletePermission(@RequestParam("contactId") int contactId, @RequestParam("sid") String sid, @RequestParam("permission") int mask) {
    Contact contact = contactManager.getById(new Long(contactId));
    Sid sidObject = new PrincipalSid(sid);
    Permission permission = permissionFactory.buildFromMask(mask);
    contactManager.deletePermission(contact, sidObject, permission);
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("contact", contact);
    model.put("sid", sidObject);
    model.put("permission", permission);
    return new ModelAndView("deletePermission", "model", model);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Permission(org.springframework.security.acls.model.Permission) BasePermission(org.springframework.security.acls.domain.BasePermission) ModelAndView(org.springframework.web.servlet.ModelAndView) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Sid(org.springframework.security.acls.model.Sid) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with PrincipalSid

use of org.springframework.security.acls.domain.PrincipalSid in project spring-security by spring-projects.

the class ContactManagerBackend method create.

public void create(Contact contact) {
    // Create the Contact itself
    contact.setId(new Long(counter++));
    contactDao.create(contact);
    // Grant the current principal administrative permission to the contact
    addPermission(contact, new PrincipalSid(getUsername()), BasePermission.ADMINISTRATION);
    if (logger.isDebugEnabled()) {
        logger.debug("Created contact " + contact + " and granted admin permission to recipient " + getUsername());
    }
}
Also used : PrincipalSid(org.springframework.security.acls.domain.PrincipalSid)

Example 4 with PrincipalSid

use of org.springframework.security.acls.domain.PrincipalSid in project spring-security by spring-projects.

the class JdbcAclServiceTests method readAclByIdMissingAcl.

// SEC-1898
@Test(expected = NotFoundException.class)
public void readAclByIdMissingAcl() {
    Map<ObjectIdentity, Acl> result = new HashMap<ObjectIdentity, Acl>();
    when(lookupStrategy.readAclsById(anyListOf(ObjectIdentity.class), anyListOf(Sid.class))).thenReturn(result);
    ObjectIdentity objectIdentity = new ObjectIdentityImpl(Object.class, 1);
    List<Sid> sids = Arrays.<Sid>asList(new PrincipalSid("user"));
    aclService.readAclById(objectIdentity, sids);
}
Also used : ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) HashMap(java.util.HashMap) ObjectIdentityImpl(org.springframework.security.acls.domain.ObjectIdentityImpl) Acl(org.springframework.security.acls.model.Acl) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Sid(org.springframework.security.acls.model.Sid) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Test(org.junit.Test)

Example 5 with PrincipalSid

use of org.springframework.security.acls.domain.PrincipalSid in project spring-security by spring-projects.

the class JdbcMutableAclServiceTests method deleteAclRemovesRowsFromDatabase.

@Test
@Transactional
public void deleteAclRemovesRowsFromDatabase() throws Exception {
    SecurityContextHolder.getContext().setAuthentication(auth);
    MutableAcl child = jdbcMutableAclService.createAcl(childOid);
    child.insertAce(0, BasePermission.DELETE, new PrincipalSid(auth), false);
    jdbcMutableAclService.updateAcl(child);
    // Remove the child and check all related database rows were removed accordingly
    jdbcMutableAclService.deleteAcl(childOid, false);
    assertThat(jdbcTemplate.queryForList(SELECT_ALL_CLASSES, new Object[] { TARGET_CLASS })).hasSize(1);
    assertThat(jdbcTemplate.queryForList("select * from acl_object_identity")).isEmpty();
    assertThat(jdbcTemplate.queryForList("select * from acl_entry")).isEmpty();
    // Check the cache
    assertThat(aclCache.getFromCache(childOid)).isNull();
    assertThat(aclCache.getFromCache(Long.valueOf(102))).isNull();
}
Also used : MutableAcl(org.springframework.security.acls.model.MutableAcl) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)21 Test (org.junit.Test)13 GrantedAuthoritySid (org.springframework.security.acls.domain.GrantedAuthoritySid)9 Sid (org.springframework.security.acls.model.Sid)9 ObjectIdentityImpl (org.springframework.security.acls.domain.ObjectIdentityImpl)8 MutableAcl (org.springframework.security.acls.model.MutableAcl)8 Authentication (org.springframework.security.core.Authentication)8 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)7 ObjectIdentity (org.springframework.security.acls.model.ObjectIdentity)6 BasePermission (org.springframework.security.acls.domain.BasePermission)5 Permission (org.springframework.security.acls.model.Permission)5 Transactional (org.springframework.transaction.annotation.Transactional)5 Acl (org.springframework.security.acls.model.Acl)3 HashMap (java.util.HashMap)2 AclImpl (org.springframework.security.acls.domain.AclImpl)2 CumulativePermission (org.springframework.security.acls.domain.CumulativePermission)2 SidRetrievalStrategyImpl (org.springframework.security.acls.domain.SidRetrievalStrategyImpl)2 NotFoundException (org.springframework.security.acls.model.NotFoundException)2 SidRetrievalStrategy (org.springframework.security.acls.model.SidRetrievalStrategy)2 CustomSid (org.springframework.security.acls.sid.CustomSid)2