View Javadoc
1   /**
2    * This file Copyright (c) 2003-2018 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.cms.security;
35  
36  import java.util.ArrayList;
37  import java.util.Collection;
38  import java.util.Collections;
39  
40  import org.apache.commons.lang3.StringUtils;
41  import org.slf4j.Logger;
42  import org.slf4j.LoggerFactory;
43  
44  
45  /**
46   * Dummy user implementation returned when an actual user instance can't be instantiated.
47   *
48   * @deprecated since 4.3.6 - usage needs to be reviewed - see MAGNOLIA-3269
49   */
50  @Deprecated
51  public class DummyUser extends AbstractUser {
52  
53      private static final Logger log = LoggerFactory.getLogger(DummyUser.class);
54  
55      private static final String DEFAULT_LANGUAGE = "en";
56  
57      public DummyUser() {
58          log.info("Initializing dummy user - Anonymous");
59          log.info("This area and/or instance is not secured");
60      }
61  
62      /**
63       * Dummy user has full access, always returns true.
64       */
65      @Override
66      public boolean hasRole(String roleName) {
67          return true;
68      }
69  
70      /**
71       * Simply log that its a dummy user.
72       */
73      @Override
74      public void removeRole(String roleName) throws UnsupportedOperationException {
75          log.debug("User [ Anonymous ] has no roles");
76      }
77  
78      /**
79       * Simply log that its a dummy user.
80       *
81       * @param roleName the name of the role
82       */
83      @Override
84      public void addRole(String roleName) throws UnsupportedOperationException {
85          log.debug("No roles can be attached to user [ Anonymous ]");
86      }
87  
88      /**
89       * Always returns true.
90       */
91      @Override
92      public boolean inGroup(String groupName) {
93          return true;
94      }
95  
96      @Override
97      public void removeGroup(String groupName) throws UnsupportedOperationException {
98          log.debug("User [ Anonymous ] has no groups");
99      }
100 
101     @Override
102     public void addGroup(String groupName) throws UnsupportedOperationException {
103         log.debug("No groups can be attached to user [ Anonymous ]");
104     }
105 
106     @Override
107     public boolean isEnabled() {
108         return true;
109     }
110 
111     @Override
112     public void setEnabled(boolean enabled) {
113     }
114 
115     @Override
116     public String getLanguage() {
117         return DEFAULT_LANGUAGE;
118     }
119 
120     @Override
121     public String getName() {
122         return UserManager.ANONYMOUS_USER;
123     }
124 
125     @Override
126     public String getPassword() {
127         return StringUtils.EMPTY;
128     }
129 
130     @Override
131     public String getProperty(String propertyName) {
132         return null;
133     }
134 
135     @Override
136     public void setProperty(String propertyName, String value) {
137         log.debug("Can not set properties on dummy user (name: {}, value: {})", propertyName, value);
138     }
139 
140     @Override
141     public String getIdentifier() {
142         throw new UnsupportedOperationException();
143     }
144 
145     @Override
146     public Collection<String> getGroups() {
147         return Collections.emptyList();
148     }
149 
150     @Override
151     public Collection<String> getAllGroups() {
152         return new ArrayList<String>();
153     }
154 
155     @Override
156     public Collection<String> getRoles() {
157         return Collections.emptyList();
158     }
159 
160     @Override
161     public Collection<String> getAllRoles() {
162         return new ArrayList<String>();
163     }
164 }