KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > server > auth > acl > ProtocolAccessControl


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.server.auth.acl;
18
19 import java.util.StringTokenizer JavaDoc;
20
21 import org.alfresco.filesys.server.SrvSession;
22 import org.alfresco.filesys.server.core.SharedDevice;
23
24 /**
25  * Protocol Access Control Class
26  * <p>
27  * Allow/disallow access to a share based on the protocol type.
28  */

29 public class ProtocolAccessControl extends AccessControl
30 {
31
32     // Available protocol type names
33

34     private static final String JavaDoc[] _protoTypes = { "SMB", "CIFS", "NFS", "FTP" };
35
36     // Parsed list of protocol types
37

38     private String JavaDoc[] m_checkList;
39
40     /**
41      * Class constructor
42      *
43      * @param protList String
44      * @param type String
45      * @param access int
46      */

47     protected ProtocolAccessControl(String JavaDoc protList, String JavaDoc type, int access)
48     {
49         super(protList, type, access);
50
51         // Parse the protocol list
52

53         m_checkList = listFromString(protList);
54     }
55
56     /**
57      * Check if the protocol matches the access control protocol list and return the allowed access.
58      *
59      * @param sess SrvSession
60      * @param share SharedDevice
61      * @param mgr AccessControlManager
62      * @return int
63      */

64     public int allowsAccess(SrvSession sess, SharedDevice share, AccessControlManager mgr)
65     {
66
67         // Determine the session protocol type
68

69         String JavaDoc sessProto = null;
70         String JavaDoc sessName = sess.getClass().getName();
71
72         if (sessName.endsWith(".SMBSrvSession"))
73             sessProto = "CIFS";
74         else if (sessName.endsWith(".FTPSrvSession"))
75             sessProto = "FTP";
76         else if (sessName.endsWith(".NFSSrvSession"))
77             sessProto = "NFS";
78
79         // Check if the session protocol type is in the protocols to be checked
80

81         if (sessProto != null && indexFromList(sessProto, m_checkList, false) != -1)
82             return getAccess();
83         return Default;
84     }
85
86     /**
87      * Validate the protocol list
88      *
89      * @param protList String
90      * @return boolean
91      */

92     public static final boolean validateProtocolList(String JavaDoc protList)
93     {
94
95         // Check if the protocol list string is valid
96

97         if (protList == null || protList.length() == 0)
98             return false;
99
100         // Split the protocol list and validate each protocol name
101

102         StringTokenizer JavaDoc tokens = new StringTokenizer JavaDoc(protList, ",");
103
104         while (tokens.hasMoreTokens())
105         {
106
107             // Get the current protocol name and validate
108

109             String JavaDoc name = tokens.nextToken().toUpperCase();
110             if (indexFromList(name, _protoTypes, false) == -1)
111                 return false;
112         }
113
114         // Protocol list is valid
115

116         return true;
117     }
118 }
119
Popular Tags