Skip to content

Commit

Permalink
Use plexus-security and remember me (not finished)
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/maven/continuum/trunk@367386 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Emmanuel Venisse committed Jan 9, 2006
1 parent fe3d5a6 commit 9d1e2d3
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 5 deletions.
5 changes: 5 additions & 0 deletions continuum-webapp/pom.xml
Expand Up @@ -44,6 +44,11 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-security-osuser</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-remember-me</artifactId>
<version>1.0-alpha-1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
Expand Down
Expand Up @@ -16,7 +16,18 @@
* limitations under the License.
*/

import org.codehaus.plexus.rememberme.RememberMeServices;
import org.codehaus.plexus.security.Authentication;
import org.codehaus.plexus.security.Authenticator;
import org.codehaus.plexus.security.DefaultAuthentication;
import org.codehaus.plexus.security.User;

import com.opensymphony.xwork.ActionSupport;
import com.opensymphony.webwork.ServletActionContext;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpSession;

/**
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
Expand All @@ -25,17 +36,62 @@
public class LoginAction
extends ActionSupport
{
private Authenticator authenticator;

private RememberMeServices rememberMeServices;

private String username = "";

private String password = "";

private boolean rememberMe = false;

/**
* Execute the login action
*/
public String execute()
throws Exception
{
return SUCCESS;
try
{
Map params = new HashMap();

params.put( "username", username );

params.put( "password", password );

User user = authenticator.authenticate( params );

if ( rememberMe )
{
Authentication auth = new DefaultAuthentication();

auth.setUser( user );

auth.setAuthenticated( true );

rememberMeServices.loginSuccess( ServletActionContext.getRequest(),
ServletActionContext.getResponse(), auth );
}

HttpSession session = ServletActionContext.getRequest().getSession( true );

session.setAttribute( "authentication", user );

return SUCCESS;
}
catch ( Exception e )
{
addActionError( "Login failed. " + e.getMessage() );

if ( rememberMe )
{
rememberMeServices.loginFail( ServletActionContext.getRequest(),
ServletActionContext.getResponse() );
}

return INPUT;
}
}

/**
Expand All @@ -51,18 +107,28 @@ public String getUsername()
return username;
}

public String getPassword()
public void setUsername( String username )
{
return password;
this.username = username;
}

public void setUsername( String username )
public String getPassword()
{
this.username = username;
return password;
}

public void setPassword( String password )
{
this.password = password;
}

public boolean isRememberMe()
{
return rememberMe;
}

public void setRememberMe( boolean rememberMe )
{
this.rememberMe = rememberMe;
}
}
Expand Up @@ -53,6 +53,7 @@ login.page.title = Continuum - Authentication
login.section.title = Authentication
login.username = Username
login.password = Password
login.rememberMe = Remember me
login.submit = Connect

// ----------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions continuum-webapp/src/main/webapp/login.jsp
Expand Up @@ -12,6 +12,7 @@
<ww:form action="login" method="post">
<ww:textfield label="%{getText('login.username')}" name="username" required="true"/>
<ww:password label="%{getText('login.password')}" name="password" required="true"/>
<ww:checkbox label="%{getText('login.rememberMe')}" name="rememberMe" value="rememberMe" fieldValue="true"/>
<c1:submitcancel value="%{getText('login.submit')}" cancel="%{getText('cancel')}"/>
</ww:form>
</div>
Expand Down

0 comments on commit 9d1e2d3

Please sign in to comment.