Source Code Cross Referenced for SignInPanel.java in  » J2EE » wicket » org » apache » wicket » authentication » panel » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » wicket » org.apache.wicket.authentication.panel 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.wicket.authentication.panel;
018:
019:        import org.apache.wicket.PageParameters;
020:        import org.apache.wicket.authentication.AuthenticatedWebSession;
021:        import org.apache.wicket.markup.html.WebMarkupContainer;
022:        import org.apache.wicket.markup.html.form.CheckBox;
023:        import org.apache.wicket.markup.html.form.Form;
024:        import org.apache.wicket.markup.html.form.PasswordTextField;
025:        import org.apache.wicket.markup.html.form.TextField;
026:        import org.apache.wicket.markup.html.panel.FeedbackPanel;
027:        import org.apache.wicket.markup.html.panel.Panel;
028:        import org.apache.wicket.model.PropertyModel;
029:        import org.apache.wicket.util.value.ValueMap;
030:
031:        /**
032:         * Reusable user sign in panel with username and password as well as support for
033:         * cookie persistence of the both. When the SignInPanel's form is submitted, the
034:         * method signIn(String, String) is called, passing the username and password
035:         * submitted. The signIn() method should authenticate the user's session. The
036:         * default implementation calls AuthenticatedWebSession.get().signIn().
037:         * 
038:         * @author Jonathan Locke
039:         * @author Juergen Donnerstag
040:         * @author Eelco Hillenius
041:         */
042:        public class SignInPanel extends Panel {
043:            private static final long serialVersionUID = 1L;
044:
045:            /** True if the panel should display a remember-me checkbox */
046:            private boolean includeRememberMe = true;
047:
048:            /** Field for password. */
049:            private PasswordTextField password;
050:
051:            /** True if the user should be remembered via form persistence (cookies) */
052:            private boolean rememberMe = true;
053:
054:            /** Field for user name. */
055:            private TextField username;
056:
057:            /**
058:             * Sign in form.
059:             */
060:            public final class SignInForm extends Form {
061:                private static final long serialVersionUID = 1L;
062:
063:                /** El-cheapo model for form. */
064:                private final ValueMap properties = new ValueMap();
065:
066:                /**
067:                 * Constructor.
068:                 * 
069:                 * @param id
070:                 *            id of the form component
071:                 */
072:                public SignInForm(final String id) {
073:                    super (id);
074:
075:                    // Attach textfield components that edit properties map
076:                    // in lieu of a formal beans model
077:                    add(username = new TextField("username", new PropertyModel(
078:                            properties, "username")));
079:                    add(password = new PasswordTextField("password",
080:                            new PropertyModel(properties, "password")));
081:
082:                    // MarkupContainer row for remember me checkbox
083:                    final WebMarkupContainer rememberMeRow = new WebMarkupContainer(
084:                            "rememberMeRow");
085:                    add(rememberMeRow);
086:
087:                    // Add rememberMe checkbox
088:                    rememberMeRow.add(new CheckBox("rememberMe",
089:                            new PropertyModel(SignInPanel.this , "rememberMe")));
090:
091:                    // Make form values persistent
092:                    setPersistent(rememberMe);
093:
094:                    // Show remember me checkbox?
095:                    rememberMeRow.setVisible(includeRememberMe);
096:                }
097:
098:                /**
099:                 * @see org.apache.wicket.markup.html.form.Form#onSubmit()
100:                 */
101:                public final void onSubmit() {
102:                    if (signIn(getUsername(), getPassword())) {
103:                        onSignInSucceeded();
104:                    } else {
105:                        onSignInFailed();
106:                    }
107:                }
108:            }
109:
110:            /**
111:             * @see org.apache.wicket.Component#Component(String)
112:             */
113:            public SignInPanel(final String id) {
114:                this (id, true);
115:            }
116:
117:            /**
118:             * @param id
119:             *            See Component constructor
120:             * @param includeRememberMe
121:             *            True if form should include a remember-me checkbox
122:             * @see org.apache.wicket.Component#Component(String)
123:             */
124:            public SignInPanel(final String id, final boolean includeRememberMe) {
125:                super (id);
126:
127:                this .includeRememberMe = includeRememberMe;
128:
129:                // Create feedback panel and add to page
130:                final FeedbackPanel feedback = new FeedbackPanel("feedback");
131:                add(feedback);
132:
133:                // Add sign-in form to page, passing feedback panel as
134:                // validation error handler
135:                add(new SignInForm("signInForm"));
136:            }
137:
138:            /**
139:             * Removes persisted form data for the signin panel (forget me)
140:             */
141:            public final void forgetMe() {
142:                // Remove persisted user data. Search for child component
143:                // of type SignInForm and remove its related persistence values.
144:                getPage().removePersistedFormData(SignInPanel.SignInForm.class,
145:                        true);
146:            }
147:
148:            /**
149:             * Convenience method to access the password.
150:             * 
151:             * @return The password
152:             */
153:            public String getPassword() {
154:                return password.getInput();
155:            }
156:
157:            /**
158:             * Get model object of the rememberMe checkbox
159:             * 
160:             * @return True if user should be remembered in the future
161:             */
162:            public boolean getRememberMe() {
163:                return rememberMe;
164:            }
165:
166:            /**
167:             * Convenience method to access the username.
168:             * 
169:             * @return The user name
170:             */
171:            public String getUsername() {
172:                return username.getModelObjectAsString();
173:            }
174:
175:            /**
176:             * Convenience method set persistence for username and password.
177:             * 
178:             * @param enable
179:             *            Whether the fields should be persistent
180:             */
181:            public void setPersistent(final boolean enable) {
182:                username.setPersistent(enable);
183:                password.setPersistent(enable);
184:            }
185:
186:            /**
187:             * Set model object for rememberMe checkbox
188:             * 
189:             * @param rememberMe
190:             */
191:            public void setRememberMe(final boolean rememberMe) {
192:                this .rememberMe = rememberMe;
193:                this .setPersistent(rememberMe);
194:            }
195:
196:            /**
197:             * Sign in user if possible.
198:             * 
199:             * @param username
200:             *            The username
201:             * @param password
202:             *            The password
203:             * @return True if signin was successful
204:             */
205:            public boolean signIn(String username, String password) {
206:                return AuthenticatedWebSession.get().signIn(username, password);
207:            }
208:
209:            protected void onSignInFailed() {
210:                // Try the component based localizer first. If not found try the
211:                // application localizer. Else use the default
212:                error(getLocalizer().getString("signInFailed", this ,
213:                        "Sign in failed"));
214:            }
215:
216:            protected void onSignInSucceeded() {
217:                // If login has been called because the user was not yet
218:                // logged in, than continue to the original destination,
219:                // otherwise to the Home page
220:                if (!continueToOriginalDestination()) {
221:                    setResponsePage(getApplication().getSessionSettings()
222:                            .getPageFactory().newPage(
223:                                    getApplication().getHomePage(),
224:                                    (PageParameters) null));
225:                }
226:            }
227:
228:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.