01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.netui.pageflow;
20:
21: import org.apache.beehive.netui.util.Bundle;
22:
23: import javax.servlet.http.HttpServletResponse;
24: import java.io.IOException;
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 @Jpf.Action} or
29: * {@link org.apache.beehive.netui.pageflow.annotations.Jpf.SimpleAction @Jpf.SimpleAction}), and there is a logged-in
30: * user who does not fulfil any of the given roles.
31: */
32: public class UnfulfilledRolesException extends PageFlowException
33: implements ResponseErrorCodeSender {
34: private String[] _roleNames;
35: private String _rolesList;
36:
37: /**
38: * Construct on the list of roles that were allowed access to the action.
39: *
40: * @param roleNames an array of String role names.
41: */
42: public UnfulfilledRolesException(String[] roleNames,
43: String rolesList, String actionName, FlowController fc) {
44: super (actionName, fc);
45: _roleNames = roleNames;
46: _rolesList = rolesList;
47: }
48:
49: /**
50: * Get the names of the roles that were allowed access to the action.
51: *
52: * @return an array of String role names.
53: */
54: public String[] getRoleNames() {
55: return _roleNames;
56: }
57:
58: protected Object[] getMessageArgs() {
59: return new Object[] { getActionName(), getFlowControllerURI(),
60: _rolesList };
61: }
62:
63: public String[] getMessageParts() {
64: return new String[] {
65: "Action ",
66: " on Page Flow ",
67: " requires the user to be in one of the following roles: ",
68: "." };
69: }
70:
71: public void sendResponseErrorCode(HttpServletResponse response)
72: throws IOException {
73: String msg = Bundle.getString(
74: "PageFlow_UnfulfilledRolesException_ResponseMessage",
75: getActionName());
76: response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
77: }
78:
79: /**
80: * Tell whether the root cause may be session expiration in cases where the requested session ID is different than
81: * the actual session ID. In this case, the answer is <code>true</code>.
82: */
83: public boolean causeMayBeSessionExpiration() {
84: return true;
85: }
86: }
|