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 * bstefanescu 011 */ 012package org.nuxeo.ecm.automation.client; 013 014import java.io.Serializable; 015import java.util.Collections; 016import java.util.Set; 017 018/** 019 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 020 */ 021@SuppressWarnings("serial") 022public class LoginInfo implements Serializable { 023 024 public static final LoginInfo ANONYNMOUS = new LoginInfo("Anonymous"); 025 026 protected String username; 027 028 protected Set<String> groups; 029 030 protected boolean isAdministrator; 031 032 public LoginInfo(String username) { 033 this(username, null); 034 } 035 036 public LoginInfo(String username, Set<String> groups) { 037 this(username, groups, false); 038 } 039 040 public LoginInfo(String username, Set<String> groups, boolean isAdministrator) { 041 this.username = username; 042 this.isAdministrator = isAdministrator; 043 if (groups == null) { 044 this.groups = Collections.emptySet(); 045 } else { 046 this.groups = groups; 047 } 048 } 049 050 public boolean isAdministrator() { 051 return isAdministrator; 052 } 053 054 public String getUsername() { 055 return username; 056 } 057 058 public String[] getGroups() { 059 return groups.toArray(new String[groups.size()]); 060 } 061 062 public boolean hasGroup(String group) { 063 return groups.contains(group); 064 } 065 066}