View Javadoc

1   /**
2    * This file Copyright (c) 2003-2010 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.jaas.principal;
35  
36  import info.magnolia.cms.security.auth.ACL;
37  
38  import java.util.ArrayList;
39  import java.util.List;
40  
41  import org.apache.commons.lang.StringUtils;
42  import org.apache.commons.lang.builder.ToStringBuilder;
43  import org.apache.commons.lang.builder.ToStringStyle;
44  
45  
46  /**
47   * This class represents access control list as a principal
48   * @author Sameer Charles $Id: ACLImpl.java 32667 2010-03-13 00:37:06Z gjoseph $
49   */
50  public class ACLImpl implements ACL {
51  
52      /**
53       * Stable serialVersionUID.
54       */
55      private static final long serialVersionUID = 222L;
56  
57      private static final String NAME = "acl";
58  
59      /**
60       * properties
61       */
62      private String name;
63  
64      private List list;
65  
66      private String repository;
67  
68      private String workspace;
69  
70      /**
71       * Constructor
72       */
73      public ACLImpl() {
74          this.list = new ArrayList();
75      }
76  
77      /**
78       * Get name given to this principal
79       * @return name
80       */
81      public String getName() {
82          if (StringUtils.isEmpty(this.name)) {
83              return NAME;
84          }
85          return this.name;
86      }
87  
88      /**
89       * Set this principal name
90       */
91      public void setName(String name) {
92          this.name = name;
93      }
94  
95      /**
96       * Get repository ID for which this ACL has been constructed
97       * @return repository ID
98       */
99      public String getRepository() {
100         return this.repository;
101     }
102 
103     /**
104      * Set repository ID for which this ACL will be constructed
105      * @param repository
106      */
107     public void setRepository(String repository) {
108         this.repository = repository;
109     }
110 
111     /**
112      * Get workspace ID for which this ACL has been contructed
113      * @return workspace ID
114      */
115     public String getWorkspace() {
116         return this.workspace;
117     }
118 
119     /**
120      * Set workspace ID for which this ACL will be constructed
121      * @param workspace
122      */
123     public void setWorkspace(String workspace) {
124         this.workspace = workspace;
125     }
126 
127     /**
128      * add permission in to an existing list
129      * @param permission
130      */
131     public void addPermission(Object permission) {
132         this.list.add(permission);
133     }
134 
135     /**
136      * Initialize access control list with provided permissions it will overwrite any existing permissions set before.
137      * @param list
138      */
139     public void setList(List list) {
140         this.list.clear();
141         this.list.addAll(list);
142     }
143 
144     /**
145      * Returns list of permissions for this principal
146      */
147     public List getList() {
148         return this.list;
149     }
150 
151     /**
152      * @see java.lang.Object#toString()
153      */
154     public String toString() {
155         return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("name", this.name).append(
156             "workspace",
157             this.workspace).append("repository", this.repository).append("list", this.list).toString();
158     }
159 
160 }