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: package org.apache.wicket.authorization.strategies.page;
18:
19: import org.apache.wicket.Component;
20: import org.apache.wicket.Page;
21: import org.apache.wicket.authorization.Action;
22: import org.apache.wicket.authorization.IAuthorizationStrategy;
23:
24: /**
25: * An abstract base class for implementing simple authorization of Pages. Users
26: * should override {@link #isPageAuthorized(Class)}, which gets called for Page
27: * classes when they are being constructed.
28: *
29: * @author Jonathan Locke
30: * @author Eelco Hillenius
31: */
32: public abstract class AbstractPageAuthorizationStrategy implements
33: IAuthorizationStrategy {
34: /**
35: * @see org.apache.wicket.authorization.IAuthorizationStrategy#isActionAuthorized(org.apache.wicket.Component,
36: * org.apache.wicket.authorization.Action)
37: */
38: public boolean isActionAuthorized(final Component component,
39: final Action action) {
40: return true;
41: }
42:
43: /**
44: * @see org.apache.wicket.authorization.IAuthorizationStrategy#isInstantiationAuthorized(java.lang.Class)
45: */
46: public final boolean isInstantiationAuthorized(
47: final Class/* <Component> */componentClass) {
48: if (instanceOf(componentClass, Page.class)) {
49: return isPageAuthorized(componentClass);
50: }
51: return true;
52: }
53:
54: /**
55: * Works like instanceof operator where instanceOf(a, b) is the runtime
56: * equivalent of (a instanceof b).
57: *
58: * @param type
59: * The type to check
60: * @param superType
61: * The interface or superclass that the type needs to implement
62: * or extend
63: * @return True if the type is an instance of the superType
64: */
65: protected boolean instanceOf(final Class type, final Class super Type) {
66: return super Type.isAssignableFrom(type);
67: }
68:
69: /**
70: * Whether to page may be created. Returns true by default.
71: *
72: * @param pageClass
73: * The Page class
74: * @return True if to page may be created
75: */
76: protected boolean isPageAuthorized(Class/* <Page> */pageClass) {
77: return true;
78: }
79: }
|