Skip to content

Commit

Permalink
org.wicketstuff.shiro.component.LoginPanel$SignInForm now extends Sta…
Browse files Browse the repository at this point in the history
…telessForm instead of Form

git-svn-id: file:///home/igor/dev/stuff/svnbackup/branches/wicketstuff-core-1.4@5663 ef7698a4-5110-0410-9fc6-c7eb3693863f
  • Loading branch information
seb authored and mocleiri committed Dec 31, 2010
1 parent d458e61 commit 760bc7c
Showing 1 changed file with 69 additions and 69 deletions.
Expand Up @@ -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;
Expand All @@ -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<String> username;

/**
* Sign in form.
*/
public final class SignInForm extends Form<Void>
public final class SignInForm extends StatelessForm<Void>
{
private static final long serialVersionUID = 1L;

Expand All @@ -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<String>("username", new PropertyModel<String>(properties, "username")));
add(password = new PasswordTextField("password", new PropertyModel<String>(properties, "password")));
add(username = new TextField<String>("username", new PropertyModel<String>(properties,
"username")));
add(password = new PasswordTextField("password", new PropertyModel<String>(properties,
"password")));

// MarkupContainer row for remember me checkbox
final WebMarkupContainer rememberMeRow = new WebMarkupContainer("rememberMeRow");
Expand All @@ -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<String> username;

/**
* @see org.apache.wicket.Component#Component(String)
*/
Expand All @@ -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
Expand Down Expand Up @@ -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.
*
Expand All @@ -190,46 +179,57 @@ 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()
{
// If login has been called because the user was not yet
// 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;
}
}

0 comments on commit 760bc7c

Please sign in to comment.