KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > authorization > AccessRule


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 /*
15  * AccessRule.java
16  *
17  * Created on den 16 mars 2002, 13:25
18  */

19
20 package org.ejbca.core.model.authorization;
21
22 import java.io.Serializable JavaDoc;
23
24
25 /**
26  * A class representing an accessrule.
27  * A class representing an accessrule in the Ejbca package. Sets rules to resources and tell if it
28  * also should apply for subresources.
29  *
30  * @author Philip Vendil
31  * @version $Id: AccessRule.java,v 1.1 2006/01/17 20:30:56 anatom Exp $
32  */

33 public class AccessRule implements Serializable JavaDoc, Comparable JavaDoc {
34     // Public rule constants.
35
public static final int RULE_ACCEPT = 1;
36     public static final int RULE_DECLINE = 2;
37     
38     /** Creates a new instance of AccessRule */
39     public AccessRule(String JavaDoc accessrule, int rule, boolean recursive ) {
40         this.accessrule=accessrule.trim();
41         this.rule=rule;
42         this.recursive=recursive;
43         
44         setState();
45     }
46     
47     public int getRule() {
48       return rule;
49     }
50     
51     public boolean isRecursive() {
52       return recursive;
53     }
54     
55     public String JavaDoc getAccessRule() {
56       return accessrule;
57     }
58     
59     public void setRule(int rule) {
60       this.rule=rule;
61       setState();
62     }
63     
64     public void setRecursive(boolean recursive) {
65       this.recursive=recursive;
66       setState();
67     }
68     
69     public void setAccessRule(String JavaDoc accessrule) {
70         this.accessrule=accessrule.trim();
71     }
72     
73     /** Method used by the access tree to speed things up. */
74     public int getRuleState(){
75       return state;
76     }
77     
78     public int compareTo(Object JavaDoc obj) {
79       return accessrule.compareTo(((AccessRule)obj).getAccessRule());
80     }
81     
82     // Private methods.
83
private void setState(){
84        if(recursive){
85          switch(rule){
86              case RULE_ACCEPT:
87                  state = AccessTreeNode.STATE_ACCEPT_RECURSIVE;
88                  break;
89              case RULE_DECLINE:
90                  state = AccessTreeNode.STATE_DECLINE_RECURSIVE;
91                  break;
92              default:
93          }
94        }
95        else{
96          switch(rule){
97              case RULE_ACCEPT:
98                  state = AccessTreeNode.STATE_ACCEPT;
99                  break;
100              case RULE_DECLINE:
101                  state = AccessTreeNode.STATE_DECLINE;
102                  break;
103              default:
104          }
105        }
106     }
107       
108     // Private fields.
109
private boolean recursive;
110     private int rule;
111     private String JavaDoc accessrule;
112     private int state; // A more efficent way of reprecenting rule and recusive.
113
}
114
Popular Tags