Author: alain_defrance
Date: 2010-10-13 09:46:15 -0400 (Wed, 13 Oct 2010)
New Revision: 4653
Modified:
components/wci/branches/adf/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java
components/wci/branches/adf/test/core/src/main/java/org/gatein/wci/container/ServletContainerContextImpl.java
components/wci/branches/adf/test/core/src/main/java/org/gatein/wci/spi/SPIAuthenticationTestCase.java
components/wci/branches/adf/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java
components/wci/branches/adf/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/ServletContainer.java
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/GenericAuthentication.java
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/TicketService.java
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/security/WCILoginController.java
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/security/WCILoginModule.java
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/spi/ServletContainerContext.java
Log:
Some bugs fixed
Modified:
components/wci/branches/adf/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java
===================================================================
---
components/wci/branches/adf/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java 2010-10-13
12:20:34 UTC (rev 4652)
+++
components/wci/branches/adf/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java 2010-10-13
13:46:15 UTC (rev 4653)
@@ -62,16 +62,18 @@
this.registration = null;
}
- public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password) {
- return GenericAuthentication.getInstance().login(userName, password, request,
response);
+ public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password, long validity)
+ {
+ return GenericAuthentication.getInstance().login(userName, password, request,
response, validity);
}
- public void logout(HttpServletRequest request, HttpServletResponse response) {
- GenericAuthentication.getInstance().logout(request, response);
+ public void logout(HttpServletRequest request, HttpServletResponse response)
+ {
+ GenericAuthentication.getInstance().logout(request, response);
}
- public void start()
+ public void start()
{
DefaultServletContainerFactory.registerContext(this);
Modified:
components/wci/branches/adf/test/core/src/main/java/org/gatein/wci/container/ServletContainerContextImpl.java
===================================================================
---
components/wci/branches/adf/test/core/src/main/java/org/gatein/wci/container/ServletContainerContextImpl.java 2010-10-13
12:20:34 UTC (rev 4652)
+++
components/wci/branches/adf/test/core/src/main/java/org/gatein/wci/container/ServletContainerContextImpl.java 2010-10-13
13:46:15 UTC (rev 4653)
@@ -61,7 +61,7 @@
this.registration = null;
}
- public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password)
+ public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password, long validity)
{
throw new UnsupportedOperationException();
}
Modified:
components/wci/branches/adf/test/core/src/main/java/org/gatein/wci/spi/SPIAuthenticationTestCase.java
===================================================================
---
components/wci/branches/adf/test/core/src/main/java/org/gatein/wci/spi/SPIAuthenticationTestCase.java 2010-10-13
12:20:34 UTC (rev 4652)
+++
components/wci/branches/adf/test/core/src/main/java/org/gatein/wci/spi/SPIAuthenticationTestCase.java 2010-10-13
13:46:15 UTC (rev 4653)
@@ -30,6 +30,7 @@
import org.gatein.wci.authentication.GenericAuthentication;
import org.gatein.wci.authentication.GenericAuthenticationResult;
import org.gatein.wci.authentication.ProgrammaticAuthenticationResult;
+import org.gatein.wci.authentication.TicketService;
import org.gatein.wci.security.Credentials;
import org.gatein.wci.impl.DefaultServletContainerFactory;
import org.jboss.unit.Failure;
@@ -71,7 +72,7 @@
container = DefaultServletContainerFactory.getInstance().getServletContainer();
container.addAuthenticationListener(new TestListener(v));
assertEquals("", v.value);
- result = container.login(req, resp, username, password);
+ result = container.login(req, resp, username, password,
TicketService.DEFAULT_VALIDITY);
assertNotNull(result);
if (result instanceof GenericAuthenticationResult)
{
@@ -79,16 +80,16 @@
// Test Ticket Service
Credentials srcCredentials = new Credentials(username, password);
String ticket =
GenericAuthentication.TICKET_SERVICE.createTicket(srcCredentials);
- Credentials resultCredentials =
GenericAuthentication.TICKET_SERVICE.validateToken(ticket, false);
+ Credentials resultCredentials =
GenericAuthentication.TICKET_SERVICE.validateTicket(ticket, false);
assertEquals(srcCredentials.getUsername(), resultCredentials.getUsername());
assertEquals(srcCredentials.getPassword(), resultCredentials.getPassword());
- assertNotNull(GenericAuthentication.TICKET_SERVICE.validateToken(ticket,
true));
- assertNull(GenericAuthentication.TICKET_SERVICE.validateToken(ticket,
true));
+ assertNotNull(GenericAuthentication.TICKET_SERVICE.validateTicket(ticket,
true));
+ assertNull(GenericAuthentication.TICKET_SERVICE.validateTicket(ticket,
true));
// Test Generic login
GenericAuthenticationResult gResult = (GenericAuthenticationResult) result;
String t = gResult.getTicket();
- Credentials credentials =
GenericAuthentication.TICKET_SERVICE.validateToken(t, true);
+ Credentials credentials =
GenericAuthentication.TICKET_SERVICE.validateTicket(t, true);
assertNotNull(credentials);
assertEquals("", v.value);
gAuthentication.perform(req, resp);
Modified:
components/wci/branches/adf/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java
===================================================================
---
components/wci/branches/adf/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java 2010-10-13
12:20:34 UTC (rev 4652)
+++
components/wci/branches/adf/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java 2010-10-13
13:46:15 UTC (rev 4653)
@@ -99,9 +99,9 @@
this.registration = null;
}
- public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password)
+ public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password, long validity)
{
- return GenericAuthentication.getInstance().login(userName, password, request,
response);
+ return GenericAuthentication.getInstance().login(userName, password, request,
response, validity);
}
public void logout(HttpServletRequest request, HttpServletResponse response)
Modified:
components/wci/branches/adf/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java
===================================================================
---
components/wci/branches/adf/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java 2010-10-13
12:20:34 UTC (rev 4652)
+++
components/wci/branches/adf/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java 2010-10-13
13:46:15 UTC (rev 4653)
@@ -40,6 +40,7 @@
import org.gatein.wci.authentication.GenericAuthentication;
import org.gatein.wci.authentication.GenericAuthenticationResult;
import org.gatein.wci.authentication.ProgrammaticAuthenticationResult;
+import org.gatein.wci.authentication.TicketService;
import org.gatein.wci.command.CommandDispatcher;
import org.gatein.wci.impl.DefaultServletContainerFactory;
import org.gatein.wci.security.Credentials;
@@ -103,7 +104,7 @@
this.registration = null;
}
- public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password) throws ServletException
+ public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password, long validity) throws ServletException
{
try
{
@@ -113,6 +114,7 @@
{
try
{
+
GenericAuthentication.TICKET_SERVICE.setValidityMillis(TicketService.DEFAULT_VALIDITY);
String ticket = GenericAuthentication.TICKET_SERVICE.createTicket(new
Credentials(userName, password));
String url = "j_security_check?j_username=" + userName +
"&j_password=" + ticket;
url = response.encodeRedirectURL(url);
Modified:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/ServletContainer.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/ServletContainer.java 2010-10-13
12:20:34 UTC (rev 4652)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/ServletContainer.java 2010-10-13
13:46:15 UTC (rev 4653)
@@ -102,7 +102,7 @@
* @param userName the username which try to login
* @param password the password of the username
*/
- AuthenticationResult login(HttpServletRequest request, HttpServletResponse response,
String userName, String password) throws ServletException;
+ AuthenticationResult login(HttpServletRequest request, HttpServletResponse response,
String userName, String password, long validity) throws ServletException;
/**
* Authentication support.
Modified:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/GenericAuthentication.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/GenericAuthentication.java 2010-10-13
12:20:34 UTC (rev 4652)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/GenericAuthentication.java 2010-10-13
13:46:15 UTC (rev 4653)
@@ -28,15 +28,16 @@
* @author <a href="mailto:alain.defrance@exoplatform.com">Alain
Defrance</a>
* @version $Revision$
*/
-public class GenericAuthentication //extends AbstractAuthentication
+public class GenericAuthentication
{
public static final TicketService TICKET_SERVICE = new TicketService();
private static final GenericAuthentication GENERIC_AUTHENTICATION = new
GenericAuthentication();
private GenericAuthentication() {}
- public AuthenticationResult login(String login, String password, HttpServletRequest
request, HttpServletResponse response)
+ public AuthenticationResult login(String login, String password, HttpServletRequest
request, HttpServletResponse response, long validity)
{
+ TICKET_SERVICE.setValidityMillis(validity);
String ticket = TICKET_SERVICE.createTicket(new Credentials(login, password));
return new GenericAuthenticationResult(login, ticket);
Modified:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/TicketService.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/TicketService.java 2010-10-13
12:20:34 UTC (rev 4652)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/authentication/TicketService.java 2010-10-13
13:46:15 UTC (rev 4653)
@@ -30,8 +30,9 @@
*/
public class TicketService
{
-
- protected long validityMillis = 1000 * 60; // TODO : Init from confguration
+ public static final long DEFAULT_VALIDITY = 60 * 1000;
+
+ protected long validityMillis;
protected final ConcurrentHashMap<String, Ticket> tickets = new
ConcurrentHashMap<String, Ticket>();
@@ -53,7 +54,7 @@
return tokenId;
}
- public Credentials validateToken(String stringKey, boolean remove)
+ public Credentials validateTicket(String stringKey, boolean remove)
{
if (stringKey == null)
{
@@ -94,7 +95,18 @@
return null;
}
- private String nextTicketId() {
- return "wci-ticket-" + random.nextInt();
+ private String nextTicketId()
+ {
+ return "wci-ticket-" + random.nextInt();
}
+
+ public long getValidityMillis()
+ {
+ return validityMillis;
+ }
+
+ public void setValidityMillis(long validityMillis)
+ {
+ this.validityMillis = validityMillis;
+ }
}
Modified:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java 2010-10-13
12:20:34 UTC (rev 4652)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java 2010-10-13
13:46:15 UTC (rev 4653)
@@ -99,9 +99,9 @@
}
/** . */
- public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password) throws ServletException
+ public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password, long validity) throws ServletException
{
- AuthenticationResult result = registration.context.login(request, response,
userName, password);
+ AuthenticationResult result = registration.context.login(request, response,
userName, password, validity);
//
if (!(result instanceof GenericAuthenticationResult))
Modified:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java 2010-10-13
12:20:34 UTC (rev 4652)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java 2010-10-13
13:46:15 UTC (rev 4653)
@@ -130,9 +130,9 @@
this.registration = null;
}
- public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password)
+ public AuthenticationResult login(HttpServletRequest request, HttpServletResponse
response, String userName, String password, long validity)
{
- return GenericAuthentication.getInstance().login(userName, password, request,
response);
+ return GenericAuthentication.getInstance().login(userName, password, request,
response, validity);
}
public void logout(HttpServletRequest request, HttpServletResponse response)
Modified:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/security/WCILoginController.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/security/WCILoginController.java 2010-10-13
12:20:34 UTC (rev 4652)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/security/WCILoginController.java 2010-10-13
13:46:15 UTC (rev 4653)
@@ -45,6 +45,12 @@
String username = req.getParameter("username");
String password = req.getParameter("password");
+ if (
+ req.getSession().getAttribute(Credentials.CREDENTIALS) != null
+ && username == null
+ && password == null
+ ) return;
+
//
if (username == null)
{
Modified:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/security/WCILoginModule.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/security/WCILoginModule.java 2010-10-13
12:20:34 UTC (rev 4652)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/security/WCILoginModule.java 2010-10-13
13:46:15 UTC (rev 4653)
@@ -62,7 +62,7 @@
callbackHandler.handle(callbacks);
String password = new String(((PasswordCallback)callbacks[1]).getPassword());
- Credentials credentials =
GenericAuthentication.TICKET_SERVICE.validateToken(password, true);
+ Credentials credentials =
GenericAuthentication.TICKET_SERVICE.validateTicket(password, true);
sharedState.put("javax.security.auth.login.name",
credentials.getUsername());
sharedState.put("javax.security.auth.login.password",
credentials.getPassword());
}
Modified:
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/spi/ServletContainerContext.java
===================================================================
---
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/spi/ServletContainerContext.java 2010-10-13
12:20:34 UTC (rev 4652)
+++
components/wci/branches/adf/wci/src/main/java/org/gatein/wci/spi/ServletContainerContext.java 2010-10-13
13:46:15 UTC (rev 4653)
@@ -82,7 +82,7 @@
* @param userName the username which try to login
* @param password the password of the username
*/
- AuthenticationResult login(HttpServletRequest request, HttpServletResponse response,
String userName, String password) throws ServletException;
+ AuthenticationResult login(HttpServletRequest request, HttpServletResponse response,
String userName, String password, long validity) throws ServletException;
/**
* Authentication support.