Author: marcelkolsteren
Date: 2010-09-26 17:20:08 -0400 (Sun, 26 Sep 2010)
New Revision: 422
Added:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/AuthenticationProtocol.java
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookConstants.java
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookLoginReceiver.java
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookLoginSender.java
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookPrincipal.java
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/OAuthConstants.java
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/configuration/FacebookConfiguration.java
federation/trunk/picketlink-webapps/seam-sp/src/main/webapp/images/
federation/trunk/picketlink-webapps/seam-sp/src/main/webapp/images/login_with_facebook.png
federation/trunk/picketlink-webapps/seam-sp/src/main/webapp/styles.css
Modified:
federation/trunk/picketlink-seam/pom.xml
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/ExternalAuthenticationFilter.java
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/ExternalAuthenticationService.java
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/ExternalAuthenticator.java
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/PagesSupportingExternalAuthentication.java
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/configuration/ServiceProvider.java
federation/trunk/picketlink-seam/src/main/resources/schema/config/external-authentication-config.xsd
federation/trunk/picketlink-webapps/seam-sp/src/main/resources/external-authentication-config.xml
federation/trunk/picketlink-webapps/seam-sp/src/main/webapp/Login.xhtml
federation/trunk/picketlink-webapps/seam-sp/src/main/webapp/PrincipalInfoFragment.xhtml
Log:
PLFED-105: add support for logging in with Facebook, based on the new OAuth 2.0 API
Modified: federation/trunk/picketlink-seam/pom.xml
===================================================================
--- federation/trunk/picketlink-seam/pom.xml 2010-09-24 09:49:09 UTC (rev 421)
+++ federation/trunk/picketlink-seam/pom.xml 2010-09-26 21:20:08 UTC (rev 422)
@@ -1,220 +1,225 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
- <parent>
- <groupId>org.picketlink</groupId>
- <artifactId>picketlink-fed-parent</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- <relativePath>../parent</relativePath>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <artifactId>picketlink-seam</artifactId>
- <packaging>jar</packaging>
- <name>PicketLink Federation Bindings for Seam</name>
- <
url>http://labs.jboss.org/portal/picketlink/
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.picketlink</groupId>
+ <artifactId>picketlink-fed-parent</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ <relativePath>../parent</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>picketlink-seam</artifactId>
+ <packaging>jar</packaging>
+ <name>PicketLink Federation Bindings for Seam</name>
+ <
url>http://labs.jboss.org/portal/picketlink/
</url>
- <description>PicketLink Seam bindings contain the default
+ <description>PicketLink Seam bindings contain the default
bindings needed for Seam web applications.</description>
- <licenses>
- <license>
- <name>lgpl</name>
- <
url>http://repository.jboss.com/licenses/lgpl.txt
+ <licenses>
+ <license>
+ <name>lgpl</name>
+ <
url>http://repository.jboss.com/licenses/lgpl.txt
</url>
- </license>
- </licenses>
- <organization>
- <name>JBoss Inc.</name>
- <url>http://www.jboss.org</url>
- </organization>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.4.3</version>
- <configuration>
- <printSummary>true</printSummary>
- <disableXmlReport>false</disableXmlReport>
- <testFailureIgnore>false</testFailureIgnore>
- <includes>
- <include>**/**TestCase.java</include>
- </includes>
- <forkMode>pertest</forkMode>
- <argLine>
- -Djava.endorsed.dirs=${basedir}/src/test/resources/endorsed
+ </license>
+ </licenses>
+ <organization>
+ <name>JBoss Inc.</name>
+ <url>http://www.jboss.org</url>
+ </organization>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.4.3</version>
+ <configuration>
+ <printSummary>true</printSummary>
+ <disableXmlReport>false</disableXmlReport>
+ <testFailureIgnore>false</testFailureIgnore>
+ <includes>
+ <include>**/**TestCase.java</include>
+ </includes>
+ <forkMode>pertest</forkMode>
+ <argLine>
+ -Djava.endorsed.dirs=${basedir}/src/test/resources/endorsed
</argLine>
- <useFile>false</useFile>
- <trimStackTrace>false</trimStackTrace>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>jaxb2-maven-plugin</artifactId>
- <version>1.3</version>
- <executions>
- <execution>
- <id>jaxb-xrds</id>
- <configuration>
-
<schemaDirectory>${basedir}/src/main/resources/schema/xrds</schemaDirectory>
-
<packageName>org.picketlink.identity.seam.federation.jaxb.xrds</packageName>
-
<outputDirectory>${basedir}/src/main/generated-source</outputDirectory>
- <clearOutputDir>true</clearOutputDir>
-
<staleFile>${project.build.directory}/generated-sources/jaxb/.staleFlag_xrds</staleFile>
- </configuration>
- <goals>
- <goal>xjc</goal>
- </goals>
- </execution>
- <execution>
- <id>jaxb-config</id>
- <configuration>
-
<schemaDirectory>${basedir}/src/main/resources/schema/config</schemaDirectory>
-
<packageName>org.picketlink.identity.seam.federation.jaxb.config</packageName>
-
<outputDirectory>${basedir}/src/main/generated-source</outputDirectory>
- <clearOutputDir>false</clearOutputDir>
-
<staleFile>${project.build.directory}/generated-sources/jaxb/.staleFlag_config</staleFile>
- </configuration>
- <goals>
- <goal>xjc</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- <dependencies>
- <dependency>
- <groupId>org.picketlink</groupId>
- <artifactId>picketlink-fed-model</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.picketlink</groupId>
- <artifactId>picketlink-fed-api</artifactId>
- <version>${project.version}</version>
- <exclusions>
- <exclusion>
- <groupId>org.jboss.security</groupId>
- <artifactId>jboss-security-spi</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.picketlink</groupId>
- <artifactId>picketlink-web</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.5</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.seam</groupId>
- <artifactId>jboss-seam</artifactId>
- <version>2.1.2.GA</version>
- <type>ejb</type>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>sun-jaf</groupId>
- <artifactId>activation</artifactId>
- <version>1.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>sun-jaf</groupId>
- <artifactId>activation</artifactId>
- <version>1.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>javax.faces</groupId>
- <artifactId>jsf-api</artifactId>
- <version>1.2</version>
- <scope>provided</scope>
- </dependency>
- <!-- START OF DEPENDENCIES NEEDED FOR OPENID4JAVA -->
- <dependency>
- <groupId>org.htmlparser</groupId>
- <artifactId>htmlparser</artifactId>
- <version>1.6</version>
- </dependency>
- <dependency>
- <groupId>org.openxri</groupId>
- <artifactId>openxri-client</artifactId>
- <version>1.2.0</version>
- <exclusions>
- <exclusion>
- <artifactId>xercesImpl</artifactId>
- <groupId>xerces</groupId>
- </exclusion>
- <exclusion>
- <artifactId>xalan</artifactId>
- <groupId>xalan</groupId>
- </exclusion>
- <exclusion>
- <artifactId>log4j</artifactId>
- <groupId>log4j</groupId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.openxri</groupId>
- <artifactId>openxri-syntax</artifactId>
- <version>1.2.0</version>
- <exclusions>
- <exclusion>
- <artifactId>log4j</artifactId>
- <groupId>log4j</groupId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>3.1</version>
- </dependency>
- <dependency>
- <groupId>net.sourceforge.nekohtml</groupId>
- <artifactId>nekohtml</artifactId>
- <version>1.9.13</version>
- <exclusions>
- <exclusion>
- <artifactId>xercesImpl</artifactId>
- <groupId>xerces</groupId>
- </exclusion>
- </exclusions>
- </dependency>
- <!-- END OF DEPENDENCIES NEEDED FOR OPENID4JAVA -->
- </dependencies>
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <configuration>
- <doclet>org.jboss.apiviz.APIviz</doclet>
- <docletArtifact>
- <groupId>org.jboss.apiviz</groupId>
- <artifactId>apiviz</artifactId>
- <version>1.2.5.GA</version>
- </docletArtifact>
- <additionalparam> -charset UTF-8 -docencoding UTF-8 -version
- -author -breakiterator -windowtitle "${project.name}
- ${project.version} API Reference" -doctitle "${project.name}
- ${project.version} API Reference" -bottom "Copyright ©
- ${project.inceptionYear}-Present ${project.organization.name}. All
- Rights Reserved." -link
http://java.sun.com/javase/6/docs/api/
- -sourceclasspath ${project.build.outputDirectory}
+ <useFile>false</useFile>
+ <trimStackTrace>false</trimStackTrace>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>jaxb2-maven-plugin</artifactId>
+ <version>1.3</version>
+ <executions>
+ <execution>
+ <id>jaxb-xrds</id>
+ <configuration>
+ <schemaDirectory>${basedir}/src/main/resources/schema/xrds</schemaDirectory>
+ <packageName>org.picketlink.identity.seam.federation.jaxb.xrds</packageName>
+ <outputDirectory>${basedir}/src/main/generated-source</outputDirectory>
+ <clearOutputDir>true</clearOutputDir>
+ <staleFile>${project.build.directory}/generated-sources/jaxb/.staleFlag_xrds</staleFile>
+ </configuration>
+ <goals>
+ <goal>xjc</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>jaxb-config</id>
+ <configuration>
+ <schemaDirectory>${basedir}/src/main/resources/schema/config</schemaDirectory>
+ <packageName>org.picketlink.identity.seam.federation.jaxb.config</packageName>
+ <outputDirectory>${basedir}/src/main/generated-source</outputDirectory>
+ <clearOutputDir>false</clearOutputDir>
+ <staleFile>${project.build.directory}/generated-sources/jaxb/.staleFlag_config</staleFile>
+ </configuration>
+ <goals>
+ <goal>xjc</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.picketlink</groupId>
+ <artifactId>picketlink-fed-model</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.picketlink</groupId>
+ <artifactId>picketlink-fed-api</artifactId>
+ <version>${project.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss.security</groupId>
+ <artifactId>jboss-security-spi</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.picketlink</groupId>
+ <artifactId>picketlink-web</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.seam</groupId>
+ <artifactId>jboss-seam</artifactId>
+ <version>2.1.2.GA</version>
+ <type>ejb</type>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>sun-jaf</groupId>
+ <artifactId>activation</artifactId>
+ <version>1.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>sun-jaf</groupId>
+ <artifactId>activation</artifactId>
+ <version>1.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.faces</groupId>
+ <artifactId>jsf-api</artifactId>
+ <version>1.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.json</groupId>
+ <artifactId>json</artifactId>
+ <version>20090211</version>
+ </dependency>
+ <!-- START OF DEPENDENCIES NEEDED FOR OPENID4JAVA -->
+ <dependency>
+ <groupId>org.htmlparser</groupId>
+ <artifactId>htmlparser</artifactId>
+ <version>1.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openxri</groupId>
+ <artifactId>openxri-client</artifactId>
+ <version>1.2.0</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>xercesImpl</artifactId>
+ <groupId>xerces</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>xalan</artifactId>
+ <groupId>xalan</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>log4j</artifactId>
+ <groupId>log4j</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.openxri</groupId>
+ <artifactId>openxri-syntax</artifactId>
+ <version>1.2.0</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>log4j</artifactId>
+ <groupId>log4j</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.nekohtml</groupId>
+ <artifactId>nekohtml</artifactId>
+ <version>1.9.13</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>xercesImpl</artifactId>
+ <groupId>xerces</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <!-- END OF DEPENDENCIES NEEDED FOR OPENID4JAVA -->
+ </dependencies>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <doclet>org.jboss.apiviz.APIviz</doclet>
+ <docletArtifact>
+ <groupId>org.jboss.apiviz</groupId>
+ <artifactId>apiviz</artifactId>
+ <version>1.2.5.GA</version>
+ </docletArtifact>
+ <additionalparam> -charset UTF-8 -docencoding UTF-8 -version
+ -author -breakiterator -windowtitle "${project.name}
+ ${project.version} API Reference" -doctitle "${project.name}
+ ${project.version} API Reference" -bottom "Copyright ©
+ ${project.inceptionYear}-Present ${project.organization.name}. All
+ Rights Reserved." -link
http://java.sun.com/javase/6/docs/api/
+ -sourceclasspath ${project.build.outputDirectory}
</additionalparam>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
- </plugins>
- </reporting>
+ <encoding>UTF-8</encoding>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
</project>
Added:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/AuthenticationProtocol.java
===================================================================
---
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/AuthenticationProtocol.java
(rev 0)
+++
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/AuthenticationProtocol.java 2010-09-26
21:20:08 UTC (rev 422)
@@ -0,0 +1,30 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.picketlink.identity.seam.federation;
+
+/**
+* @author Marcel Kolsteren
+* @since Sep 25, 2010
+*/
+public enum AuthenticationProtocol {
+ SAML, OPEN_ID, FACEBOOK
+}
Property changes on:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/AuthenticationProtocol.java
___________________________________________________________________
Name: svn
+ eol-style=native
Name: svn:keywords
+ Revision Author Date
Modified:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/ExternalAuthenticationFilter.java
===================================================================
---
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/ExternalAuthenticationFilter.java 2010-09-24
09:49:09 UTC (rev 421)
+++
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/ExternalAuthenticationFilter.java 2010-09-26
21:20:08 UTC (rev 422)
@@ -70,6 +70,8 @@
public static final String OPEN_ID_PARAMETER = "openId";
+ public static final String AUTHENTICATION_PROTOCOL_PARAMETER =
"authProtocol";
+
@Logger
private Log log;
@@ -156,33 +158,46 @@
case AUTHENTICATION_SERVICE :
String returnUrl = httpRequest.getParameter(RETURN_URL_PARAMETER);
- String providerName = httpRequest.getParameter(IDP_ENTITY_ID_PARAMETER);
- if (providerName != null)
+ String authenticationProtocolParam =
httpRequest.getParameter(AUTHENTICATION_PROTOCOL_PARAMETER);
+ AuthenticationProtocol authProtocol =
Enum.valueOf(AuthenticationProtocol.class,
+ authenticationProtocolParam);
+
+ switch (authProtocol)
{
- SamlIdentityProvider identityProvider =
Configuration.instance().getServiceProvider()
-
.getSamlConfiguration().getSamlIdentityProviderByEntityId(providerName);
+ case SAML : {
+ String providerName =
httpRequest.getParameter(IDP_ENTITY_ID_PARAMETER);
+ SamlIdentityProvider identityProvider =
Configuration.instance().getServiceProvider()
+
.getSamlConfiguration().getSamlIdentityProviderByEntityId(providerName);
- // User requested a page for which login is required. Return a page
- // that instructs the browser to post an authentication request to the
IDP.
- if (identityProvider instanceof SamlIdentityProvider)
- {
- SamlSingleSignOnSender samlSingleSignOnSender =
(SamlSingleSignOnSender) Component
- .getInstance(SamlSingleSignOnSender.class);
- samlSingleSignOnSender.sendAuthenticationRequestToIDP(httpRequest,
httpResponse,
- (SamlIdentityProvider) identityProvider, returnUrl);
+ // User requested a page for which login is required. Return a page
+ // that instructs the browser to post an authentication request to the
IDP.
+ if (identityProvider instanceof SamlIdentityProvider)
+ {
+ SamlSingleSignOnSender samlSingleSignOnSender =
(SamlSingleSignOnSender) Component
+ .getInstance(SamlSingleSignOnSender.class);
+ samlSingleSignOnSender.sendAuthenticationRequestToIDP(httpRequest,
httpResponse,
+ (SamlIdentityProvider) identityProvider, returnUrl);
+ }
+ else
+ {
+ throw new RuntimeException("Only SAML identity providers are
supported in this version");
+ }
+ break;
}
- else
- {
- throw new RuntimeException("Only SAML identity providers are
supported in this version");
+ case OPEN_ID : {
+ OpenIdSingleLoginSender openIdSingleLoginSender =
(OpenIdSingleLoginSender) Component
+ .getInstance(OpenIdSingleLoginSender.class);
+ String openId = httpRequest.getParameter(OPEN_ID_PARAMETER);
+ openIdSingleLoginSender.sendAuthRequest(openId, returnUrl,
httpResponse);
+ break;
}
+ case FACEBOOK : {
+ FacebookLoginSender facebookLoginSender = (FacebookLoginSender)
Component
+ .getInstance(FacebookLoginSender.class);
+ facebookLoginSender.sendAuthorizeRequest(returnUrl, httpResponse);
+ break;
+ }
}
- else
- {
- OpenIdSingleLoginSender openIdSingleLoginSender =
(OpenIdSingleLoginSender) Component
- .getInstance(OpenIdSingleLoginSender.class);
- String openId = httpRequest.getParameter(OPEN_ID_PARAMETER);
- openIdSingleLoginSender.sendAuthRequest(openId, returnUrl, httpResponse);
- }
break;
case LOGOUT_SERVICE :
Identity identity = (Identity) Component.getInstance(Identity.class);
@@ -221,6 +236,12 @@
httpResponse.setContentType("application/xrds+xml");
httpResponse.flushBuffer();
break;
+ case FACEBOOK_SERVICE :
+ FacebookLoginReceiver facebookLoginReceiver = (FacebookLoginReceiver)
Component
+ .getInstance(FacebookLoginReceiver.class);
+
+ facebookLoginReceiver.handleAuthenticationResponse(httpRequest,
httpResponse);
+ break;
default :
throw new RuntimeException("Unsupported service " + service);
}
Modified:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/ExternalAuthenticationService.java
===================================================================
---
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/ExternalAuthenticationService.java 2010-09-24
09:49:09 UTC (rev 421)
+++
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/ExternalAuthenticationService.java 2010-09-26
21:20:08 UTC (rev 422)
@@ -39,8 +39,10 @@
OPEN_ID_SERVICE("OpenIdService"),
- OPEN_ID_XRDS_SERVICE("OpenIdXrdsService");
+ OPEN_ID_XRDS_SERVICE("OpenIdXrdsService"),
+ FACEBOOK_SERVICE("FacebookService");
+
private String name;
private ExternalAuthenticationService(String name)
Modified:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/ExternalAuthenticator.java
===================================================================
---
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/ExternalAuthenticator.java 2010-09-24
09:49:09 UTC (rev 421)
+++
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/ExternalAuthenticator.java 2010-09-26
21:20:08 UTC (rev 422)
@@ -75,6 +75,7 @@
String authenticationServiceURL = serviceProvider
.getServiceURL(ExternalAuthenticationService.AUTHENTICATION_SERVICE);
Map<String, String> params = new HashMap<String, String>();
+ params.put(ExternalAuthenticationFilter.AUTHENTICATION_PROTOCOL_PARAMETER,
AuthenticationProtocol.SAML.name());
params.put(ExternalAuthenticationFilter.IDP_ENTITY_ID_PARAMETER, idpEntityId);
params.put(ExternalAuthenticationFilter.RETURN_URL_PARAMETER, returnUrl);
redirect(authenticationServiceURL, params);
@@ -94,11 +95,26 @@
String authenticationServiceURL = serviceProvider
.getServiceURL(ExternalAuthenticationService.AUTHENTICATION_SERVICE);
Map<String, String> params = new HashMap<String, String>();
+ params.put(ExternalAuthenticationFilter.AUTHENTICATION_PROTOCOL_PARAMETER,
AuthenticationProtocol.OPEN_ID.name());
params.put(ExternalAuthenticationFilter.RETURN_URL_PARAMETER, returnUrl);
params.put(ExternalAuthenticationFilter.OPEN_ID_PARAMETER, openId);
redirect(authenticationServiceURL, params);
}
+ public void facebookLogin()
+ {
+ if (serviceProvider.getFacebookConfiguration() == null)
+ {
+ throw new RuntimeException("Facebook is not configured.");
+ }
+ String authenticationServiceURL = serviceProvider
+ .getServiceURL(ExternalAuthenticationService.AUTHENTICATION_SERVICE);
+ Map<String, String> params = new HashMap<String, String>();
+ params.put(ExternalAuthenticationFilter.AUTHENTICATION_PROTOCOL_PARAMETER,
AuthenticationProtocol.FACEBOOK.name());
+ params.put(ExternalAuthenticationFilter.RETURN_URL_PARAMETER, returnUrl);
+ redirect(authenticationServiceURL, params);
+ }
+
public void singleLogout()
{
if (!identity.isLoggedIn())
Added:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookConstants.java
===================================================================
---
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookConstants.java
(rev 0)
+++
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookConstants.java 2010-09-26
21:20:08 UTC (rev 422)
@@ -0,0 +1,35 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.picketlink.identity.seam.federation;
+
+/**
+* @author Marcel Kolsteren
+* @since Sep 26, 2010
+*/
+public class FacebookConstants
+{
+ public static final String AUTHENTICATION_ENDPOINT_URL =
"https://graph.facebook.com/oauth/authorize";
+
+ public static final String ACCESS_TOKEN_ENDPOINT_URL =
"https://graph.facebook.com/oauth/access_token";
+
+ public static final String PROFILE_ENDPOINT_URL =
"https://graph.facebook.com/me";
+}
Property changes on:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookConstants.java
___________________________________________________________________
Name: svn
+ eol-style=native
Name: svn:keywords
+ Revision Author Date
Added:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookLoginReceiver.java
===================================================================
---
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookLoginReceiver.java
(rev 0)
+++
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookLoginReceiver.java 2010-09-26
21:20:08 UTC (rev 422)
@@ -0,0 +1,226 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.picketlink.identity.seam.federation;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.security.auth.login.LoginException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.seam.annotations.AutoCreate;
+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.json.JSONException;
+import org.json.JSONObject;
+import org.picketlink.identity.seam.federation.configuration.ServiceProvider;
+
+/**
+* @author Marcel Kolsteren
+* @since Sep 25, 2010
+*/
+(a)Name("org.picketlink.identity.seam.federation.facebookLoginReceiver")
+@AutoCreate
+public class FacebookLoginReceiver
+{
+ @In
+ private FacebookLoginSender facebookLoginSender;
+
+ @In
+ private InternalAuthenticator internalAuthenticator;
+
+ @In
+ private ServiceProvider serviceProvider;
+
+ public void handleAuthenticationResponse(HttpServletRequest request,
HttpServletResponse response)
+ {
+ String error = request.getParameter(OAuthConstants.ERROR_PARAMETER);
+ if (error != null)
+ {
+ sendErrorRedirect(response, error);
+ }
+ else
+ {
+ String returnUrl =
request.getParameter(ExternalAuthenticationFilter.RETURN_URL_PARAMETER);
+ if (returnUrl == null)
+ {
+ throw new RuntimeException("Return URL parameter not found");
+ }
+ String authorizationCode = request.getParameter(OAuthConstants.CODE_PARAMETER);
+ if (returnUrl == null)
+ {
+ throw new RuntimeException("Authorization code parameter not
found");
+ }
+
+ URLConnection connection = facebookLoginSender.sendAccessTokenRequest(returnUrl,
authorizationCode, response);
+
+ if (connection.getContentType().startsWith("text/plain"))
+ {
+ Map<String, String> params =
formUrlDecode(readUrlContent(connection));
+ String accessToken = params.get(OAuthConstants.ACCESS_TOKEN_PARAMETER);
+ if (accessToken == null)
+ {
+ throw new RuntimeException("No access token found");
+ }
+ else
+ {
+ login(request, response, accessToken, returnUrl);
+ }
+ }
+ else if (connection.getContentType().equals("application/json"))
+ {
+ sendErrorRedirect(response, readUrlContent(connection));
+ }
+ else
+ {
+ throw new RuntimeException("Unsupported content type: " +
connection.getContentType());
+ }
+ }
+ }
+
+ private Map<String, String> formUrlDecode(String encodedData)
+ {
+ Map<String, String> params = new HashMap<String, String>();
+ String[] elements = encodedData.split("&");
+ for (String element : elements)
+ {
+ String[] pair = element.split("=");
+ if (pair.length == 2)
+ {
+ String paramName = pair[0];
+ String paramValue;
+ try
+ {
+ paramValue = URLDecoder.decode(pair[1], "UTF-8");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new RuntimeException(e);
+ }
+ params.put(paramName, paramValue);
+ }
+ else
+ {
+ throw new RuntimeException("Unexpected name-value pair in response:
" + element);
+ }
+ }
+ return params;
+ }
+
+ public void login(HttpServletRequest request, HttpServletResponse response, String
accessToken, String returnUrl)
+ {
+ FacebookPrincipal facebookPrincipal = null;
+ try
+ {
+ String urlString = new
StringBuilder(FacebookConstants.PROFILE_ENDPOINT_URL).append("?access_token=").append(
+ URLEncoder.encode(accessToken, "UTF-8")).toString();
+ URL profileUrl = new URL(urlString);
+ String profileContent = readUrlContent(profileUrl.openConnection());
+ JSONObject jsonObject = new JSONObject(profileContent);
+
+ facebookPrincipal = new FacebookPrincipal();
+ facebookPrincipal.setAccessToken(accessToken);
+ facebookPrincipal.setId(jsonObject.getString("id"));
+ facebookPrincipal.setName(jsonObject.getString("name"));
+ facebookPrincipal.setFirstName(jsonObject.getString("first_name"));
+ facebookPrincipal.setLastName(jsonObject.getString("last_name"));
+ facebookPrincipal.setGender(jsonObject.getString("gender"));
+ facebookPrincipal.setTimezone(jsonObject.getString("timezone"));
+ facebookPrincipal.setLocale(jsonObject.getString("locale"));
+ if (jsonObject.getString("email") != null)
+ {
+ facebookPrincipal.setEmail(jsonObject.getString("email"));
+ }
+ }
+ catch (JSONException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ boolean authenticated = internalAuthenticator.authenticate(facebookPrincipal,
request);
+
+ try
+ {
+ if (authenticated)
+ {
+ response.sendRedirect(returnUrl);
+ }
+ else
+ {
+ sendErrorRedirect(response, null);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private void sendErrorRedirect(HttpServletResponse response, String message)
+ {
+ LoginException exception = message != null ? new LoginException(message) : new
LoginException();
+ Events.instance().raiseEvent(Identity.EVENT_LOGIN_FAILED, exception);
+ try
+ {
+ response.sendRedirect(serviceProvider.getFailedAuthenticationUrl());
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private String readUrlContent(URLConnection connection)
+ {
+ StringBuilder result = new StringBuilder();
+ try
+ {
+ Reader reader = new InputStreamReader(connection.getInputStream());
+ char[] buffer = new char[50];
+ int nrOfChars;
+ while ((nrOfChars = reader.read(buffer)) != -1)
+ {
+ result.append(buffer, 0, nrOfChars);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ return result.toString();
+ }
+}
Property changes on:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookLoginReceiver.java
___________________________________________________________________
Name: svn
+ eol-style=native
Name: svn:keywords
+ Revision Author Date
Added:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookLoginSender.java
===================================================================
---
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookLoginSender.java
(rev 0)
+++
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookLoginSender.java 2010-09-26
21:20:08 UTC (rev 422)
@@ -0,0 +1,145 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.picketlink.identity.seam.federation;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.seam.annotations.AutoCreate;
+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;
+
+/**
+* Component for sending login requests to Facebook.
+*
+* @author Marcel Kolsteren
+* @since Sep 25, 2010
+*/
+(a)Name("org.picketlink.identity.seam.federation.facebookLoginSender")
+@AutoCreate
+public class FacebookLoginSender
+{
+
+ @In
+ private ServiceProvider serviceProvider;
+
+ public void sendAuthorizeRequest(String returnUrl, HttpServletResponse response)
+ {
+ Events.instance().raiseEvent(Identity.EVENT_PRE_AUTHENTICATE);
+
+ String returnUri = getReturnUri(returnUrl);
+ String clientId = serviceProvider.getFacebookConfiguration().getClientId();
+ Map<String, String> params = new HashMap<String, String>();
+ params.put(OAuthConstants.REDIRECT_URI_PARAMETER, returnUri);
+ params.put(OAuthConstants.CLIENT_ID_PARAMETER, clientId);
+ String scope = serviceProvider.getFacebookConfiguration().getScope();
+ if (scope != null)
+ {
+ params.put(OAuthConstants.SCOPE_PARAMETER, scope);
+ }
+ String location = new
StringBuilder(FacebookConstants.AUTHENTICATION_ENDPOINT_URL).append("?").append(
+ createQueryString(params)).toString();
+ try
+ {
+ response.sendRedirect(location);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public URLConnection sendAccessTokenRequest(String returnUrl, String
authorizationCode, HttpServletResponse response)
+ {
+ String returnUri = getReturnUri(returnUrl);
+ String clientId = serviceProvider.getFacebookConfiguration().getClientId();
+ String clientSecret =
serviceProvider.getFacebookConfiguration().getClientSecret();
+
+ Map<String, String> params = new HashMap<String, String>();
+ params.put(OAuthConstants.REDIRECT_URI_PARAMETER, returnUri);
+ params.put(OAuthConstants.CLIENT_ID_PARAMETER, clientId);
+ params.put(OAuthConstants.CLIENT_SECRET_PARAMETER, clientSecret);
+ params.put(OAuthConstants.CODE_PARAMETER, authorizationCode);
+ String location = new
StringBuilder(FacebookConstants.ACCESS_TOKEN_ENDPOINT_URL).append("?").append(
+ createQueryString(params)).toString();
+
+ try
+ {
+ URL url = new URL(location);
+ URLConnection connection = url.openConnection();
+ return connection;
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private String getReturnUri(String returnUrl)
+ {
+ String serviceUrl =
serviceProvider.getServiceURL(ExternalAuthenticationService.FACEBOOK_SERVICE);
+ Map<String, String> params = new HashMap<String, String>();
+ params.put(ExternalAuthenticationFilter.RETURN_URL_PARAMETER, returnUrl);
+ return new
StringBuilder(serviceUrl).append("?").append(createQueryString(params)).toString();
+ }
+
+ private String createQueryString(Map<String, String> params)
+ {
+ StringBuilder queryString = new StringBuilder();
+ boolean first = true;
+ for (Map.Entry<String, String> entry : params.entrySet())
+ {
+ String paramName = entry.getKey();
+ String paramValue = entry.getValue();
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ queryString.append("&");
+ }
+ queryString.append(paramName).append("=");
+ String encodedParamValue;
+ try
+ {
+ encodedParamValue = URLEncoder.encode(paramValue, "UTF-8");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new RuntimeException(e);
+ }
+ queryString.append(encodedParamValue);
+ }
+ return queryString.toString();
+ }
+}
Property changes on:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookLoginSender.java
___________________________________________________________________
Name: svn
+ eol-style=native
Name: svn:keywords
+ Revision Author Date
Added:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookPrincipal.java
===================================================================
---
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookPrincipal.java
(rev 0)
+++
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookPrincipal.java 2010-09-26
21:20:08 UTC (rev 422)
@@ -0,0 +1,139 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.picketlink.identity.seam.federation;
+
+import java.security.Principal;
+
+/**
+* @author Marcel Kolsteren
+* @since Sep 26, 2010
+*/
+public class FacebookPrincipal implements Principal
+{
+ private String accessToken;
+
+ private String id;
+
+ private String name;
+
+ private String firstName;
+
+ private String lastName;
+
+ private String gender;
+
+ private String timezone;
+
+ private String locale;
+
+ private String email;
+
+ public String getAccessToken()
+ {
+ return accessToken;
+ }
+
+ public void setAccessToken(String accessToken)
+ {
+ this.accessToken = accessToken;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public void setId(String id)
+ {
+ this.id = id;
+ }
+
+ public String getFirstName()
+ {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName)
+ {
+ this.firstName = firstName;
+ }
+
+ public String getLastName()
+ {
+ return lastName;
+ }
+
+ public void setLastName(String lastName)
+ {
+ this.lastName = lastName;
+ }
+
+ public String getGender()
+ {
+ return gender;
+ }
+
+ public void setGender(String gender)
+ {
+ this.gender = gender;
+ }
+
+ public String getTimezone()
+ {
+ return timezone;
+ }
+
+ public void setTimezone(String timezone)
+ {
+ this.timezone = timezone;
+ }
+
+ public String getLocale()
+ {
+ return locale;
+ }
+
+ public void setLocale(String locale)
+ {
+ this.locale = locale;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getEmail()
+ {
+ return email;
+ }
+
+ public void setEmail(String email)
+ {
+ this.email = email;
+ }
+}
Property changes on:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/FacebookPrincipal.java
___________________________________________________________________
Name: svn
+ eol-style=native
Name: svn:keywords
+ Revision Author Date
Added:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/OAuthConstants.java
===================================================================
---
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/OAuthConstants.java
(rev 0)
+++
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/OAuthConstants.java 2010-09-26
21:20:08 UTC (rev 422)
@@ -0,0 +1,43 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.picketlink.identity.seam.federation;
+
+/**
+* @author Marcel Kolsteren
+* @since Sep 26, 2010
+*/
+public class OAuthConstants
+{
+ public static final String CODE_PARAMETER = "code";
+
+ public static final String CLIENT_ID_PARAMETER = "client_id";
+
+ public static final String CLIENT_SECRET_PARAMETER = "client_secret";
+
+ public static final String SCOPE_PARAMETER = "scope";
+
+ public static final String REDIRECT_URI_PARAMETER = "redirect_uri";
+
+ public static final String ACCESS_TOKEN_PARAMETER = "access_token";
+
+ public static final String ERROR_PARAMETER = "error";
+}
Property changes on:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/OAuthConstants.java
___________________________________________________________________
Name: svn
+ eol-style=native
Name: svn:keywords
+ Revision Author Date
Modified:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/PagesSupportingExternalAuthentication.java
===================================================================
---
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/PagesSupportingExternalAuthentication.java 2010-09-24
09:49:09 UTC (rev 421)
+++
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/PagesSupportingExternalAuthentication.java 2010-09-26
21:20:08 UTC (rev 422)
@@ -37,6 +37,7 @@
import org.jboss.seam.faces.FacesManager;
import org.jboss.seam.navigation.Pages;
import org.picketlink.identity.seam.federation.configuration.Configuration;
+import org.picketlink.identity.seam.federation.configuration.FacebookConfiguration;
import org.picketlink.identity.seam.federation.configuration.OpenIdConfiguration;
import org.picketlink.identity.seam.federation.configuration.SamlConfiguration;
import org.picketlink.identity.seam.federation.configuration.ServiceProvider;
@@ -63,11 +64,11 @@
.getRequest();
StringBuffer returnUrl = httpRequest.getRequestURL();
-
+
//PLFED-98: missing query parameters
String queryString = httpRequest.getQueryString();
- if( queryString != null && queryString.length() > 0 )
- returnUrl.append( "?" ).append( queryString );
+ if (queryString != null && queryString.length() > 0)
+ returnUrl.append("?").append(queryString);
ExternalAuthenticator externalAuthenticator = (ExternalAuthenticator) Component
.getInstance(ExternalAuthenticator.class);
@@ -91,14 +92,23 @@
}
else
{
- // Otherwise, redirect to the login view, so that the user can choose an IDP
- if (getLoginViewId() == null)
+ // Otherwise, use Facebook, if configured
+ FacebookConfiguration facebookConfiguration =
serviceProvider.getFacebookConfiguration();
+ if (facebookConfiguration != null)
{
- throw new RuntimeException("Login view id not specified in
pages.xml.");
+ externalAuthenticator.facebookLogin();
}
- Map<String, Object> parameters = new HashMap<String, Object>();
- parameters.put(ExternalAuthenticationFilter.RETURN_URL_PARAMETER,
returnUrl);
- FacesManager.instance().redirect(getLoginViewId(), parameters, false);
+ else
+ {
+ // Otherwise, redirect to the login view, so that the user can choose an
IDP
+ if (getLoginViewId() == null)
+ {
+ throw new RuntimeException("Login view id not specified in
pages.xml.");
+ }
+ Map<String, Object> parameters = new HashMap<String,
Object>();
+ parameters.put(ExternalAuthenticationFilter.RETURN_URL_PARAMETER,
returnUrl);
+ FacesManager.instance().redirect(getLoginViewId(), parameters, false);
+ }
}
}
}
Added:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/configuration/FacebookConfiguration.java
===================================================================
---
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/configuration/FacebookConfiguration.java
(rev 0)
+++
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/configuration/FacebookConfiguration.java 2010-09-26
21:20:08 UTC (rev 422)
@@ -0,0 +1,64 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.picketlink.identity.seam.federation.configuration;
+
+import org.picketlink.identity.seam.federation.jaxb.config.FacebookConfigType;
+
+/**
+* @author Marcel Kolsteren
+* @since Jan 28, 2010
+*/
+public class FacebookConfiguration
+{
+ private String clientId;
+
+ private String clientSecret;
+
+ private String scope;
+
+ public FacebookConfiguration(FacebookConfigType facebookConfiguration)
+ {
+ clientId = facebookConfiguration.getClientId();
+ clientSecret = facebookConfiguration.getClientSecret();
+ scope = facebookConfiguration.getScope();
+ }
+
+ public String getClientId()
+ {
+ return clientId;
+ }
+
+ public String getClientSecret()
+ {
+ return clientSecret;
+ }
+
+ public String getScope()
+ {
+ return scope;
+ }
+
+ public void setScope(String scope)
+ {
+ this.scope = scope;
+ }
+}
Property changes on:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/configuration/FacebookConfiguration.java
___________________________________________________________________
Name: svn
+ eol-style=native
Name: svn:keywords
+ Revision Author Date
Modified:
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/configuration/ServiceProvider.java
===================================================================
---
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/configuration/ServiceProvider.java 2010-09-24
09:49:09 UTC (rev 421)
+++
federation/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/configuration/ServiceProvider.java 2010-09-26
21:20:08 UTC (rev 422)
@@ -43,6 +43,8 @@
private OpenIdConfiguration openIdConfiguration;
+ private FacebookConfiguration facebookConfiguration;
+
private String hostname;
private String protocol;
@@ -96,6 +98,11 @@
{
openIdConfiguration = new
OpenIdConfiguration(serviceProvider.getOpenIdConfig());
}
+
+ if (serviceProvider.getFacebookConfig() != null)
+ {
+ facebookConfiguration = new
FacebookConfiguration(serviceProvider.getFacebookConfig());
+ }
}
public String getServiceURL(ExternalAuthenticationService service)
@@ -138,6 +145,11 @@
return openIdConfiguration;
}
+ public FacebookConfiguration getFacebookConfiguration()
+ {
+ return facebookConfiguration;
+ }
+
public String getHostname()
{
return hostname;
Modified:
federation/trunk/picketlink-seam/src/main/resources/schema/config/external-authentication-config.xsd
===================================================================
---
federation/trunk/picketlink-seam/src/main/resources/schema/config/external-authentication-config.xsd 2010-09-24
09:49:09 UTC (rev 421)
+++
federation/trunk/picketlink-seam/src/main/resources/schema/config/external-authentication-config.xsd 2010-09-26
21:20:08 UTC (rev 422)
@@ -26,6 +26,8 @@
minOccurs="0" />
<element name="OpenIdConfig" type="tns:OpenIdConfigType"
minOccurs="0" />
+ <element name="FacebookConfig" type="tns:FacebookConfigType"
+ minOccurs="0" />
</sequence>
<attribute name="protocol" type="tns:ProtocolTypes"
use="optional"
default="https">
@@ -155,6 +157,31 @@
</annotation>
</attribute>
</complexType>
+ <complexType name="FacebookConfigType">
+ <annotation>
+ <documentation>
+ Configuration for Facebook.
+ </documentation>
+ </annotation>
+ <attribute name="clientId" type="string"
use="required">
+ <annotation>
+ <documentation>Client application id.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="clientSecret" type="string"
use="required">
+ <annotation>
+ <documentation>Client application secret.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="scope" type="string"
use="optional">
+ <annotation>
+ <documentation>Space separated list of requested permissions.
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
<complexType name="OpenIdAttributeType">
<annotation>
<documentation>
Modified:
federation/trunk/picketlink-webapps/seam-sp/src/main/resources/external-authentication-config.xml
===================================================================
---
federation/trunk/picketlink-webapps/seam-sp/src/main/resources/external-authentication-config.xml 2010-09-24
09:49:09 UTC (rev 421)
+++
federation/trunk/picketlink-webapps/seam-sp/src/main/resources/external-authentication-config.xml 2010-09-26
21:20:08 UTC (rev 422)
@@ -11,8 +11,8 @@
failedAuthenticationUrl="http://localhost:8080/seam-sp/FailedAuthenticationPage.seam"
internalAuthenticationMethod="#{authenticator.internalAuthenticate}">
<SamlConfig serviceProviderEntityId="http://localhost:8080/seam-sp"
- keyStoreUrl="classpath:/picketlink_test_keystore.jks"
- keyStorePass="store456" signingKeyAlias="servercert"
signingKeyPass="pass456">
+ keyStoreUrl="classpath:/picketlink_test_keystore.jks"
keyStorePass="store456"
+ signingKeyAlias="servercert" signingKeyPass="pass456">
<SamlIdentityProvider entityId="http://idp.ssocircle.com" />
<SamlIdentityProvider entityId="http://localhost:8888/opensso" />
</SamlConfig>
@@ -51,4 +51,12 @@
internalAuthenticationMethod="#{authenticator.internalAuthenticate}">
<OpenIdConfig
defaultOpenIdProvider="https://www.google.com/accounts/o8/id" />
</ServiceProvider>
+ <ServiceProvider protocol="http"
hostname="facebook.picketlink.org"
+ unsolicitedAuthenticationUrl="http://facebook.picketlink.org:8080/seam-sp/PublicPage.seam"
+ loggedOutUrl="http://facebook.picketlink.org:8080/seam-sp/PublicPage.seam"
+ failedAuthenticationUrl="http://facebook.picketlink.org:8080/seam-sp/FailedAuthenticationPage.seam"
+ internalAuthenticationMethod="#{authenticator.internalAuthenticate}">
+ <FacebookConfig clientId="156872394341240"
+ clientSecret="7b6919b80e544f0faf2ee05875f48f46" scope="email
publish_stream"/>
+ </ServiceProvider>
</ExternalAuthenticationConfig>
Modified: federation/trunk/picketlink-webapps/seam-sp/src/main/webapp/Login.xhtml
===================================================================
--- federation/trunk/picketlink-webapps/seam-sp/src/main/webapp/Login.xhtml 2010-09-24
09:49:09 UTC (rev 421)
+++ federation/trunk/picketlink-webapps/seam-sp/src/main/webapp/Login.xhtml 2010-09-26
21:20:08 UTC (rev 422)
@@ -1,49 +1,65 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:c="http://java.sun.com/jstl/core"
xmlns:f="http://java.sun.com/jsf/core">
<body>
<h:messages />
<h1>Identity provider selection</h1>
-<h2>SAML</h2>
-<p>Choose one of the following identity providers to sign on:</p>
-<h:form>
- <h:dataTable
- value="#{configuration.serviceProvider.samlConfiguration.identityProviders}"
- var="identityProvider">
- <h:column>
- <h:outputText value="#{identityProvider.entityId}" />
- </h:column>
- <h:column>
- <h:commandLink
- action="#{externalAuthenticator.samlSignOn(identityProvider.entityId)}"
- value="Login" />
- </h:column>
- </h:dataTable>
-</h:form>
-<h2>OpenID</h2>
-<h:form>
- <p>Choose your OpenID provider (using "directed identity"): <ul>
- <li><h:commandLink
-
action="#{externalAuthenticator.openIdSignOn('https://www.google...
- value="Google" /> </li>
- <li><h:commandLink
- action="#{externalAuthenticator.openIdSignOn('https://me.yahoo.com')}"
- value="Yahoo" /> </li>
- <li><h:commandLink
- action="#{externalAuthenticator.openIdSignOn('https://myopenid.com')}"
- value="myOpenID" /> </li>
- <li><h:commandLink
- action="#{externalAuthenticator.openIdSignOn('http://myspace.com')}"
- value="MySpace" /> </li>
- </ul></p>
-</h:form>
-<h:form>
- <p>Or use your OpenID URL: <h:inputText
- value="#{externalAuthenticator.openId}" required="true"
/> <h:commandLink
- action="#{externalAuthenticator.openIdSignOn}" value="Sign On"
/></p>
-</h:form>
+<c:if
+ test="#{configuration.serviceProvider.samlConfiguration != null}">
+ <h2>SAML</h2>
+ <p>Choose one of the following identity providers to sign on:</p>
+ <h:form>
+ <h:dataTable
+ value="#{configuration.serviceProvider.samlConfiguration.identityProviders}"
+ var="identityProvider">
+ <h:column>
+ <h:outputText value="#{identityProvider.entityId}" />
+ </h:column>
+ <h:column>
+ <h:commandLink
+ action="#{externalAuthenticator.samlSignOn(identityProvider.entityId)}"
+ value="Login" />
+ </h:column>
+ </h:dataTable>
+ </h:form>
+</c:if>
+<c:if
+ test="#{configuration.serviceProvider.openIdConfiguration != null}">
+ <h2>OpenID</h2>
+ <h:form>
+ <p>Choose your OpenID provider (using "directed identity"): <ul>
+ <li><h:commandLink
+
action="#{externalAuthenticator.openIdSignOn('https://www.google...
+ value="Google" /> </li>
+ <li><h:commandLink
+ action="#{externalAuthenticator.openIdSignOn('https://me.yahoo.com')}"
+ value="Yahoo" /> </li>
+ <li><h:commandLink
+ action="#{externalAuthenticator.openIdSignOn('https://myopenid.com')}"
+ value="myOpenID" /> </li>
+ <li><h:commandLink
+ action="#{externalAuthenticator.openIdSignOn('http://myspace.com')}"
+ value="MySpace" /> </li>
+ </ul></p>
+ </h:form>
+ <h:form>
+ <p>Or use your OpenID URL: <h:inputText
+ value="#{externalAuthenticator.openId}" required="true"
/> <h:commandLink
+ action="#{externalAuthenticator.openIdSignOn}" value="Sign On"
/></p>
+ </h:form>
+</c:if>
+<c:if
+ test="#{configuration.serviceProvider.facebookConfiguration != null}">
+ <h2>Facebook</h2>
+ <h:form>
+ <h:commandLink action="#{externalAuthenticator.facebookLogin}">
+ <h:graphicImage value="/images/login_with_facebook.png" />
+ </h:commandLink>
+ </h:form>
+</c:if>
</body>
</html>
\ No newline at end of file
Modified:
federation/trunk/picketlink-webapps/seam-sp/src/main/webapp/PrincipalInfoFragment.xhtml
===================================================================
---
federation/trunk/picketlink-webapps/seam-sp/src/main/webapp/PrincipalInfoFragment.xhtml 2010-09-24
09:49:09 UTC (rev 421)
+++
federation/trunk/picketlink-webapps/seam-sp/src/main/webapp/PrincipalInfoFragment.xhtml 2010-09-26
21:20:08 UTC (rev 422)
@@ -4,11 +4,14 @@
xmlns:c="http://java.sun.com/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
+ <head>
+ <link type="text/css" rel="stylesheet"
href="styles.css" />
+ </head>
<c:choose>
<c:when
test="#{identity.principal.getClass().getSimpleName() ==
'SeamSamlPrincipal'}">
- <h2>Logged on via SAML</h2>
- <h:panelGrid columns="2">
+ <h2>Logged on with SAML</h2>
+ <h:panelGrid columns="2" columnClasses="propertyName,
propertyValue">
<h:outputText value="NameID" />
<h:outputText value="#{identity.principal.nameId.value}" />
<h:outputText value="NameID format" />
@@ -41,9 +44,10 @@
<p><h:commandLink action="#{externalAuthenticator.singleLogout}"
value="Single logout" /></p>
</c:when>
- <c:otherwise>
- <h2>Logged on via OpenID</h2>
- <h:panelGrid columns="2">
+ <c:when
+ test="#{identity.principal.getClass().getSimpleName() ==
'OpenIdPrincipal'}">
+ <h2>Logged on with OpenID</h2>
+ <h:panelGrid columns="2" columnClasses="propertyName,
propertyValue">
<h:outputText value="Identifier" />
<h:outputText value="#{identity.principal.identifier}" />
<h:outputText value="Provider" />
@@ -61,6 +65,29 @@
</ul>
</h:panelGroup>
</h:panelGrid>
+ </c:when>
+ <c:otherwise>
+ <h2>Logged on with Facebook</h2>
+ <h:panelGrid columns="2" columnClasses="propertyName,
propertyValue">
+ <h:outputText value="Access token" />
+ <h:outputText value="#{identity.principal.accessToken}" />
+ <h:outputText value="ID" />
+ <h:outputText value="#{identity.principal.id}" />
+ <h:outputText value="Name" />
+ <h:outputText value="#{identity.principal.name}" />
+ <h:outputText value="First name" />
+ <h:outputText value="#{identity.principal.firstName}" />
+ <h:outputText value="Last name" />
+ <h:outputText value="#{identity.principal.lastName}" />
+ <h:outputText value="Email" />
+ <h:outputText value="#{identity.principal.email}" />
+ <h:outputText value="Gender" />
+ <h:outputText value="#{identity.principal.gender}" />
+ <h:outputText value="Timezone" />
+ <h:outputText value="#{identity.principal.timezone}" />
+ <h:outputText value="Locale" />
+ <h:outputText value="#{identity.principal.locale}" />
+ </h:panelGrid>
</c:otherwise>
</c:choose>
<p><h:commandLink action="#{authenticator.localLogout}"
Added:
federation/trunk/picketlink-webapps/seam-sp/src/main/webapp/images/login_with_facebook.png
===================================================================
(Binary files differ)
Property changes on:
federation/trunk/picketlink-webapps/seam-sp/src/main/webapp/images/login_with_facebook.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: federation/trunk/picketlink-webapps/seam-sp/src/main/webapp/styles.css
===================================================================
--- federation/trunk/picketlink-webapps/seam-sp/src/main/webapp/styles.css
(rev 0)
+++ federation/trunk/picketlink-webapps/seam-sp/src/main/webapp/styles.css 2010-09-26
21:20:08 UTC (rev 422)
@@ -0,0 +1,9 @@
+.propertyName {
+ padding: 5px;
+ background-color: #aaaaaa;
+}
+
+.propertyValue {
+ padding: 5px;
+ background-color: #dddddd;
+}
\ No newline at end of file