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