Commits

Joeri Sykora committed c8341ad

use jsf as well

Comments (0)

Files changed (11)

oauthconsumer/nb-configuration.xml

 Any value defined here will override the pom.xml file value but is only applicable to the current project.
 -->
         <netbeans.compile.on.save>all</netbeans.compile.on.save>
+        <org-netbeans-modules-projectapi.jsf_2e_language>Facelets</org-netbeans-modules-projectapi.jsf_2e_language>
+        <org-netbeans-modules-maven-jaxws.rest_2e_config_2e_type>user</org-netbeans-modules-maven-jaxws.rest_2e_config_2e_type>
     </properties>
 </project-shared-configuration>

oauthconsumer/src/main/java/com/mycompany/oauthconsumer/HomeHandler.java

 
 @Path("home")
 public class HomeHandler {
-	private static final String PROVIDER_URL = "http://localhost:8080/oauthprovider/rest";
-	private static final String CONSUMER_KEY = "b71519bcbda2fe74";
-	private static final String CONSUMER_SECRET = "fa65941c9ccdff6f";
+	private static final String PROVIDER_URL = "http://localhost:8080/oauthprovider";
+	private static final String CONSUMER_KEY = "72d0d4cf36a16b8e";
+	private static final String CONSUMER_SECRET = "2c0625282b3268a8";
 	private static final String CONSUMER_CALLBACK = "http://localhost:8080/oauthconsumer/rest/home/callback";
 
 	@Context

oauthconsumer/src/main/java/com/mycompany/oauthconsumer/view/Callback.java

+package com.mycompany.oauthconsumer.view;
+
+import com.lodgon.dali.core.social.DaliCoreExternalNetwork;
+import javax.annotation.PostConstruct;
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.ManagedProperty;
+import javax.faces.bean.RequestScoped;
+
+/**
+ *
+ * @author joeri
+ */
+@ManagedBean
+@RequestScoped
+public class Callback {
+	private static final String PROVIDER_URL = "http://localhost:8080/oauthprovider";
+	private static final String CONSUMER_KEY = "72d0d4cf36a16b8e";
+	private static final String CONSUMER_SECRET = "2c0625282b3268a8";
+
+	@ManagedProperty(value = "#{param.oauth_token}")
+	private String requestToken;
+	@ManagedProperty(value = "#{param.verifier}")
+	private String verifier;
+
+
+	public String getRequestToken() {
+		return requestToken;
+	}
+
+	public void setRequestToken(String requestToken) {
+		this.requestToken = requestToken;
+	}
+
+	public String getVerifier() {
+		return verifier;
+	}
+
+	public void setVerifier(String verifier) {
+		this.verifier = verifier;
+	}
+
+	@ManagedProperty(value = "#{home}")
+	private Home home;
+
+	public Home getHome() {
+		return home;
+	}
+
+	public void setHome(Home home) {
+		this.home = home;
+	}
+
+	public String home() {
+		return "/pages/home";
+	}
+
+	@PostConstruct
+	public void postConstruct() {
+		DaliCoreExternalNetwork externalNetwork = new DaliCoreExternalNetwork(PROVIDER_URL,
+						CONSUMER_KEY, CONSUMER_SECRET);
+		home.setAccessToken(externalNetwork.callback(requestToken, verifier));
+	}
+}

oauthconsumer/src/main/java/com/mycompany/oauthconsumer/view/Home.java

+package com.mycompany.oauthconsumer.view;
+
+import com.lodgon.dali.core.social.DaliCoreExternalNetwork;
+import com.lodgon.dali.core.social.entity.ExternalToken;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.SessionScoped;
+import javax.faces.context.FacesContext;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+/**
+ *
+ * @author joeri
+ */
+@ManagedBean
+@SessionScoped
+public class Home {
+	private static final String PROVIDER_URL = "http://localhost:8080/oauthprovider";
+	private static final String CONSUMER_KEY = "72d0d4cf36a16b8e";
+	private static final String CONSUMER_SECRET = "2c0625282b3268a8";
+	private static final String CONSUMER_CALLBACK = "http://localhost:8080/oauthconsumer/pages/callback.faces";
+
+	private ExternalToken accessToken;
+
+	public ExternalToken getAccessToken() {
+		return accessToken;
+	}
+
+	public void setAccessToken(ExternalToken accessToken) {
+		this.accessToken = accessToken;
+	}
+
+	public String authorize() throws IOException {
+		if (accessToken != null) {
+			return "/pages/home";
+		}
+
+		DaliCoreExternalNetwork externalNetwork = new DaliCoreExternalNetwork(PROVIDER_URL,
+							CONSUMER_KEY, CONSUMER_SECRET);
+
+		try {
+			Response response = externalNetwork.connect(CONSUMER_CALLBACK);
+			String location = response.getMetadata().getFirst("Location").toString();
+
+			FacesContext.getCurrentInstance().getExternalContext().redirect(location);
+		} catch (WebApplicationException ex) {
+			Logger.getLogger(Home.class.getName()).log(Level.SEVERE, "Connect failed: " + ex.getResponse().getStatus(), ex);
+		}
+
+		return "/pages";
+	}
+}

oauthconsumer/src/main/resources/META-INF/persistence.xml

     <class>com.lodgon.dali.core.entity.TypePermission</class>
     <class>com.lodgon.dali.core.entity.User</class>
     <class>com.lodgon.dali.core.entity.UserPermission</class>
-    <class>com.lodgon.dali.core.externalnetwork.entity.ExternalToken</class>
-    <class>com.lodgon.dali.core.externalnetwork.entity.OnlineAccount</class>
+    <class>com.lodgon.dali.core.social.entity.ExternalToken</class>
+    <class>com.lodgon.dali.core.social.entity.OnlineAccount</class>
     <exclude-unlisted-classes>false</exclude-unlisted-classes>
     <properties>
       <property name="eclipselink.ddl-generation" value="create-tables"/>

oauthconsumer/src/main/webapp/WEB-INF/faces-config.xml

+<?xml version='1.0' encoding='UTF-8'?>
+
+<!-- =========== FULL CONFIGURATION FILE ================================== -->
+
+<faces-config version="2.0"
+    xmlns="http://java.sun.com/xml/ns/javaee" 
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
+
+
+</faces-config>

oauthconsumer/src/main/webapp/WEB-INF/web.xml

 <?xml version="1.0" encoding="UTF-8"?>
+
 <web-app xmlns="http://java.sun.com/xml/ns/javaee"
 				 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 				 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
 				 version="3.0">
+	<context-param>
+		<param-name>javax.faces.PROJECT_STAGE</param-name>
+		<param-value>Development</param-value>
+	</context-param>
+
 	<servlet>
-		<servlet-name>jerseyservlet</servlet-name>
-		<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
+			<servlet-name>Faces Servlet</servlet-name>
+			<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+			<load-on-startup>1</load-on-startup>
 	</servlet>
 
 	<servlet-mapping>
-		<servlet-name>jerseyservlet</servlet-name>
-		<url-pattern>/rest/*</url-pattern>
+			<servlet-name>Faces Servlet</servlet-name>
+			<url-pattern>/faces/*</url-pattern>
+			<url-pattern>*.faces</url-pattern>
 	</servlet-mapping>
+
 	<session-config>
 		<session-timeout>
 			30
 		</session-timeout>
 	</session-config>
+
+	<welcome-file-list>
+		<welcome-file>index.jsp</welcome-file>
+	</welcome-file-list>
 </web-app>

oauthconsumer/src/main/webapp/home.jsp

-<%@page contentType="text/html" pageEncoding="UTF-8"%>
-<!DOCTYPE html>
-<html>
-	<head>
-		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-		<title>dalicore-oauth service provider</title>
-	</head>
-	<body>
-		<h1>Connected!</h1>
-
-		<p>You successfully connected with the external network ${it.network}.</p>
-
-		Access Token key: ${it.token}<br/>
-		Access Token secret: ${it.secret}
-	</body>
-</html>

oauthconsumer/src/main/webapp/index.jsp

+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@page contentType="text/html" pageEncoding="UTF-8"%>
+<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+
+<c:redirect url="pages/home.faces"/>

oauthconsumer/src/main/webapp/pages/callback.xhtml

+<?xml version='1.0' encoding='UTF-8' ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+			xmlns:f="http://java.sun.com/jsf/core"
+      xmlns:h="http://java.sun.com/jsf/html">
+	<h:head>
+		<title>dalicore-oauth service provider</title>
+	</h:head>
+	<h:body>
+		<f:metadata>
+			<f:event type="preRenderView" listener="#{callback.home()}"/>
+		</f:metadata>
+	</h:body>
+</html>

oauthconsumer/src/main/webapp/pages/home.xhtml

+<?xml version='1.0' encoding='UTF-8' ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+			xmlns:c="http://java.sun.com/jsp/jstl/core"
+			xmlns:f="http://java.sun.com/jsf/core"
+      xmlns:h="http://java.sun.com/jsf/html">
+	<h:head>
+		<title>dalicore-oauth service provider</title>
+	</h:head>
+	<h:body>
+		<c:if test="${empty home.accessToken}">
+			<f:metadata>
+				<f:event type="preRenderView" listener="#{home.authorize()}"/>
+			</f:metadata>
+		</c:if>
+		<c:if test="${not empty home.accessToken}">
+			<h1>Connected!</h1>
+
+			<p>You successfully connected with the external network ${home.accessToken.network}.</p>
+
+			Access Token key: ${home.accessToken.token}<br/>
+			Access Token secret: ${home.accessToken.secret}
+		</c:if>
+	</h:body>
+</html>