KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > samples > AuthResult


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 package org.ejbca.samples;
15
16 import java.util.Hashtable JavaDoc;
17
18
19 /**
20  * Class containing the complete result from an authenticateUser request.
21  *
22  * @author Original code by Peter Neemeth
23  * @version $Id: AuthResult.java,v 1.1 2006/01/17 20:31:52 anatom Exp $
24  */

25 public class AuthResult {
26     /** Constants for grant and reject */
27     private static final boolean GRANT_STATUS = true;
28     private static final boolean REJECT_STATUS = false;
29
30     /** Default to rejecting a request */
31     private boolean status = REJECT_STATUS; //GRANT_STATUS or REJECT_STATUS
32

33     /** What was the reason to reject this request? */
34     private String JavaDoc reason = ""; //No reason
35

36     /** This Hashtable keeps all the name-value pairs in the result. */
37     private Hashtable JavaDoc resultHash = new Hashtable JavaDoc();
38
39     /**
40      * Adds a new key, value pair to the grant response.
41      *
42      * @param key left hand value. Must be unique for this result
43      * @param value right hand value
44      */

45     public void add(final String JavaDoc key, final String JavaDoc value) {
46         resultHash.put(key, value);
47     }
48
49     /**
50      * DOCUMENT ME!
51      *
52      * @return reason for rejecting this request
53      */

54     public String JavaDoc getReason() {
55         return reason;
56     }
57
58     /**
59      * Get result as Hashtable.
60      *
61      * @return hash table of results
62      */

63     public Hashtable JavaDoc getResult() {
64         return resultHash;
65     }
66
67     /**
68      * Set status to GRANT
69      */

70     public void grant() {
71         status = GRANT_STATUS;
72     }
73
74     /**
75      * DOCUMENT ME!
76      *
77      * @return true if the request was GRANTed
78      */

79     public boolean granted() {
80         return status == GRANT_STATUS;
81     }
82
83     /**
84      * Set status to REJECT
85      */

86     public void reject() {
87         status = REJECT_STATUS;
88     }
89
90     /**
91      * DOCUMENT ME!
92      *
93      * @return true if the request was REJECTed
94      */

95     public boolean rejected() {
96         return status == REJECT_STATUS;
97     }
98
99     /**
100      * Set reason of rejected request. No default.
101      *
102      * @param newReason describing why the request was rejected
103      */

104     public void setReason(final String JavaDoc newReason) {
105         reason = newReason;
106     }
107 }
108
Popular Tags