KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > security > auth > message > MessagePolicy


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package javax.security.auth.message;
23
24 /**
25  * @author <a HREF="mailto:Anil.Saldhana@jboss.org">Anil Saldhana@jboss.org</a>
26  * @author Charlie Lai, Ron Monzillo (Javadoc for JSR-196)</a>
27  * @since May 11, 2006
28  * @version $Revision: 45179 $
29  */

30 public class MessagePolicy
31 {
32    protected TargetPolicy[] targetPolicies = null;
33    
34    /**
35     * Create a MessagePolicy instance with an array of target policies.
36     *
37     * @param targetPolicies an array of target policies.
38     * @throws IllegalArgumentException if the specified targetPolicies is null.
39     */

40    public MessagePolicy(TargetPolicy[] targetPolicies)
41    {
42       if( targetPolicies == null)
43          throw new IllegalArgumentException JavaDoc("specified targetPolicies is null");
44       
45       this.targetPolicies = targetPolicies;
46    }
47    
48    /**
49     * Get the target policies that comprise the authentication policy.
50     *
51     * @return an array of target authentication policies, where each element describes an
52     * authentication policy and the parts of the message to which the authentication
53     * policy applies. This method returns null to indicate that no security operations
54     * should be performed on the messages to which the policy applies. <b>This method
55     * never returns a zero-length array</b>. When this method returns an array of target
56     * policies, the order of elements in the array represents the order that the
57     * corresponding message transformations or validations described by the target
58     * policies are to be performed by the authentication module.
59     */

60    public TargetPolicy[]getTargetPolicies()
61    {
62       if(targetPolicies != null && targetPolicies.length == 0 )
63          throw new IllegalStateException JavaDoc("Target Policies should not be of zero length");
64       return this.targetPolicies;
65    }
66    
67    /**
68     * This interface is implemented by objects that represent and perform message targeting
69     * on behalf of authentication modules.</p>
70     * <p>The internal state of a Target indicates whether it applies to the request or
71     * response message of an AuthParam and to which components it applies within the
72     * identified message.</p>
73     */

74    public static interface Target
75    {
76       /**
77        * Get the Object identified by the Target from the AuthParam.
78        *
79        * @param authParam the AuthParam containing the request or response message from which
80        * the target is to be obtained.
81        * @return an Object representing the target, or null when the target could not be found
82        * in the AuthParam.
83        */

84       public Object JavaDoc get(AuthParam authParam);
85       
86       /**
87        * Put the Object into the AuthParam at the location identified by the target.
88        * @param authParam the AuthParam containing the request or response message
89        * into which the object is to be put.
90        * @param data
91        */

92       public void put(AuthParam authParam, Object JavaDoc data);
93       
94       /**
95        * Remove the Object identified by the Target from the AuthParam.
96        *
97        * @param authParam the AuthParam containing the request or response message from
98        * which the target is to be removed.
99        */

100       public void remove(AuthParam authParam);
101    }
102     
103    public static class TargetPolicy
104    {
105       
106       protected ProtectionPolicy protectionPolicy;
107       protected Target[] targets;
108       
109       /**
110        *
111        * Create a new TargetPolicy.
112        *
113        * @param targets
114        * @param protectionPolicy
115        */

116       public TargetPolicy(Target[] targets, ProtectionPolicy protectionPolicy)
117       {
118          this.targets = targets;
119          this.protectionPolicy = protectionPolicy;
120       }
121       
122       /**
123        * Get the URI that identifies the policy that applies to the targets.
124        *
125        * @return a URI that identifies a source or recipient authentication policy.
126        */

127       public ProtectionPolicy getProtectionPolicy()
128       {
129          return this.protectionPolicy;
130       }
131       
132       /**
133        * Get the array of layer-specific target descriptors that identify the one or
134        * more message parts to which the specified message protection policy applies.
135        * @return an array of MessageTarget that identify targets within a message.
136        * This method returns null when the specified policy applies to the whole message
137        * (excluding any meta data added to the message to satisfy the policy).
138        * <b>This method never returns a zero-length array.</b>
139        */

140       public Target[] getTargets()
141       {
142          if(targets != null && targets.length == 0 )
143             throw new IllegalStateException JavaDoc(" Targets cannot be of length zero");
144          return this.targets;
145       }
146    }
147    
148    /**
149     * <p>This interface is used to represent message authentication policy.</p>
150     * <p>The internal state of a ProtectionPolicy object defines the message
151     * authentication requirements to be applied to the associated Target.</p>
152     */

153    public static interface ProtectionPolicy
154    {
155       /**
156        * A URI fragment that represents a recipient entity authentication policy AUTHENTICATE_RECIPIENT_CONTENT
157        */

158       public static final String JavaDoc AUTHENTICATE_RECIPIENT = "http://jboss.org/security/auth/container/auth_recipient";
159       
160       /**
161        * A URI fragment that represents a source entity authentication policy AUTHENTICATE_SOURCE_CONTENT
162        */

163       public static final String JavaDoc AUTHENTICATE_SOURCE = "http://jboss.org/security/auth/container/auth_source";
164       
165       /**
166        * A URI fragment that represents a data origin authentication policy
167        */

168       public static final String JavaDoc AUTHENTICATE_SOURCE_CONTENT = "http://jboss.org/security/auth/container/auth_source_content";
169        
170       public String JavaDoc getID();
171    }
172    
173 }
174
Popular Tags