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