Author: ruchith
Date: Thu Dec  6 19:23:23 2007
New Revision: 10662

Log:

Code from Sudheera for IDENTITY-148

Added:
   trunk/solutions/identity/modules/drupal/
   trunk/solutions/identity/modules/drupal/INSTALL
   trunk/solutions/identity/modules/drupal/README
   trunk/solutions/identity/modules/drupal/cardspace.info
   trunk/solutions/identity/modules/drupal/cardspace.install
   trunk/solutions/identity/modules/drupal/cardspace.module
   trunk/solutions/identity/modules/drupal/logo.png   (contents, props changed)

Added: trunk/solutions/identity/modules/drupal/INSTALL
==============================================================================
--- (empty file)
+++ trunk/solutions/identity/modules/drupal/INSTALL     Thu Dec  6 19:23:23 2007
@@ -0,0 +1,12 @@
+Requirements
+------------
+
+This module requires Drupal versions 4.7, 5.xx, or 6.xx
+
+Installation
+------------
+
+1. Copy the cardspace folder and its contents to the Drupal modules/ 
directory. 
+   Drupal will automaticaly detect it and add it to the list of modules.
+
+2. Go to 'administer -> modules' and enable cardspace.

Added: trunk/solutions/identity/modules/drupal/README
==============================================================================
--- (empty file)
+++ trunk/solutions/identity/modules/drupal/README      Thu Dec  6 19:23:23 2007
@@ -0,0 +1,8 @@
+CardSpace Extension for Dupal
+
+This extension enables CardSpace Authentication for Dupal
+
+This extension will handle CardSpace card association with a user name and 
+authentication using that username to card (ppid) association.
+
+For installation instruction please reffer the INSTALL file.

Added: trunk/solutions/identity/modules/drupal/cardspace.info
==============================================================================
--- (empty file)
+++ trunk/solutions/identity/modules/drupal/cardspace.info      Thu Dec  6 
19:23:23 2007
@@ -0,0 +1,5 @@
+name = CardSpace
+description = "Enables log-in using CardSpace authentication"
+version = "5.x,6.x"
+project = "cardspace"
+

Added: trunk/solutions/identity/modules/drupal/cardspace.install
==============================================================================
--- (empty file)
+++ trunk/solutions/identity/modules/drupal/cardspace.install   Thu Dec  6 
19:23:23 2007
@@ -0,0 +1,11 @@
+<?php
+
+function cardspace_install() {
+    db_query("CREATE TABLE cardspace_assoc (ppid VARCHAR(255) NOT NULL PRIMARY 
KEY, name  VARCHAR(255) NOT NULL)");
+}
+
+function cardspace_uninstall() {
+    db_query("DROP TABLE cardspace_assoc");
+}
+
+?>

Added: trunk/solutions/identity/modules/drupal/cardspace.module
==============================================================================
--- (empty file)
+++ trunk/solutions/identity/modules/drupal/cardspace.module    Thu Dec  6 
19:23:23 2007
@@ -0,0 +1,195 @@
+<?php
+global $cardspace_cons;
+$cardspace_cons['apache_get'] = '__mod_cspace_login__';
+$cardspace_cons['ppid'] = 
'cardspace_http://schemas_xmlsoap_org/ws/2005/05/identity/claims/privatepersonalidentifier';
+$cardspace_cons['requiredClaims'][] = 
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/privatepersonalidentifier';
+
+
+function cardspace_form_alter($form_id, &$form)
+{
+    if ($form_id == 'user_login_block' || $form_id == 'user_login') {
+        $form['cardspace_link'] = array('#value' => '<a href="' . 
+                                        url('cardspace/authenticate') .
+                                        '"><div>' .
+                                        '<img 
src="modules/cardspace/logo.png"><br />' . t('Cardspace Login') .
+                                        '</div></a>'
+                                       );
+    }
+    return $form;
+}
+
+function cardspace_user($type, &$edit, &$account, $category = NULL)
+{
+    if ($type == 'view') {
+        $items['cardspace'] = array('title'=>t('Card Management'), 
+                                    'value' => '<a href="' . 
+                                        url('cardspace/associate') .
+                                        '"><div>' .
+                                        t('Associate Card') .
+                                        '</div></a>' . '<a href="' . 
+                                        url('cardspace/cards') .
+                                        '"><div>' .
+                                        t('Card List') .
+                                        '</div></a>'
+                                   );
+                                   
+        return array(t('CardSpace') => $items);
+    }
+}
+
+function cardspace_object()
+{
+    global $cardspace_cons;
+    if (!$_REQUEST[$cardspace_cons['apache_get']]) {
+    ?>
+    <html>
+    <body onload="cardspace_auth.submit()">
+        <form id="cardspace_auth" method="POST" 
action="?<?=$cardspace_cons['apache_get']?>=xx&q=cardspace/authenticate">
+        <?php
+            cardspace_object_part();
+        ?>
+        </form>
+    </body>
+    </html>
+    <?php
+    } else {
+        if($_SERVER['cardspace_auth_state']=='success') {
+            $ppid = $_SERVER[$cardspace_cons['ppid']];
+            $sql = "SELECT name FROM cardspace_assoc WHERE ppid='$ppid'";      
+            $res = db_query($sql);
+            $res = db_fetch_object($res);
+            
+            if (!$res || $res->name !='') {
+                $name = $res->name;
+                $sql = "SELECT uid FROM users WHERE name='$name'";     
+                $res = db_query($sql);
+                $res = db_fetch_object($res);
+                global $user;
+                $user->uid = $res->uid;
+                user_login_submit('user_login', array());
+                drupal_goto();                
+            } else {
+                drupal_set_message("Invalid Card or not associated with an 
account");
+                drupal_goto();
+            }            
+        }
+    }
+}
+
+function cardspace_associate()
+{
+    global $cardspace_cons;
+    if (!$_REQUEST[$cardspace_cons['apache_get']]) {
+        ?>
+        <html>
+        <body onload="cardspace_auth.submit()">
+            <form id="cardspace_auth" method="POST" 
action="?<?=$cardspace_cons['apache_get']?>=xx&q=cardspace/associate">
+            <?php
+                cardspace_object_part();
+            ?>
+            </form>
+        </body>
+        </html>
+        <?php
+    } else {
+        global $user;
+        $name = $user->name;
+        $ppid = $_SERVER[$cardspace_cons['ppid']];
+        
+        if ($_SERVER['cardspace_auth_state']=='success' && $ppid == '') {
+            drupal_set_message("Invalid Card" . print_r($_SERVER, TRUE));
+            drupal_goto();
+        }
+        
+        $sql = "INSERT INTO cardspace_assoc VALUES('$ppid', '$name')";
+        db_query($sql);
+        drupal_set_message("Card Associated with this account");
+        drupal_goto();
+    }
+}
+
+function cardspace_assoc_list()
+{
+    $head = array(t('Cardspace ID'), t('Action'));
+    
+    global $user;
+    $name = $user->name;
+    $sql = "SELECT * FROM cardspace_assoc WHERE name='$name'";
+    $res = db_query($sql);
+    while ($assoc = db_fetch_object($res)) {
+        $body[] = array($assoc->ppid, l(t('Delete'), 'cardspace/remove/'. 
$assoc->ppid));
+    }
+    
+    if(count($body)<1) {
+        $body[] = array("No Cards yet", l(t('Associate new card'), 
'cardspace/associate'));
+    }
+    
+    $page = theme('table', $head, $body);
+    return $page;
+}
+
+function cardspace_remove()
+{
+    $ppid = arg(2);
+    if ($ppid && $ppid!='') {
+        global $user;
+        $name = $user->name;
+        $sql = "DELETE FROM cardspace_assoc WHERE ppid='$ppid' AND 
name='$name'";
+        db_query($sql);
+        drupal_set_message(t('Association successfully removed'));
+    } else {
+        drupal_set_message(t("Error : BAD PPID :" . arg(2)));
+    }
+    
+    drupal_goto('cardspace/cards');
+}
+
+function cardspace_object_part()
+{
+    global $cardspace_cons;
+    foreach ($cardspace_cons['requiredClaims'] as $claim) {
+        $claims .= $claim . '';
+    }
+    $claims = trim($claims);
+?>
+    <OBJECT type="application/x-informationCard" name="xmlToken">
+    <PARAM  Name="tokenType" Value="urn:oasis:names:tc:SAML:1.0:assertion">
+    <PARAM  Name="requiredClaims" value="<?=$claims?>">
+    </OBJECT>
+<?php
+}
+
+function cardspace_menu($may_cache)
+{
+    $items[] = array('path' => 'cardspace/authenticate',
+                     'title' => t('CardSpace Authentication'),
+                     'callback' => 'cardspace_object',
+                     'access' => TRUE,
+                     'type' => MENU_CALLBACK
+                    );
+    
+    $items[] = array('path' => 'cardspace/associate',
+                     'title' => t('CardSpace Associate'),
+                     'callback' => 'cardspace_associate',
+                     'access' => TRUE,
+                     'type' => MENU_CALLBACK
+                    );
+                    
+    $items[] = array('path' => 'cardspace/cards',
+                     'title' => t('CardSpace card list'),
+                     'callback' => 'cardspace_assoc_list',
+                     'access' => TRUE,
+                     'type' => MENU_CALLBACK
+                    );
+
+    $items[] = array('path' => 'cardspace/remove',
+                     'title' => t('CardSpace Remove'),
+                     'callback' => 'cardspace_remove',
+                     'callback arguments' => 'infocard_admin',
+                     'access' => TRUE,
+                     'type' => MENU_CALLBACK
+                    );
+
+    return $items;
+}
+?>

Added: trunk/solutions/identity/modules/drupal/logo.png
==============================================================================
Binary file. No diff available.

_______________________________________________
Identity-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/identity-dev

Reply via email to