Example usage for org.springframework.security.acls.model NotFoundException getLocalizedMessage

List of usage examples for org.springframework.security.acls.model NotFoundException getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:com.kylinolap.rest.service.AclService.java

@Override
public MutableAcl createAcl(ObjectIdentity objectIdentity) throws AlreadyExistsException {
    Acl acl = null;/*from w w  w  .  j av  a  2s .c o  m*/

    try {
        acl = readAclById(objectIdentity);
    } catch (NotFoundException e) {
    }
    if (null != acl) {
        throw new AlreadyExistsException("ACL of " + objectIdentity + " exists!");
    }

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    PrincipalSid sid = new PrincipalSid(auth);

    HTableInterface htable = null;
    try {
        htable = HBaseConnection.get(hbaseUrl).getTable(aclTableName);
        Put put = new Put(Bytes.toBytes(String.valueOf(objectIdentity.getIdentifier())));
        put.add(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_TYPE_COLUMN),
                Bytes.toBytes(objectIdentity.getType()));
        put.add(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_OWNER_COLUMN),
                sidSerializer.serialize(new SidInfo(sid)));
        put.add(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_ENTRY_INHERIT_COLUMN),
                Bytes.toBytes(true));

        htable.put(put);
        htable.flushCommits();

        logger.debug("ACL of " + objectIdentity + " created successfully.");
    } catch (IOException e) {
        logger.error(e.getLocalizedMessage(), e);
    } finally {
        IOUtils.closeQuietly(htable);
    }

    return (MutableAcl) readAclById(objectIdentity);
}

From source file:com.kylinolap.rest.service.AclService.java

@Override
public MutableAcl updateAcl(MutableAcl acl) throws NotFoundException {
    try {//  w  ww  .  ja v  a 2 s .  co  m
        readAclById(acl.getObjectIdentity());
    } catch (NotFoundException e) {
        throw e;
    }

    HTableInterface htable = null;
    try {
        htable = HBaseConnection.get(hbaseUrl).getTable(aclTableName);
        Delete delete = new Delete(Bytes.toBytes(String.valueOf(acl.getObjectIdentity().getIdentifier())));
        delete.deleteFamily(Bytes.toBytes(ACL_ACES_FAMILY));
        htable.delete(delete);

        Put put = new Put(Bytes.toBytes(String.valueOf(acl.getObjectIdentity().getIdentifier())));

        if (null != acl.getParentAcl()) {
            put.add(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_PARENT_COLUMN),
                    domainObjSerializer
                            .serialize(new DomainObjectInfo(acl.getParentAcl().getObjectIdentity())));
        }

        for (AccessControlEntry ace : acl.getEntries()) {
            AceInfo aceInfo = new AceInfo(ace);
            put.add(Bytes.toBytes(ACL_ACES_FAMILY), Bytes.toBytes(aceInfo.getSidInfo().getSid()),
                    aceSerializer.serialize(aceInfo));
        }

        if (!put.isEmpty()) {
            htable.put(put);
            htable.flushCommits();

            logger.debug("ACL of " + acl.getObjectIdentity() + " updated successfully.");
        }
    } catch (IOException e) {
        logger.error(e.getLocalizedMessage(), e);
    } finally {
        IOUtils.closeQuietly(htable);
    }

    return (MutableAcl) readAclById(acl.getObjectIdentity());
}