KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > security > sasl > AuthorizeCallback


1 /*
2  * @(#)AuthorizeCallback.java 1.10 04/02/03
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.security.sasl;
9
10 import javax.security.auth.callback.Callback JavaDoc;
11
12 /**
13   * This callback is used by <tt>SaslServer</tt> to determine whether
14   * one entity (identified by an authenticated authentication id)
15   * can act on
16   * behalf of another entity (identified by an authorization id).
17   *
18   * @since 1.5
19   *
20   * @author Rosanna Lee
21   * @author Rob Weltman
22   */

23 public class AuthorizeCallback implements Callback JavaDoc, java.io.Serializable JavaDoc {
24     /**
25      * The (authenticated) authentication id to check.
26      * @serial
27      */

28     private String JavaDoc authenticationID;
29
30     /**
31      * The authorization id to check.
32      * @serial
33      */

34     private String JavaDoc authorizationID;
35
36     /**
37      * The id of the authorized entity. If null, the id of
38      * the authorized entity is authorizationID.
39      * @serial
40      */

41     private String JavaDoc authorizedID;
42
43     /**
44      * A flag indicating whether the authentication id is allowed to
45      * act on behalf of the authorization id.
46      * @serial
47      */

48     private boolean authorized;
49
50     /**
51      * Constructs an instance of <tt>AuthorizeCallback</tt>.
52      *
53      * @param authnID The (authenticated) authentication id.
54      * @param authzID The authorization id.
55      */

56     public AuthorizeCallback(String JavaDoc authnID, String JavaDoc authzID) {
57     authenticationID = authnID;
58     authorizationID = authzID;
59     }
60
61     /**
62      * Returns the authentication id to check.
63      * @return The authentication id to check.
64      */

65     public String JavaDoc getAuthenticationID() {
66     return authenticationID;
67     }
68
69     /**
70      * Returns the authorization id to check.
71      * @return The authentication id to check.
72      */

73     public String JavaDoc getAuthorizationID() {
74     return authorizationID;
75     }
76
77     /**
78      * Determines whether the authentication id is allowed to
79      * act on behalf of the authorization id.
80      *
81      * @return <tt>true</tt> if authorization is allowed; <tt>false</tt> otherwise
82      * @see #setAuthorized(boolean)
83      * @see #getAuthorizedID()
84      */

85     public boolean isAuthorized() {
86     return authorized;
87     }
88
89     /**
90      * Sets whether the authorization is allowed.
91      * @param ok <tt>true</tt> if authorization is allowed; <tt>false</tt> otherwise
92      * @see #isAuthorized
93      * @see #setAuthorizedID(java.lang.String)
94      */

95     public void setAuthorized(boolean ok) {
96     authorized = ok;
97     }
98
99     /**
100      * Returns the id of the authorized user.
101      * @return The id of the authorized user. <tt>null</tt> means the
102      * authorization failed.
103      * @see #setAuthorized(boolean)
104      * @see #setAuthorizedID(java.lang.String)
105      */

106     public String JavaDoc getAuthorizedID() {
107     if (!authorized) {
108         return null;
109     }
110     return (authorizedID == null) ? authorizationID : authorizedID;
111     }
112
113     /**
114      * Sets the id of the authorized entity. Called by handler only when the id
115      * is different from getAuthorizationID(). For example, the id
116      * might need to be canonicalized for the environment in which it
117      * will be used.
118      * @param id The id of the authorized user.
119      * @see #setAuthorized(boolean)
120      * @see #getAuthorizedID
121      */

122     public void setAuthorizedID(String JavaDoc id) {
123     authorizedID = id;
124     }
125
126     private static final long serialVersionUID = -2353344186490470805L;
127 }
128
Popular Tags