Author: jsdelfino
Date: Sun Jun 27 00:47:05 2010
New Revision: 958305

URL: http://svn.apache.org/viewvc?rev=958305&view=rev
Log:
Add support for user and email component properties, and minimal support for 
sign in using OpenID.

Added:
    tuscany/sca-cpp/trunk/modules/openid/
    tuscany/sca-cpp/trunk/modules/openid/Makefile.am
      - copied, changed from r958158, tuscany/sca-cpp/trunk/modules/Makefile.am
    tuscany/sca-cpp/trunk/modules/openid/htdocs/
    tuscany/sca-cpp/trunk/modules/openid/htdocs/index.html
    tuscany/sca-cpp/trunk/modules/openid/htdocs/login/
    tuscany/sca-cpp/trunk/modules/openid/htdocs/login/index.html
    tuscany/sca-cpp/trunk/modules/openid/htdocs/protected/
    tuscany/sca-cpp/trunk/modules/openid/htdocs/protected/index.html
    tuscany/sca-cpp/trunk/modules/openid/openid-conf   (with props)
    tuscany/sca-cpp/trunk/modules/openid/openid.composite
    tuscany/sca-cpp/trunk/modules/openid/server-test   (contents, props changed)
      - copied, changed from r958158, tuscany/sca-cpp/trunk/modules/Makefile.am
    tuscany/sca-cpp/trunk/modules/openid/server-test.scm
Modified:
    tuscany/sca-cpp/trunk/configure.ac
    tuscany/sca-cpp/trunk/modules/Makefile.am
    tuscany/sca-cpp/trunk/modules/http/httpd-conf
    tuscany/sca-cpp/trunk/modules/http/httpd.hpp
    tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp

Modified: tuscany/sca-cpp/trunk/configure.ac
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/configure.ac?rev=958305&r1=958304&r2=958305&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/configure.ac (original)
+++ tuscany/sca-cpp/trunk/configure.ac Sun Jun 27 00:47:05 2010
@@ -475,6 +475,39 @@ else
 fi
 AC_SUBST(JAVA_LDFLAGS)
 
+# Enable support for OpenID.
+AC_MSG_CHECKING([whether to enable OpenID support])
+AC_ARG_ENABLE(openid, [AS_HELP_STRING([--enable-openid], [enable OpenID 
support [default=no]])],
+[ case "${enableval}" in
+  no)
+    AC_MSG_RESULT(no)
+    ;;
+  *)
+    AC_MSG_RESULT(yes)
+    want_openid=true
+    ;;
+  esac ],
+[ AC_MSG_RESULT(no)])
+if test "${want_openid}" = "true"; then
+
+  # Configure path to mod-auth-openid
+  AC_MSG_CHECKING([for mod-auth-openid])
+  AC_ARG_WITH([mod-auth-openid], 
[AC_HELP_STRING([--with-mod-auth-openid=PATH], [path to installed 
mod-auth-openid [default=/usr]])], [
+    MODAUTHOPENID_PREFIX="${withval}"
+    AC_MSG_RESULT("${withval}")
+  ], [
+    MODAUTHOPENID_PREFIX="/usr/local/"
+    AC_MSG_RESULT(/usr/local)
+  ])
+  AC_SUBST(MODAUTHOPENID_PREFIX)
+
+  AM_CONDITIONAL([WANT_OPENID], true)
+  AC_DEFINE([WANT_OPENID], 1, [enable OpenID support])
+
+else
+  AM_CONDITIONAL([WANT_OPENID], false)
+fi
+
 # Enable support for Google AppEngine.
 AC_MSG_CHECKING([whether to enable Google AppEngine support])
 AC_ARG_ENABLE(gae, [AS_HELP_STRING([--enable-gae], [enable Google AppEngine 
support [default=no]])],
@@ -801,13 +834,14 @@ AC_CONFIG_FILES([Makefile
                  modules/Makefile
                  modules/scheme/Makefile
                  modules/atom/Makefile
+                 modules/rss/Makefile
                  modules/json/Makefile
                  modules/scdl/Makefile
                  modules/http/Makefile
+                 modules/server/Makefile
                  modules/python/Makefile
                  modules/java/Makefile
-                 modules/rss/Makefile
-                 modules/server/Makefile
+                 modules/openid/Makefile
                  modules/wsgi/Makefile
                  components/Makefile
                  components/cache/Makefile

Modified: tuscany/sca-cpp/trunk/modules/Makefile.am
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/Makefile.am?rev=958305&r1=958304&r2=958305&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/modules/Makefile.am Sun Jun 27 00:47:05 2010
@@ -15,5 +15,5 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-SUBDIRS = scheme atom rss json scdl http rss server python wsgi java
+SUBDIRS = scheme atom rss json scdl http server python java openid wsgi
 

Modified: tuscany/sca-cpp/trunk/modules/http/httpd-conf
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/httpd-conf?rev=958305&r1=958304&r2=958305&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/httpd-conf (original)
+++ tuscany/sca-cpp/trunk/modules/http/httpd-conf Sun Jun 27 00:47:05 2010
@@ -57,6 +57,7 @@ LoadModule asis_module ${modules_prefix}
 LoadModule negotiation_module ${modules_prefix}/modules/mod_negotiation.so
 LoadModule dir_module ${modules_prefix}/modules/mod_dir.so
 LoadModule rewrite_module ${modules_prefix}/modules/mod_rewrite.so
+LoadModule setenvif_module ${modules_prefix}/modules/mod_setenvif.so
 <IfModule !log_config_module>
 LoadModule log_config_module ${modules_prefix}/modules/mod_log_config.so
 </IfModule>

Modified: tuscany/sca-cpp/trunk/modules/http/httpd.hpp
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/httpd.hpp?rev=958305&r1=958304&r2=958305&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/httpd.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/http/httpd.hpp Sun Jun 27 00:47:05 2010
@@ -97,8 +97,19 @@ int debugHeader(unused void* r, const ch
     return 1;
 }
 
+int debugEnv(unused void* r, const char* key, const char* value) {
+    cerr << "  var key: " << key << ", value: " << value << endl;
+    return 1;
+}
+
+int debugNote(unused void* r, const char* key, const char* value) {
+    cerr << "  note key: " << key << ", value: " << value << endl;
+    return 1;
+}
+
 const bool debugRequest(request_rec* r, const string& msg) {
     cerr << msg << ":" << endl;
+    cerr << "  server: " << optional(r->server->server_hostname) << endl;
     cerr << "  protocol: " << optional(r->protocol) << endl;
     cerr << "  method: " << optional(r->method) << endl;
     cerr << "  method number: " << r->method_number << endl;
@@ -111,6 +122,10 @@ const bool debugRequest(request_rec* r, 
     cerr << "  filename: " << optional(r->filename) << endl;
     cerr << "  uri tokens: " << pathTokens(r->uri) << endl;
     cerr << "  args: " << optional(r->args) << endl;
+    cerr << "  user: " << optional(r->user) << endl;
+    cerr << "  auth type: " << optional(r->ap_auth_type) << endl;
+    apr_table_do(debugEnv, r, r->subprocess_env, NULL);
+    apr_table_do(debugEnv, r, r->notes, NULL);
     return true;
 }
 
@@ -331,6 +346,7 @@ const failable<request_rec*, int> intern
     nr->no_local_copy = r->no_local_copy;
     nr->read_length = r->read_length;
     nr->vlist_validator = r->vlist_validator;
+    nr->user = r->user;
 
     // Setup input and output filters
     nr->proto_output_filters  = r->proto_output_filters;

Copied: tuscany/sca-cpp/trunk/modules/openid/Makefile.am (from r958158, 
tuscany/sca-cpp/trunk/modules/Makefile.am)
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/openid/Makefile.am?p2=tuscany/sca-cpp/trunk/modules/openid/Makefile.am&p1=tuscany/sca-cpp/trunk/modules/Makefile.am&r1=958158&r2=958305&rev=958305&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/modules/openid/Makefile.am Sun Jun 27 00:47:05 2010
@@ -15,5 +15,18 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-SUBDIRS = scheme atom rss json scdl http rss server python wsgi java
 
+if WANT_OPENID
+
+dist_mod_SCRIPTS = openid-conf
+moddir = $(prefix)/modules/openid
+
+mod_DATA = openid.prefix
+openid.prefix: $(top_builddir)/config.status
+       echo ${MODAUTHOPENID_PREFIX} >openid.prefix
+
+EXTRA_DIST = openid.composite server-test.scm htdocs/index.html 
htdocs/login.html htdocs/protected/index.html
+
+dist_noinst_SCRIPTS = server-test
+
+endif

Added: tuscany/sca-cpp/trunk/modules/openid/htdocs/index.html
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/openid/htdocs/index.html?rev=958305&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/modules/openid/htdocs/index.html (added)
+++ tuscany/sca-cpp/trunk/modules/openid/htdocs/index.html Sun Jun 27 00:47:05 
2010
@@ -0,0 +1,21 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+   
+     http://www.apache.org/licenses/LICENSE-2.0
+     
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License.
+-->
+
+<html><body><h1>Unprotected area - It works!</h1></body></html>
+

Added: tuscany/sca-cpp/trunk/modules/openid/htdocs/login/index.html
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/openid/htdocs/login/index.html?rev=958305&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/modules/openid/htdocs/login/index.html (added)
+++ tuscany/sca-cpp/trunk/modules/openid/htdocs/login/index.html Sun Jun 27 
00:47:05 2010
@@ -0,0 +1,38 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+   
+     http://www.apache.org/licenses/LICENSE-2.0
+     
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License.
+-->
+
+<html><body>
+<h1>Sign in using an OpenID provider</h1>
+<form action="/protected" method="GET">
+<input type="hidden" name="openid_identifier" 
value="https://www.google.com/accounts/o8/id"/>
+<input type="submit" value="Sign in with your Google account"/>
+</form>
+<form action="/protected" method="GET">
+<input type="hidden" name="openid_identifier" value="https://me.yahoo.com/"/>
+<input type="submit" value="Sign in with your Yahoo account"/>
+</form>
+<form action="/protected" method="GET">
+<input type="hidden" name="openid_identifier" value="https://me.myopenid.com"/>
+<input type="submit" value="Sign in with your MyOpenID account"/>
+</form>
+<form action="/protected" method="GET">
+<input type="hidden" name="openid_identifier" 
value="https://pip.verisignlabs.com/"/>
+<input type="submit" value="Sign in with your Verisign account"/>
+</form>
+</body></html>

Added: tuscany/sca-cpp/trunk/modules/openid/htdocs/protected/index.html
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/openid/htdocs/protected/index.html?rev=958305&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/modules/openid/htdocs/protected/index.html (added)
+++ tuscany/sca-cpp/trunk/modules/openid/htdocs/protected/index.html Sun Jun 27 
00:47:05 2010
@@ -0,0 +1,21 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+   
+     http://www.apache.org/licenses/LICENSE-2.0
+     
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License.
+-->
+
+<html><body><h1>Protected area - It works!</h1></body></html>
+

Added: tuscany/sca-cpp/trunk/modules/openid/openid-conf
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/openid/openid-conf?rev=958305&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/modules/openid/openid-conf (added)
+++ tuscany/sca-cpp/trunk/modules/openid/openid-conf Sun Jun 27 00:47:05 2010
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#  
+#    http://www.apache.org/licenses/LICENSE-2.0
+#    
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+
+# Generate an Axis2 server conf
+here=`readlink -f $0`; here=`dirname $here`
+root=`readlink -f $1`
+htdocs=`readlink -f $2`
+openid_prefix=`cat openid.prefix`
+
+# Configure HTTPD mod_auth_openid module
+cat >>$root/conf/httpd.conf <<EOF
+# Support for OpenID authentication
+LoadModule authopenid_module  $openid_prefix/modules/mod_auth_openid.so
+
+<Location /protected>
+AuthOpenIDEnabled On
+AuthOpenIDLoginPage /login
+AuthOpenIDAXAdd EMAIL http://axschema.org/contact/email
+</Location>
+
+<Location /login>
+AuthOpenIDEnabled Off
+</Location>
+
+EOF

Propchange: tuscany/sca-cpp/trunk/modules/openid/openid-conf
------------------------------------------------------------------------------
    svn:executable = *

Added: tuscany/sca-cpp/trunk/modules/openid/openid.composite
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/openid/openid.composite?rev=958305&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/modules/openid/openid.composite (added)
+++ tuscany/sca-cpp/trunk/modules/openid/openid.composite Sun Jun 27 00:47:05 
2010
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912";
+  xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1";
+  targetNamespace="http://tuscany.apache.org/xmlns/sca/components";
+  name="openid">
+        
+    <component name="hello">
+        <t:implementation.scheme script="server-test.scm"/>
+        <service name="hello">
+            <t:binding.jsonrpc uri="protected/hello"/>
+        </service>
+        <property name="user">nobody</property>
+        <property name="email">[email protected]</property>
+    </component>     
+
+</composite>

Copied: tuscany/sca-cpp/trunk/modules/openid/server-test (from r958158, 
tuscany/sca-cpp/trunk/modules/Makefile.am)
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/openid/server-test?p2=tuscany/sca-cpp/trunk/modules/openid/server-test&p1=tuscany/sca-cpp/trunk/modules/Makefile.am&r1=958158&r2=958305&rev=958305&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/modules/openid/server-test Sun Jun 27 00:47:05 2010
@@ -1,3 +1,5 @@
+#!/bin/sh
+
 #  Licensed to the Apache Software Foundation (ASF) under one
 #  or more contributor license agreements.  See the NOTICE file
 #  distributed with this work for additional information
@@ -15,5 +17,24 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-SUBDIRS = scheme atom rss json scdl http rss server python wsgi java
+# Setup
+../../modules/http/httpd-conf tmp localhost 8090 htdocs
+../../modules/server/server-conf tmp
+../../modules/server/scheme-conf tmp
+./openid-conf tmp htdocs
+cat >>tmp/conf/httpd.conf <<EOF
+SCAContribution `pwd`/
+SCAComposite openid.composite
+EOF
+
+../../modules/http/httpd-start tmp
+sleep 2
+
+# Test
+#./client-test 2>/dev/null
+rc=$?
 
+# Cleanup
+#../../modules/http/httpd-stop tmp
+#sleep 2
+return $rc

Propchange: tuscany/sca-cpp/trunk/modules/openid/server-test
------------------------------------------------------------------------------
    svn:executable = *

Added: tuscany/sca-cpp/trunk/modules/openid/server-test.scm
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/openid/server-test.scm?rev=958305&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/modules/openid/server-test.scm (added)
+++ tuscany/sca-cpp/trunk/modules/openid/server-test.scm Sun Jun 27 00:47:05 
2010
@@ -0,0 +1,21 @@
+;  Licensed to the Apache Software Foundation (ASF) under one
+;  or more contributor license agreements.  See the NOTICE file
+;  distributed with this work for additional information
+;  regarding copyright ownership.  The ASF licenses this file
+;  to you under the Apache License, Version 2.0 (the
+;  "License"); you may not use this file except in compliance
+;  with the License.  You may obtain a copy of the License at
+;  
+;    http://www.apache.org/licenses/LICENSE-2.0
+;    
+;  Unless required by applicable law or agreed to in writing,
+;  software distributed under the License is distributed on an
+;  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+;  KIND, either express or implied.  See the License for the
+;  specific language governing permissions and limitations
+;  under the License.
+
+; OpenID support test case
+
+(define (get id user email) (list "text/html" (list "<html><body><p>Hello " 
(user) ", " (email) "</p></body></html>")))
+

Modified: tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp?rev=958305&r1=958304&r2=958305&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp Sun Jun 27 00:47:05 2010
@@ -234,7 +234,6 @@ const failable<int> del(request_rec* r, 
  * Translate a component request.
  */
 int translate(request_rec *r) {
-    gc_scoped_pool pool(r->pool);
     if (strncmp(r->uri, "/components/", 12) != 0)
         return DECLINED;
     r->handler = "mod_tuscany_eval";
@@ -242,12 +241,32 @@ int translate(request_rec *r) {
 }
 
 /**
+ * Store current HTTP request for access from property lambda functions.
+ */
+#ifdef WANT_THREADS
+__thread
+#endif
+const request_rec* currentRequest = NULL;
+
+class scoped_request {
+public:
+    scoped_request(const request_rec* r) {
+        currentRequest = r;
+    }
+
+    ~scoped_request() {
+        currentRequest = NULL;
+    }
+};
+
+/**
  * HTTP request handler.
  */
 int handler(request_rec *r) {
-    gc_scoped_pool pool(r->pool);
     if(strcmp(r->handler, "mod_tuscany_eval"))
         return DECLINED;
+    gc_scoped_pool pool(r->pool);
+    scoped_request sr(r);
     httpdDebugRequest(r, "modeval::handler::input");
 
     // Get the component implementation lambda
@@ -287,7 +306,8 @@ const list<value> refProxies(const list<
 
 /**
  * Convert a list of component properties to a list of lambda functions that 
just return
- * the property value.
+ * the property value. The user and email properties are configured with the 
values
+ * from the HTTP request, if any.
  */
 struct propProxy {
     const value v;
@@ -298,7 +318,34 @@ struct propProxy {
     }
 };
 
+struct emailPropProxy {
+    const value v;
+    emailPropProxy(const value& v) : v(v) {
+    }
+    const value operator()(unused const list<value>& params) const {
+        const char* email = apr_table_get(currentRequest->subprocess_env, 
"EMAIL");
+        if (email == NULL || *email == '\0')
+            return v;
+        return string(email);
+    }
+};
+
+struct userPropProxy {
+    const value v;
+    userPropProxy(const value& v) : v(v) {
+    }
+    const value operator()(unused const list<value>& params) const {
+        if (currentRequest->user == NULL)
+            return v;
+        return string(currentRequest->user);
+    }
+};
+
 const value mkpropProxy(const value& prop) {
+    if (scdl::name(prop) == "email")
+        return lambda<value(const 
list<value>&)>(emailPropProxy(elementValue(prop)));
+    if (scdl::name(prop) == "user")
+        return lambda<value(const 
list<value>&)>(userPropProxy(elementValue(prop)));
     return lambda<value(const list<value>&)>(propProxy(elementValue(prop)));
 }
 


Reply via email to