View Javadoc

1   /**
2    * This file Copyright (c) 2003-2011 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.module.admininterface.config;
35  
36  import info.magnolia.cms.beans.config.ContentRepository;
37  
38  import java.util.ArrayList;
39  import java.util.Collections;
40  import java.util.Iterator;
41  import java.util.LinkedHashMap;
42  import java.util.List;
43  import java.util.Map;
44  
45  import org.slf4j.Logger;
46  import org.slf4j.LoggerFactory;
47  
48  
49  /**
50   * @author philipp
51   * @version $Id: SecurityConfiguration.java 41137 2011-01-06 18:19:25Z gjoseph $
52   */
53  public class SecurityConfiguration {
54  
55      /**
56       * Logger.
57       */
58      private static Logger log = LoggerFactory.getLogger(SecurityConfiguration.class);
59  
60      private Map repositories = new LinkedHashMap();
61  
62      private RepositoryConfiguration defaultRepositoryConfiguration;
63  
64      private Map systemRepositories = new LinkedHashMap();
65  
66      public RepositoryConfiguration getDefaultRepositoryConfiguration() {
67          return this.defaultRepositoryConfiguration;
68      }
69  
70      public void setDefaultRepositoryConfiguration(RepositoryConfiguration defaultRepositoryConfiguration) {
71          this.defaultRepositoryConfiguration = defaultRepositoryConfiguration;
72      }
73  
74      public Map getRepositories() {
75          return this.repositories;
76      }
77  
78      public void setRepositories(Map repositories) {
79          this.repositories = repositories;
80      }
81  
82      public void addRepository(String name, RepositoryConfiguration repositoryConfiguration) {
83          this.repositories.put(name, repositoryConfiguration);
84      }
85  
86      public Map getSystemRepositories() {
87          return this.systemRepositories;
88      }
89  
90      public void setSystemRepositories(Map systemRepositories) {
91          this.systemRepositories = systemRepositories;
92      }
93  
94      public void addSystemRepository(String name, RepositoryConfiguration repository){
95          this.systemRepositories.put(name, repository);
96      }
97  
98      public List getVisibleRepositories(){
99          List visibleRepositories = new ArrayList();
100         // add all configured repositories
101         visibleRepositories.addAll(this.getRepositories().values());
102 
103         for (Iterator iter = ContentRepository.getAllRepositoryNames(); iter.hasNext();) {
104             String name = (String) iter.next();
105             if(!systemRepositories.containsKey(name)){
106                 if(!this.getRepositories().containsKey(name)){
107                     DefaultRepositoryConfigurationWrapper repositoryConfiguration = new DefaultRepositoryConfigurationWrapper(this.getDefaultRepositoryConfiguration());
108                     repositoryConfiguration.setName(name);
109                     visibleRepositories.add(repositoryConfiguration);
110                 }
111             }
112         }
113         Collections.sort(visibleRepositories);
114         return visibleRepositories;
115     }
116 
117     /**
118      * Delegate everything exept name and label.
119      * @author philipp
120      */
121     static class DefaultRepositoryConfigurationWrapper extends RepositoryConfiguration{
122         RepositoryConfiguration repositoryConfiguration;
123 
124         public DefaultRepositoryConfigurationWrapper(RepositoryConfiguration repositoryConfiguration) {
125             this.repositoryConfiguration = repositoryConfiguration;
126         }
127 
128         public void addAclType(AclTypeConfiguration type) {
129             this.repositoryConfiguration.addAclType(type);
130         }
131 
132         public void addPermission(PermissionConfiguration permission) {
133             this.repositoryConfiguration.addPermission(permission);
134         }
135 
136         public List getAclTypes() {
137             return this.repositoryConfiguration.getAclTypes();
138         }
139 
140         public List getPermissions() {
141             return this.repositoryConfiguration.getPermissions();
142         }
143 
144         public boolean isChooseButton() {
145             return this.repositoryConfiguration.isChooseButton();
146         }
147 
148         public void setAclTypes(List patternTypes) {
149             this.repositoryConfiguration.setAclTypes(patternTypes);
150         }
151 
152         public void setChooseButton(boolean chooseButton) {
153             this.repositoryConfiguration.setChooseButton(chooseButton);
154         }
155 
156         public void setPermissions(List permissions) {
157             this.repositoryConfiguration.setPermissions(permissions);
158         }
159 
160         public String toViewPattern(String path) {
161             return this.repositoryConfiguration.toViewPattern(path);
162         }
163     }
164 
165 }