001/*
002 * (C) Copyright 2006-2014 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 *     Bogdan Stefanescu
018 *     Florent Guillaume
019 */
020package org.nuxeo.ecm.core.api.security.impl;
021
022import java.util.HashSet;
023import java.util.Set;
024
025import org.nuxeo.ecm.core.api.security.UserEntry;
026
027public class UserEntryImpl implements UserEntry {
028
029    private static final long serialVersionUID = 1L;
030
031    private final String username;
032
033    private final Set<String> granted;
034
035    private final Set<String> denied;
036
037    public UserEntryImpl(String username) {
038        this.username = username;
039        granted = new HashSet<String>();
040        denied = new HashSet<String>();
041    }
042
043    @Override
044    public void addPrivilege(String permission) {
045        granted.add(permission);
046        denied.remove(permission);
047    }
048
049    @Override
050    public void addPrivilege(String permission, boolean isGranted) {
051        if (isGranted) {
052            addPrivilege(permission);
053        } else {
054            granted.remove(permission);
055            denied.add(permission);
056        }
057    }
058
059    @Override
060    @Deprecated
061    public void addPrivilege(String permission, boolean granted, boolean readOnly) {
062        addPrivilege(permission, granted);
063    }
064
065    @Override
066    public String getUserName() {
067        return username;
068    }
069
070    @Override
071    public Set<String> getGrantedPermissions() {
072        return granted;
073    }
074
075    @Override
076    public Set<String> getDeniedPermissions() {
077        return denied;
078    }
079
080}