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