From 760bc7cd33c7028be367019e42757f5a28c150ed Mon Sep 17 00:00:00 2001 From: seb Date: Wed, 1 Dec 2010 19:11:47 +0000 Subject: [PATCH] org.wicketstuff.shiro.component.LoginPanel$SignInForm now extends StatelessForm instead of Form git-svn-id: file:///home/igor/dev/stuff/svnbackup/branches/wicketstuff-core-1.4@5663 ef7698a4-5110-0410-9fc6-c7eb3693863f --- .../shiro/component/LoginPanel.java | 138 +++++++++--------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/jdk-1.5-parent/shiro-security/wicket-shiro/src/main/java/org/wicketstuff/shiro/component/LoginPanel.java b/jdk-1.5-parent/shiro-security/wicket-shiro/src/main/java/org/wicketstuff/shiro/component/LoginPanel.java index e99d68e674..c1934d33db 100644 --- a/jdk-1.5-parent/shiro-security/wicket-shiro/src/main/java/org/wicketstuff/shiro/component/LoginPanel.java +++ b/jdk-1.5-parent/shiro-security/wicket-shiro/src/main/java/org/wicketstuff/shiro/component/LoginPanel.java @@ -24,8 +24,8 @@ import org.apache.shiro.subject.Subject; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.form.CheckBox; -import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.PasswordTextField; +import org.apache.wicket.markup.html.form.StatelessForm; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.markup.html.panel.FeedbackPanel; import org.apache.wicket.markup.html.panel.Panel; @@ -45,24 +45,10 @@ */ public class LoginPanel extends Panel { - private static final long serialVersionUID = 1L; - - /** True if the panel should display a remember-me checkbox */ - private boolean includeRememberMe = true; - - /** Field for password. */ - private PasswordTextField password; - - /** True if the user should be remembered via form persistence (cookies) */ - private boolean rememberMe = true; - - /** Field for user name. */ - private TextField username; - /** * Sign in form. */ - public final class SignInForm extends Form + public final class SignInForm extends StatelessForm { private static final long serialVersionUID = 1L; @@ -81,8 +67,10 @@ public SignInForm(final String id) // Attach textfield components that edit properties map // in lieu of a formal beans model - add(username = new TextField("username", new PropertyModel(properties, "username"))); - add(password = new PasswordTextField("password", new PropertyModel(properties, "password"))); + add(username = new TextField("username", new PropertyModel(properties, + "username"))); + add(password = new PasswordTextField("password", new PropertyModel(properties, + "password"))); // MarkupContainer row for remember me checkbox final WebMarkupContainer rememberMeRow = new WebMarkupContainer("rememberMeRow"); @@ -102,13 +90,25 @@ public SignInForm(final String id) @Override public final void onSubmit() { - if (login(getUsername(), getPassword(), getRememberMe() )) - { + if (login(getUsername(), getPassword(), getRememberMe())) onSignInSucceeded(); - } } } + private static final long serialVersionUID = 1L; + + /** True if the panel should display a remember-me checkbox */ + private boolean includeRememberMe = true; + + /** Field for password. */ + private PasswordTextField password; + + /** True if the user should be remembered via form persistence (cookies) */ + private boolean rememberMe = true; + + /** Field for user name. */ + private TextField username; + /** * @see org.apache.wicket.Component#Component(String) */ @@ -129,12 +129,11 @@ public LoginPanel(final String id, final boolean includeRememberMe) super(id); this.includeRememberMe = includeRememberMe; - if( !includeRememberMe ) { - this.rememberMe = false; - } + if (!includeRememberMe) + rememberMe = false; // Create feedback panel and add to page - add( new FeedbackPanel("feedback") ); + add(new FeedbackPanel("feedback")); // Add sign-in form to page, passing feedback panel as // validation error handler @@ -171,16 +170,6 @@ public String getUsername() return username.getDefaultModelObjectAsString(); } - /** - * Set model object for rememberMe checkbox - * - * @param rememberMe - */ - public void setRememberMe(final boolean rememberMe) - { - this.rememberMe = rememberMe; - } - /** * Sign in user if possible. * @@ -190,36 +179,37 @@ public void setRememberMe(final boolean rememberMe) * The password * @return True if signin was successful */ - public boolean login(String username, String password, boolean rememberMe) - { - Subject currentUser = SecurityUtils.getSubject(); - UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe); - try - { - currentUser.login(token); - return true; - - // the following exceptions are just a few you can catch and handle accordingly. See the - // AuthenticationException JavaDoc and its subclasses for more. - } - catch (IncorrectCredentialsException ice) - { - error("Password is incorrect."); - } - catch (UnknownAccountException uae) - { - error("There is no account with that username."); - } - catch (AuthenticationException ae) - { - error("Invalid username and/or password."); - } - catch( Exception ex ) { - error("Login failed"); - } - return false; - } - + public boolean login(final String username, final String password, final boolean rememberMe) + { + final Subject currentUser = SecurityUtils.getSubject(); + final UsernamePasswordToken token = new UsernamePasswordToken(username, password, + rememberMe); + try + { + currentUser.login(token); + return true; + + // the following exceptions are just a few you can catch and handle accordingly. See the + // AuthenticationException JavaDoc and its subclasses for more. + } + catch (final IncorrectCredentialsException ice) + { + error("Password is incorrect."); + } + catch (final UnknownAccountException uae) + { + error("There is no account with that username."); + } + catch (final AuthenticationException ae) + { + error("Invalid username and/or password."); + } + catch (final Exception ex) + { + error("Login failed"); + } + return false; + } protected void onSignInSucceeded() { @@ -227,9 +217,19 @@ protected void onSignInSucceeded() // logged in, than continue to the original destination, // otherwise to the Home page if (!continueToOriginalDestination()) - { - setResponsePage(getApplication().getSessionSettings().getPageFactory().newPage( - getApplication().getHomePage())); - } + setResponsePage(getApplication().getSessionSettings() + .getPageFactory() + .newPage(getApplication().getHomePage())); + } + + + /** + * Set model object for rememberMe checkbox + * + * @param rememberMe + */ + public void setRememberMe(final boolean rememberMe) + { + this.rememberMe = rememberMe; } }