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.Request;
20: import org.apache.wicket.protocol.http.WebApplication;
21: import org.apache.wicket.protocol.http.WebSession;
22:
23: /**
24: * Session class for signin example. Holds and authenticates users.
25: *
26: * @author Jonathan Locke
27: */
28: public final class SignInSession extends WebSession {
29: /** Trivial user representation */
30: private String user;
31:
32: /**
33: * Constructor
34: *
35: * @param application
36: * The application
37: * @param request
38: */
39: protected SignInSession(final WebApplication application,
40: Request request) {
41: super (application, request);
42: }
43:
44: /**
45: * Checks the given username and password, returning a User object if if the
46: * username and password identify a valid user.
47: *
48: * @param username
49: * The username
50: * @param password
51: * The password
52: * @return True if the user was authenticated
53: */
54: public final boolean authenticate(final String username,
55: final String password) {
56: if (user == null) {
57: // Trivial password "db"
58: if ("wicket".equalsIgnoreCase(username)
59: && "wicket".equalsIgnoreCase(password)) {
60: user = username;
61: }
62: }
63:
64: return user != null;
65: }
66:
67: /**
68: * @return True if user is signed in
69: */
70: public boolean isSignedIn() {
71: return user != null;
72: }
73:
74: /**
75: * @return User
76: */
77: public String getUser() {
78: return user;
79: }
80:
81: /**
82: * @param user
83: * New user
84: */
85: public void setUser(final String user) {
86: this.user = user;
87: }
88: }
|