Author: marcelkolsteren
Date: 2010-06-22 03:46:51 -0400 (Tue, 22 Jun 2010)
New Revision: 316
Modified:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/InternalAuthenticator.java
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/OpenIdSingleLoginReceiver.java
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/OpenIdSingleLoginSender.java
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/SamlSingleSignOnReceiver.java
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/SamlSingleSignOnSender.java
Log:
PLFED-90: "Seam authentication filter: add events support"
Modified:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/InternalAuthenticator.java
===================================================================
---
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/InternalAuthenticator.java 2010-06-18
18:06:34 UTC (rev 315)
+++
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/InternalAuthenticator.java 2010-06-22
07:46:51 UTC (rev 316)
@@ -25,12 +25,14 @@
import java.util.LinkedList;
import java.util.List;
+import javax.security.auth.login.LoginException;
import javax.servlet.http.HttpServletRequest;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Import;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
+import org.jboss.seam.core.Events;
import org.jboss.seam.security.Identity;
import org.picketlink.identity.seam.federation.configuration.ServiceProvider;
@@ -54,13 +56,29 @@
List<String> roles = new LinkedList<String>();
Boolean internallyAuthenticated =
serviceProvider.getInternalAuthenticationMethod().invoke(principal, roles);
+ if (Events.exists())
+ {
+ Events.instance().raiseEvent(Identity.EVENT_POST_AUTHENTICATE, identity);
+ }
+
if (internallyAuthenticated)
{
identity.acceptExternallyAuthenticatedPrincipal(principal);
+
for (String role : roles)
{
identity.addRole(role);
}
+
+ if (Events.exists())
+ {
+ Events.instance().raiseEvent(Identity.EVENT_LOGIN_SUCCESSFUL);
+ }
+ } else {
+ if (Events.exists())
+ {
+ Events.instance().raiseEvent(Identity.EVENT_LOGIN_FAILED, new
LoginException());
+ }
}
return internallyAuthenticated;
Modified:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/OpenIdSingleLoginReceiver.java
===================================================================
---
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/OpenIdSingleLoginReceiver.java 2010-06-18
18:06:34 UTC (rev 315)
+++
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/OpenIdSingleLoginReceiver.java 2010-06-22
07:46:51 UTC (rev 316)
@@ -25,6 +25,7 @@
import java.net.URL;
import java.util.Map;
+import javax.security.auth.login.LoginException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -32,6 +33,8 @@
import org.jboss.seam.annotations.Import;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
+import org.jboss.seam.core.Events;
+import org.jboss.seam.security.Identity;
import org.openid4java.OpenIDException;
import org.openid4java.consumer.ConsumerManager;
import org.openid4java.consumer.VerificationResult;
@@ -111,6 +114,10 @@
}
else
{
+ if (Events.exists())
+ {
+ Events.instance().raiseEvent(Identity.EVENT_LOGIN_FAILED, new
LoginException());
+ }
authenticated = false;
}
Modified:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/OpenIdSingleLoginSender.java
===================================================================
---
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/OpenIdSingleLoginSender.java 2010-06-18
18:06:34 UTC (rev 315)
+++
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/OpenIdSingleLoginSender.java 2010-06-22
07:46:51 UTC (rev 316)
@@ -30,6 +30,8 @@
import org.jboss.seam.annotations.Import;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
+import org.jboss.seam.core.Events;
+import org.jboss.seam.security.Identity;
import org.openid4java.OpenIDException;
import org.openid4java.consumer.ConsumerManager;
import org.openid4java.discovery.DiscoveryInformation;
@@ -87,12 +89,22 @@
String url = authReq.getDestinationUrl(true);
+ if (Events.exists())
+ {
+ Events.instance().raiseEvent(Identity.EVENT_PRE_AUTHENTICATE);
+ }
+
httpResponse.sendRedirect(url);
}
catch (OpenIDException e)
{
try
{
+ if (Events.exists())
+ {
+ Events.instance().raiseEvent(Identity.EVENT_LOGIN_FAILED);
+ }
+
httpResponse.sendRedirect(serviceProvider.getFailedAuthenticationUrl());
}
catch (IOException e1)
Modified:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/SamlSingleSignOnReceiver.java
===================================================================
---
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/SamlSingleSignOnReceiver.java 2010-06-18
18:06:34 UTC (rev 315)
+++
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/SamlSingleSignOnReceiver.java 2010-06-22
07:46:51 UTC (rev 316)
@@ -25,6 +25,7 @@
import java.util.LinkedList;
import java.util.List;
+import javax.security.auth.login.LoginException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.bind.JAXBElement;
@@ -36,6 +37,7 @@
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
+import org.jboss.seam.core.Events;
import org.jboss.seam.log.Log;
import org.jboss.seam.security.Identity;
import org.picketlink.identity.federation.core.exceptions.ConfigurationException;
@@ -116,6 +118,12 @@
{
try
{
+ if (Events.exists())
+ {
+ Events.instance().raiseEvent(Identity.EVENT_POST_AUTHENTICATE, identity);
+ Events.instance().raiseEvent(Identity.EVENT_LOGIN_FAILED, new
LoginException());
+ }
+
httpResponse.sendRedirect(serviceProvider.getFailedAuthenticationUrl());
}
catch (IOException e)
@@ -286,8 +294,8 @@
}
}
- private void loginUser(HttpServletRequest httpRequest, HttpServletResponse
httpResponse, SeamSamlPrincipal principal,
- RequestContext requestContext)
+ private void loginUser(HttpServletRequest httpRequest, HttpServletResponse
httpResponse,
+ SeamSamlPrincipal principal, RequestContext requestContext)
{
if (identity.isLoggedIn())
{
Modified:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/SamlSingleSignOnSender.java
===================================================================
---
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/SamlSingleSignOnSender.java 2010-06-18
18:06:34 UTC (rev 315)
+++
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/SamlSingleSignOnSender.java 2010-06-22
07:46:51 UTC (rev 316)
@@ -28,6 +28,8 @@
import org.jboss.seam.annotations.Import;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
+import org.jboss.seam.core.Events;
+import org.jboss.seam.security.Identity;
import org.picketlink.identity.federation.saml.v2.protocol.AuthnRequestType;
import org.picketlink.identity.seam.federation.configuration.SamlIdentityProvider;
@@ -55,6 +57,11 @@
AuthnRequestType authnRequest = samlMessageFactory.createAuthnRequest();
requests.addRequest(authnRequest.getID(), samlIdentityProvider, returnUrl);
+ if (Events.exists())
+ {
+ Events.instance().raiseEvent(Identity.EVENT_PRE_AUTHENTICATE);
+ }
+
samlMessageSender.sendRequestToIDP(request, response, samlIdentityProvider,
SamlProfile.SINGLE_SIGN_ON,
authnRequest);
}