01: /*
02: * $Id: SignInApplication.java 459167 2006-02-11 07:31:53Z ehillenius $ $Revision:
03: * 1.9 $ $Date: 2006-02-11 08:31:53 +0100 (Sat, 11 Feb 2006) $
04: *
05: * ==================================================================== Licensed
06: * under the Apache License, Version 2.0 (the "License"); you may not use this
07: * file except in compliance with the License. You may obtain a copy of the
08: * License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15: * License for the specific language governing permissions and limitations under
16: * the License.
17: */
18: package wicket.examples.signin;
19:
20: import wicket.Component;
21: import wicket.ISessionFactory;
22: import wicket.RestartResponseAtInterceptPageException;
23: import wicket.Session;
24: import wicket.authorization.Action;
25: import wicket.authorization.IAuthorizationStrategy;
26: import wicket.examples.WicketExampleApplication;
27:
28: /**
29: * Forms example.
30: *
31: * @author Jonathan Locke
32: */
33: public final class SignInApplication extends WicketExampleApplication {
34: /**
35: * Constructor.
36: */
37: public SignInApplication() {
38: }
39:
40: /**
41: * @see wicket.examples.WicketExampleApplication#init()
42: */
43: protected void init() {
44: getSecuritySettings().setAuthorizationStrategy(
45: new IAuthorizationStrategy() {
46: public boolean isActionAuthorized(
47: Component component, Action action) {
48: return true;
49: }
50:
51: public boolean isInstantiationAuthorized(
52: Class componentClass) {
53: if (AuthenticatedWebPage.class
54: .isAssignableFrom(componentClass)) {
55: // Is user signed in?
56: if (((SignInSession) Session.get())
57: .isSignedIn()) {
58: // okay to proceed
59: return true;
60: }
61:
62: // Force sign in
63: throw new RestartResponseAtInterceptPageException(
64: SignIn.class);
65: }
66: return true;
67: }
68: });
69: }
70:
71: /**
72: * @see wicket.protocol.http.WebApplication#getSessionFactory()
73: */
74: public ISessionFactory getSessionFactory() {
75: return new ISessionFactory() {
76: public Session newSession() {
77: return new SignInSession(SignInApplication.this );
78: }
79: };
80: }
81:
82: /**
83: * @see wicket.Application#getHomePage()
84: */
85: public Class getHomePage() {
86: return Home.class;
87: }
88:
89: }
|