001/*
002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Nuxeo - initial API and implementation
011 *
012 * $Id$
013 */
014
015package org.nuxeo.ecm.core.api.security;
016
017import java.io.Serializable;
018
019public class UserVisiblePermission implements Serializable {
020
021    private static final long serialVersionUID = 1L;
022
023    protected final String permission;
024
025    protected final String denyPermission;
026
027    protected final String id;
028
029    public UserVisiblePermission(String id, String perm, String denyPerm) {
030        permission = perm;
031        denyPermission = denyPerm;
032        this.id = id;
033    }
034
035    @Override
036    public boolean equals(Object o) {
037        if (this == o) {
038            return true;
039        }
040        if (o == null || getClass() != o.getClass()) {
041            return false;
042        }
043
044        UserVisiblePermission other = (UserVisiblePermission) o;
045
046        if (denyPermission != null ? !denyPermission.equals(other.denyPermission) : other.denyPermission != null) {
047            return false;
048        }
049        if (id != null ? !id.equals(other.id) : other.id != null) {
050            return false;
051        }
052        if (permission != null ? !permission.equals(other.permission) : other.permission != null) {
053            return false;
054        }
055        return true;
056    }
057
058    @Override
059    public int hashCode() {
060        int result = permission != null ? permission.hashCode() : 0;
061        result = 31 * result + (denyPermission != null ? denyPermission.hashCode() : 0);
062        result = 31 * result + (id != null ? id.hashCode() : 0);
063        return result;
064    }
065
066    @Override
067    public String toString() {
068        if (denyPermission != null) {
069            return String.format("UserVisiblePermission %s [%s (deny %s)]", id, permission, denyPermission);
070        } else {
071            return String.format("UserVisiblePermission %s [%s]", id, permission);
072        }
073    }
074
075    public String getPermission() {
076        return permission;
077    }
078
079    public String getDenyPermission() {
080        return denyPermission;
081    }
082
083    public String getId() {
084        return id;
085    }
086
087}