KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > store > mem > TransientSecurityStore


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/stores/org/apache/slide/store/mem/TransientSecurityStore.java,v 1.3 2004/07/28 09:34:05 ib Exp $
3  * $Revision: 1.3 $
4  * $Date: 2004/07/28 09:34:05 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23 package org.apache.slide.store.mem;
24
25 import java.util.ArrayList JavaDoc;
26 import java.util.Enumeration JavaDoc;
27 import java.util.List JavaDoc;
28
29 import org.apache.slide.common.ServiceAccessException;
30 import org.apache.slide.common.Uri;
31 import org.apache.slide.security.NodePermission;
32 import org.apache.slide.store.SecurityStore;
33
34
35 /**
36  */

37 public class TransientSecurityStore extends AbstractTransientStore implements
38       SecurityStore
39 {
40    // ExtendendStore always caches, so we don't
41

42    public void grantPermission(Uri uri, NodePermission permission)
43          throws ServiceAccessException
44    {
45       debug("grantPermission {0} {1}", uri, permission);
46       List JavaDoc list = (List JavaDoc)get(uri.toString());
47       if (list != null) {
48          list = new ArrayList JavaDoc(list);
49       } else {
50          list = new ArrayList JavaDoc();
51       }
52       list.add(permission);
53       put(uri.toString(), list);
54    }
55
56    public void revokePermission(Uri uri, NodePermission permission)
57          throws ServiceAccessException
58    {
59       debug("revokePermission {0} {1}", uri, permission);
60       List JavaDoc list = (List JavaDoc)get(uri.toString());
61       if (list != null) {
62          list = new ArrayList JavaDoc(list);
63          if (list.remove(permission)) {
64             if (list.size() > 0) {
65                put(uri.toString(), list);
66             } else {
67                remove(uri.toString());
68             }
69          }
70       }
71    }
72
73    public void revokePermissions(Uri uri) throws ServiceAccessException
74    {
75       debug("revokePermissions {0}", uri);
76       List JavaDoc list = (List JavaDoc)get(uri.toString());
77       if (list != null) {
78          remove(uri.toString());
79       }
80    }
81
82    public Enumeration JavaDoc enumeratePermissions(Uri uri)
83          throws ServiceAccessException
84    {
85       debug("enumeratePermissions {0}", uri);
86       List JavaDoc list = (List JavaDoc)get(uri.toString());
87       if (list != null) {
88          return new IteratorEnum(list.iterator());
89       } else {
90          return EMPTY_ENUM;
91       }
92    }
93 }
94
Popular Tags