[Carbon-commits] [Carbon Components] svn commit r53005 - in trunk/carbon-components/identity: org.wso2.carbon.identity.oauth.mediator/src/main/java/org/wso2/carbon/identity/oauth/mediator org.wso2.carbon.identity.oauth.mediator/src/main/resources org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dto org.wso2.carbon.identity.oauth/src/main/resources/META-INF

prabath at wso2.com prabath at wso2.com
Sat Jan 16 12:47:25 PST 2010


Author: prabath
Date: Sat Jan 16 12:47:25 2010
New Revision: 53005
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=53005

Log:
adding 2-legged oauth support

Added:
   trunk/carbon-components/identity/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/OAuthAdminService.java
   trunk/carbon-components/identity/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dto/
   trunk/carbon-components/identity/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dto/OAuthConsumerDTO.java
Modified:
   trunk/carbon-components/identity/org.wso2.carbon.identity.oauth.mediator/src/main/java/org/wso2/carbon/identity/oauth/mediator/OAuthMediator.java
   trunk/carbon-components/identity/org.wso2.carbon.identity.oauth.mediator/src/main/java/org/wso2/carbon/identity/oauth/mediator/OAuthServiceClient.java
   trunk/carbon-components/identity/org.wso2.carbon.identity.oauth.mediator/src/main/resources/OAuthService.wsdl
   trunk/carbon-components/identity/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/OAuthService.java
   trunk/carbon-components/identity/org.wso2.carbon.identity.oauth/src/main/resources/META-INF/services.xml

Modified: trunk/carbon-components/identity/org.wso2.carbon.identity.oauth.mediator/src/main/java/org/wso2/carbon/identity/oauth/mediator/OAuthMediator.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/identity/org.wso2.carbon.identity.oauth.mediator/src/main/java/org/wso2/carbon/identity/oauth/mediator/OAuthMediator.java?rev=53005&r1=53004&r2=53005&view=diff
==============================================================================
--- trunk/carbon-components/identity/org.wso2.carbon.identity.oauth.mediator/src/main/java/org/wso2/carbon/identity/oauth/mediator/OAuthMediator.java	(original)
+++ trunk/carbon-components/identity/org.wso2.carbon.identity.oauth.mediator/src/main/java/org/wso2/carbon/identity/oauth/mediator/OAuthMediator.java	Sat Jan 16 12:47:25 2010
@@ -1,13 +1,14 @@
 package org.wso2.carbon.identity.oauth.mediator;
 
+import java.util.Map;
+
 import org.apache.synapse.MessageContext;
 import org.apache.synapse.core.axis2.Axis2MessageContext;
 import org.apache.synapse.mediators.AbstractMediator;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.CarbonConstants;
-import org.wso2.carbon.utils.ServerConfiguration;
+import org.wso2.carbon.identity.oauth.mediator.dto.OAuthConsumerDTO;
 
 public class OAuthMediator extends AbstractMediator {
 
@@ -16,7 +17,6 @@
     private boolean remote = true;
     private String remoteServiceUrl;
 
-
     public boolean isRemote() {
         return remote;
     }
@@ -26,6 +26,11 @@
     }
 
     public String getRemoteServiceUrl() {
+        if (remoteServiceUrl != null) {
+            if (!remoteServiceUrl.endsWith("/")) {
+                remoteServiceUrl += "/";
+            }
+        }
         return remoteServiceUrl;
     }
 
@@ -37,30 +42,62 @@
      * {@inheritDoc}
      */
     public boolean mediate(MessageContext synCtx) {
-        
-    	 OAuthServiceClient client = null;
-         String decision = null;
-         ConfigurationContext configContext = null;        
-         org.apache.axis2.context.MessageContext msgContext;
-         Axis2MessageContext axis2Msgcontext = null;
-         axis2Msgcontext = (Axis2MessageContext) synCtx;
-         msgContext = axis2Msgcontext.getAxis2MessageContext();
-         String consumerKey = null;
-         String consumerSecret = null;
-         String serviceName = null;
-         String operationName = null;
-   
-
-         if (log.isDebugEnabled()) {
-             log.debug("Mediation for Entitlement started");
-         }
-
-         try {
-             configContext = msgContext.getConfigurationContext();         
-         } catch (Exception e) {
-             log.error("Error occured while evaluating the policy", e);
-             return false;
-         }
-         return true;
+
+        OAuthServiceClient client = null;
+        ConfigurationContext configContext = null;
+        org.apache.axis2.context.MessageContext msgContext;
+        Axis2MessageContext axis2Msgcontext = null;
+        axis2Msgcontext = (Axis2MessageContext) synCtx;
+        msgContext = axis2Msgcontext.getAxis2MessageContext();
+        String consumerKey = null;
+        String signature = null;
+        String signatureMethod = null;
+        String nonce = null;
+        String timestamp = null;
+        Map headersMap = null;
+        OAuthConsumerDTO consumer = null;
+        String authHeader = null;
+
+        if (log.isDebugEnabled()) {
+            log.debug("Mediation for Entitlement started");
+        }
+
+        try {
+            configContext = msgContext.getConfigurationContext();
+            headersMap = (Map) msgContext
+                    .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
+
+            if (headersMap != null) {
+                authHeader = (String) headersMap.get("Authorization");
+                client = new OAuthServiceClient(getRemoteServiceUrl(), configContext);
+                consumer = new OAuthConsumerDTO();
+                if (authHeader != null) {
+                    String[] headers = authHeader.split(",");
+                    if (headers != null && headers.length > 0) {
+                        for (int i = 0; i < headers.length; i++) {
+                            String[] elements = headers[i].split("=");
+                            if (elements != null && elements.length > 0) {
+                                if ("oauth_consumer_key".equals(elements[0].trim())) {
+                                    consumer.setOauthConsumerKey(elements[1].trim());
+                                } else if ("oauth_nonce".equals(elements[0].trim())) {
+                                    consumer.setOauthNonce(elements[1].trim());
+                                } else if ("oauth_signature".equals(elements[0].trim())) {
+                                    consumer.setOauthSignature(elements[1].trim());
+                                } else if ("oauth_signature_method".equals(elements[0].trim())) {
+                                    consumer.setOauthSignatureMethod(elements[1].trim());
+                                } else if ("oauth_timestamp".equals(elements[0].trim())) {
+                                    consumer.setOauthTimeStamp(elements[1].trim());
+                                }
+                            }
+                        }
+                    }
+                }
+                return client.isOAuthConsumerValid(consumer);
+            }
+        } catch (Exception e) {
+            log.error("Error occured while validating oauth consumer", e);
+            return false;
+        }
+        return false;
     }
 }

Modified: trunk/carbon-components/identity/org.wso2.carbon.identity.oauth.mediator/src/main/java/org/wso2/carbon/identity/oauth/mediator/OAuthServiceClient.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/identity/org.wso2.carbon.identity.oauth.mediator/src/main/java/org/wso2/carbon/identity/oauth/mediator/OAuthServiceClient.java?rev=53005&r1=53004&r2=53005&view=diff
==============================================================================
--- trunk/carbon-components/identity/org.wso2.carbon.identity.oauth.mediator/src/main/java/org/wso2/carbon/identity/oauth/mediator/OAuthServiceClient.java	(original)
+++ trunk/carbon-components/identity/org.wso2.carbon.identity.oauth.mediator/src/main/java/org/wso2/carbon/identity/oauth/mediator/OAuthServiceClient.java	Sat Jan 16 12:47:25 2010
@@ -1,6 +1,51 @@
 package org.wso2.carbon.identity.oauth.mediator;
 
+import java.rmi.RemoteException;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.identity.oauth.mediator.dto.OAuthConsumerDTO;
+
 public class OAuthServiceClient {
 
+    private OAuthServiceStub stub = null;
+    private static final Log log = LogFactory.getLog(OAuthServiceClient.class);
+
+    public OAuthServiceClient(String backendServerURL, ConfigurationContext configCtx)
+            throws AxisFault {
+        String serviceURL = backendServerURL + "OAuthService";
+
+        try {
+            stub = new OAuthServiceStub(configCtx, serviceURL);
+        } catch (Exception e) {
+            handleException("Error initializing Relying Party Client", e);
+        }
+    }
+
+    public boolean isOAuthConsumerValid(OAuthConsumerDTO oauthConsumer) throws AxisFault {
+        try {
+            return stub.isOAuthConsumerValid(oauthConsumer);
+        } catch (RemoteException e) {
+            handleException("Error while validating OAuth consumer credentials", e);
+        }
+        return false;
+    }
+
+    /**
+     * Logs and wraps the given exception.
+     * 
+     * @param msg
+     *            Error message
+     * @param e
+     *            Exception
+     * @throws AxisFault
+     *             which wraps the error
+     */
+    private void handleException(String msg, Exception e) throws AxisFault {
+        log.error(msg, e);
+        throw new AxisFault(msg, e);
+    }
 
 }

Modified: trunk/carbon-components/identity/org.wso2.carbon.identity.oauth.mediator/src/main/resources/OAuthService.wsdl
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/identity/org.wso2.carbon.identity.oauth.mediator/src/main/resources/OAuthService.wsdl?rev=53005&r1=53004&r2=53005&view=diff
==============================================================================
--- trunk/carbon-components/identity/org.wso2.carbon.identity.oauth.mediator/src/main/resources/OAuthService.wsdl	(original)
+++ trunk/carbon-components/identity/org.wso2.carbon.identity.oauth.mediator/src/main/resources/OAuthService.wsdl	Sat Jan 16 12:47:25 2010
@@ -1,12 +1,12 @@
-<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:axis2="http://oauth.identity.carbon.wso2.org" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://oauth.identity.carbon.wso2.org">
+<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:axis2="http://oauth.identity.carbon.wso2.org" xmlns:ax215="http://dto.oauth.identity.carbon.wso2.org/xsd" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://oauth.identity.carbon.wso2.org">
     <wsdl:documentation>OAuthService</wsdl:documentation>
     <wsdl:types>
-        <xs:schema xmlns:ns="http://org.apache.axis2/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://org.apache.axis2/xsd">
+        <xs:schema xmlns:ax216="http://dto.oauth.identity.carbon.wso2.org/xsd" xmlns:ns="http://org.apache.axis2/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://org.apache.axis2/xsd">
+            <xs:import namespace="http://dto.oauth.identity.carbon.wso2.org/xsd" />
             <xs:element name="isOAuthConsumerValid">
                 <xs:complexType>
                     <xs:sequence>
-                        <xs:element name="condumerKey" nillable="true" type="xs:string" />
-                        <xs:element name="consumerSecret" nillable="true" type="xs:string" />
+                        <xs:element name="oauthConsumer" nillable="true" type="ax216:OAuthConsumerDTO" />
                     </xs:sequence>
                 </xs:complexType>
             </xs:element>
@@ -18,6 +18,17 @@
                 </xs:complexType>
             </xs:element>
         </xs:schema>
+        <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://dto.oauth.identity.carbon.wso2.org/xsd">
+            <xs:complexType name="OAuthConsumerDTO">
+                <xs:sequence>
+                    <xs:element name="oauthConsumerKey" nillable="true" type="xs:string" />
+                    <xs:element name="oauthNonce" nillable="true" type="xs:string" />
+                    <xs:element name="oauthSignature" nillable="true" type="xs:string" />
+                    <xs:element name="oauthSignatureMethod" nillable="true" type="xs:string" />
+                    <xs:element name="oauthTimeStamp" nillable="true" type="xs:string" />
+                </xs:sequence>
+            </xs:complexType>
+        </xs:schema>
     </wsdl:types>
     <wsdl:message name="isOAuthConsumerValidRequest">
         <wsdl:part name="parameters" element="ns1:isOAuthConsumerValid" />

Added: trunk/carbon-components/identity/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/OAuthAdminService.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/identity/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/OAuthAdminService.java?pathrev=53005
==============================================================================
--- (empty file)
+++ trunk/carbon-components/identity/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/OAuthAdminService.java	Sat Jan 16 12:47:25 2010
@@ -0,0 +1,9 @@
+package org.wso2.carbon.identity.oauth;
+
+public class OAuthAdminService {
+
+    public void registerOAuthConsumer(String consumerKey, String consumerSecret) {
+
+    }
+
+}

Modified: trunk/carbon-components/identity/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/OAuthService.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/identity/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/OAuthService.java?rev=53005&r1=53004&r2=53005&view=diff
==============================================================================
--- trunk/carbon-components/identity/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/OAuthService.java	(original)
+++ trunk/carbon-components/identity/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/OAuthService.java	Sat Jan 16 12:47:25 2010
@@ -1,9 +1,11 @@
 package org.wso2.carbon.identity.oauth;
 
+import org.wso2.carbon.identity.oauth.dto.OAuthConsumerDTO;
+
 public class OAuthService {
 
-    public boolean isOAuthConsumerValid(String condumerKey, String consumerSecret) {
-        return false;
+    public boolean isOAuthConsumerValid(OAuthConsumerDTO oauthConsumer) {
+        return true;
     }
 
 }

Added: trunk/carbon-components/identity/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dto/OAuthConsumerDTO.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/identity/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dto/OAuthConsumerDTO.java?pathrev=53005
==============================================================================
--- (empty file)
+++ trunk/carbon-components/identity/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dto/OAuthConsumerDTO.java	Sat Jan 16 12:47:25 2010
@@ -0,0 +1,55 @@
+package org.wso2.carbon.identity.oauth.dto;
+
+public class OAuthConsumerDTO {
+
+    // oauth_signature
+    private String oauthSignature = null;
+    // oauth_nonce
+    private String oauthNonce = null;
+    // oauth_signature_method = HMAC-SHA1
+    private String oauthSignatureMethod = null;
+    // oauth_consumer_key
+    private String oauthConsumerKey = null;
+    // oauth_timestamp
+    private String oauthTimeStamp = null;
+
+    public String getOauthSignature() {
+        return oauthSignature;
+    }
+
+    public void setOauthSignature(String oauthSignature) {
+        this.oauthSignature = oauthSignature;
+    }
+
+    public String getOauthNonce() {
+        return oauthNonce;
+    }
+
+    public void setOauthNonce(String oauthNonce) {
+        this.oauthNonce = oauthNonce;
+    }
+
+    public String getOauthSignatureMethod() {
+        return oauthSignatureMethod;
+    }
+
+    public void setOauthSignatureMethod(String oauthSignatureMethod) {
+        this.oauthSignatureMethod = oauthSignatureMethod;
+    }
+
+    public String getOauthConsumerKey() {
+        return oauthConsumerKey;
+    }
+
+    public void setOauthConsumerKey(String oauthConsumerKey) {
+        this.oauthConsumerKey = oauthConsumerKey;
+    }
+
+    public String getOauthTimeStamp() {
+        return oauthTimeStamp;
+    }
+
+    public void setOauthTimeStamp(String oauthTimeStamp) {
+        this.oauthTimeStamp = oauthTimeStamp;
+    }
+}

Modified: trunk/carbon-components/identity/org.wso2.carbon.identity.oauth/src/main/resources/META-INF/services.xml
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/identity/org.wso2.carbon.identity.oauth/src/main/resources/META-INF/services.xml?rev=53005&r1=53004&r2=53005&view=diff
==============================================================================
--- trunk/carbon-components/identity/org.wso2.carbon.identity.oauth/src/main/resources/META-INF/services.xml	(original)
+++ trunk/carbon-components/identity/org.wso2.carbon.identity.oauth/src/main/resources/META-INF/services.xml	Sat Jan 16 12:47:25 2010
@@ -1,17 +1,22 @@
 <serviceGroup>
 
 	<service name="OAuthService" scope="transportsession">
-		<transports>
-			<transport>https</transport>
-		</transports>
+		<transports><transport>https</transport></transports>
 		<schema schemaNamespace="http://org.apache.axis2/xsd" elementFormDefaultQualified="true" />
 		<description>OAuth related functionality.</description>
-		<parameter name="ServiceClass">
-			org.wso2.carbon.identity.oauth.OAuthService
-		</parameter>
+		<parameter name="ServiceClass">org.wso2.carbon.identity.oauth.OAuthService</parameter>
+		<parameter name="DoAuthentication" locked="true">false</parameter>
+	</service>
+
+	<service name="OAuthAdminService" scope="transportsession">
+		<transports><transport>https</transport></transports>
+		<schema schemaNamespace="http://org.apache.axis2/xsd" elementFormDefaultQualified="true" />
+		<description>OAuth administration related functionality.</description>
+		<parameter name="ServiceClass">org.wso2.carbon.identity.oauth.OAuthAdminService</parameter>
+		<parameter name="DoAuthentication" locked="true">true</parameter>
+		<parameter name="AuthorizationAction" locked="true">/permission/admin/login</parameter>
 	</service>
 
-	<parameter name="DoAuthentication" locked="true">false</parameter>
 	<parameter name="adminService" locked="true">true</parameter>
- 	<parameter name="hiddenService" locked="true">true</parameter>
+	<parameter name="hiddenService" locked="true">true</parameter>
 </serviceGroup>



More information about the Carbon-commits mailing list