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.examples.signin;
18:
19: import org.apache.wicket.Component;
20: import org.apache.wicket.Request;
21: import org.apache.wicket.Response;
22: import org.apache.wicket.RestartResponseAtInterceptPageException;
23: import org.apache.wicket.Session;
24: import org.apache.wicket.authorization.Action;
25: import org.apache.wicket.authorization.IAuthorizationStrategy;
26: import org.apache.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 org.apache.wicket.Application#getHomePage()
42: */
43: public Class getHomePage() {
44: return Home.class;
45: }
46:
47: /**
48: * @see org.apache.wicket.protocol.http.WebApplication#newSession(Request,
49: * Response)
50: */
51: public Session newSession(Request request, Response response) {
52: return new SignInSession(SignInApplication.this , request);
53: }
54:
55: /**
56: * @see org.apache.wicket.examples.WicketExampleApplication#init()
57: */
58: protected void init() {
59: getSecuritySettings().setAuthorizationStrategy(
60: new IAuthorizationStrategy() {
61: public boolean isActionAuthorized(
62: Component component, Action action) {
63: return true;
64: }
65:
66: public boolean isInstantiationAuthorized(
67: Class componentClass) {
68: if (AuthenticatedWebPage.class
69: .isAssignableFrom(componentClass)) {
70: // Is user signed in?
71: if (((SignInSession) Session.get())
72: .isSignedIn()) {
73: // okay to proceed
74: return true;
75: }
76:
77: // Force sign in
78: throw new RestartResponseAtInterceptPageException(
79: SignIn.class);
80: }
81: return true;
82: }
83: });
84: }
85:
86: }
|