001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 *
019 * $Id$
020 */
021
022package org.nuxeo.ecm.core.api.security;
023
024import java.io.Serializable;
025
026public class UserVisiblePermission implements Serializable {
027
028    private static final long serialVersionUID = 1L;
029
030    protected final String permission;
031
032    protected final String denyPermission;
033
034    protected final String id;
035
036    public UserVisiblePermission(String id, String perm, String denyPerm) {
037        permission = perm;
038        denyPermission = denyPerm;
039        this.id = id;
040    }
041
042    @Override
043    public boolean equals(Object o) {
044        if (this == o) {
045            return true;
046        }
047        if (o == null || getClass() != o.getClass()) {
048            return false;
049        }
050
051        UserVisiblePermission other = (UserVisiblePermission) o;
052
053        if (denyPermission != null ? !denyPermission.equals(other.denyPermission) : other.denyPermission != null) {
054            return false;
055        }
056        if (id != null ? !id.equals(other.id) : other.id != null) {
057            return false;
058        }
059        if (permission != null ? !permission.equals(other.permission) : other.permission != null) {
060            return false;
061        }
062        return true;
063    }
064
065    @Override
066    public int hashCode() {
067        int result = permission != null ? permission.hashCode() : 0;
068        result = 31 * result + (denyPermission != null ? denyPermission.hashCode() : 0);
069        result = 31 * result + (id != null ? id.hashCode() : 0);
070        return result;
071    }
072
073    @Override
074    public String toString() {
075        if (denyPermission != null) {
076            return String.format("UserVisiblePermission %s [%s (deny %s)]", id, permission, denyPermission);
077        } else {
078            return String.format("UserVisiblePermission %s [%s]", id, permission);
079        }
080    }
081
082    public String getPermission() {
083        return permission;
084    }
085
086    public String getDenyPermission() {
087        return denyPermission;
088    }
089
090    public String getId() {
091        return id;
092    }
093
094}