/** * {@inheritDoc} */ @Override public String toString() { return "Role [name=" + name + ", version=" + this.getVersion() + ", created at=" + getCreatedAt() + ", by=" + getCreatedBy() + ", description=" + description + ", permissions=" + getPermissions() + ", includedRoles=" + getIncludedRoles() + "]"; }
@Override public Object process(Entry<String, Role> entry) { logger.debug("process.enter; entry: {}", entry); if (entry.getValue() == null) { String name = entry.getKey(); Role role = new Role(getVersion(), new Date(), getAdmin(), null, null, name, description); entry.setValue(role); auditEntity(AuditType.create, role); return role; } return null; }
@Override public void write(ObjectDataOutput out, Role xRole) throws IOException { super.writeEntity(out, xRole); out.writeUTF(xRole.getName()); out.writeUTF(xRole.getDescription()); // write permissions and roles List<Permission> perms = new ArrayList<Permission>(xRole.getPermissions().values()); out.writeObject(perms); out.writeObject(xRole.getIncludedRoles()); }
protected void getRecursivePermissions(Map<String, Permission> xPerms, String roleName) { Role role = getRoleCache().get(roleName); if (role != null) { if (role.getIncludedRoles().size() > 0) { for (String name: role.getIncludedRoles()) { getRecursivePermissions(xPerms, name); } } Collection<Permission> perms = role.getPermissions().values(); if (perms.size() > 0) { for (Permission perm: perms) { Permission xPerm = xPerms.get(perm.getResource()); if (xPerm == null) { xPerm = new Permission(perm.getResource()); xPerms.put(perm.getResource(), xPerm); } for (Permission.Value p: perm.getPermissions()) { xPerm.addPermission(p); } } } } }
protected void getRecursiveRoles(Set<String> xRoles, String roleName) { Role role = getRoleCache().get(roleName); if (role != null) { if (role.getIncludedRoles().size() > 0) { for (String name: role.getIncludedRoles()) { getRecursiveRoles(xRoles, name); } } xRoles.add(roleName); } }
@SuppressWarnings("unchecked") @Override protected Map<String, Role> loadEntities() { Map<String, Role> roles = new HashMap<String, Role>(); Collection<Role> cRoles = (Collection<Role>) cfg.getEntities(Role.class); for (Role role: cRoles) { roles.put(role.getName(), role); } return roles; }
@Override public Object process(Entry<String, Role> entry) { logger.debug("process.enter; entry: {}", entry); if (entry.getValue() != null) { Role role = entry.getValue(); if (role.getVersion() == getVersion()) { entry.setValue(null); auditEntity(AuditType.delete, role); return role; } else { // throw ex ? logger.warn("process; outdated role version: {}; entry version: {}; process terminated", getVersion(), entry.getValue().getVersion()); } } return null; }
@SuppressWarnings("unchecked") private void setupCaches() { boolean lite = !hasStorageMembers(hzInstance); if (lite) { String confName = System.getProperty(pn_access_filename); if (confName != null) { // TODO: get it from Spring context? AccessConfig cfg = new AccessConfig(confName); Collection<Role> rCache = (Collection<Role>) cfg.getEntities(Role.class); for (Role role: rCache) { roles.put(role.getName(), role); } Collection<User> uCache = (Collection<User>) cfg.getEntities(User.class); for (User user: uCache) { users.put(user.getLogin(), user); } } } else { copyCache(hzInstance.getMap(CN_SYS_ROLES), roles); copyCache(hzInstance.getMap(CN_SYS_USERS), users); } logger.trace("setupCaches.exit; lite: {}; initiated roles: {}; users {}", lite, roles.size(), users.size()); }
@ManagedOperation(description="Delete Role") @ManagedOperationParameters({ @ManagedOperationParameter(name = "name", description = "Role name")}) public boolean deleteRole(String name) { //return userCache.remove(login) != null; Role role = entityCache.get(name); if (role != null) { Object result = entityCache.executeOnKey(name, new RoleRemover(role.getVersion(), getCurrentUser())); logger.debug("deleteRole; execution result: {}", result); return result != null; } return false; }
@Override @SuppressWarnings("unchecked") public Role read(ObjectDataInput in) throws IOException { Object[] entity = super.readEntity(in); String name = in.readUTF(); String description = in.readUTF(); List<Permission> perms = (List<Permission>) in.readObject(); Set<String> roles = (Set<String>) in.readObject(); Map<String, Permission> mPerms = new HashMap<String, Permission>(perms.size()); for (Permission xpm: perms) { mPerms.put(xpm.getResource(), xpm); } Role xRole = new Role( (int) entity[0], (Date) entity[1], (String) entity[2], mPerms, roles, name, description); return xRole; }