KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > pageflow > UnfulfilledRolesException


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.pageflow;
19
20 import org.apache.beehive.netui.util.Bundle;
21
22 import javax.servlet.http.HttpServletResponse JavaDoc;
23 import java.io.IOException JavaDoc;
24
25
26 /**
27  * Exception that is thrown when <code>rolesAllowed</code> is set on the current action's annotation
28  * ({@link org.apache.beehive.netui.pageflow.annotations.Jpf.Action &#64;Jpf.Action} or
29  * {@link org.apache.beehive.netui.pageflow.annotations.Jpf.SimpleAction &#64;Jpf.SimpleAction}), and there is a logged-in
30  * user who does not fulfil any of the given roles.
31  */

32 public class UnfulfilledRolesException
33         extends PageFlowException
34         implements ResponseErrorCodeSender
35 {
36     private String JavaDoc[] _roleNames;
37     private String JavaDoc _rolesList;
38     
39
40     /**
41      * Construct on the list of roles that were allowed access to the action.
42      *
43      * @param roleNames an array of String role names.
44      */

45     public UnfulfilledRolesException( String JavaDoc[] roleNames, String JavaDoc rolesList, String JavaDoc actionName, FlowController fc )
46      {
47         super( actionName, fc );
48         _roleNames = roleNames;
49         _rolesList = rolesList;
50     }
51
52     /**
53      * Get the names of the roles that were allowed access to the action.
54      *
55      * @return an array of String role names.
56      */

57     public String JavaDoc[] getRoleNames()
58     {
59         return _roleNames;
60     }
61     
62
63     protected Object JavaDoc[] getMessageArgs()
64     {
65         return new Object JavaDoc[]{ getActionName(), getFlowControllerURI(), _rolesList };
66     }
67
68     public String JavaDoc[] getMessageParts()
69     {
70         return new String JavaDoc[]
71         {
72             "Action ", " on Page Flow ", " requires the user to be in one of the following roles: ", "."
73         };
74     }
75
76     public void sendResponseErrorCode( HttpServletResponse JavaDoc response ) throws IOException JavaDoc
77     {
78         String JavaDoc msg = Bundle.getString( "PageFlow_UnfulfilledRolesException_ResponseMessage", getActionName() );
79         response.sendError( HttpServletResponse.SC_BAD_REQUEST, msg );
80     }
81
82     /**
83      * Tell whether the root cause may be session expiration in cases where the requested session ID is different than
84      * the actual session ID. In this case, the answer is <code>true</code>.
85      */

86     public boolean causeMayBeSessionExpiration()
87     {
88         return true;
89     }
90 }
91
Popular Tags