incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asa...@apache.org
Subject svn commit: r1469334 - in /sling/whiteboard/asanso/openidconnect: pom.xml src/main/java/org/apache/sling/auth/openidconnect/impl/OpenIDConnectAuthenticationHandler.java
Date Thu, 18 Apr 2013 14:04:51 GMT
Author: asanso
Date: Thu Apr 18 14:04:51 2013
New Revision: 1469334

URL: http://svn.apache.org/r1469334
Log:
SLING-2759 - Provide an OpenId Connect Authentication Handler

Modified:
    sling/whiteboard/asanso/openidconnect/pom.xml
    sling/whiteboard/asanso/openidconnect/src/main/java/org/apache/sling/auth/openidconnect/impl/OpenIDConnectAuthenticationHandler.java

Modified: sling/whiteboard/asanso/openidconnect/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/openidconnect/pom.xml?rev=1469334&r1=1469333&r2=1469334&view=diff
==============================================================================
--- sling/whiteboard/asanso/openidconnect/pom.xml (original)
+++ sling/whiteboard/asanso/openidconnect/pom.xml Thu Apr 18 14:04:51 2013
@@ -88,9 +88,24 @@
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
       	<dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
+       	<dependency>
+      		<groupId>org.apache.oltu.oauth2</groupId>
+      		<artifactId>org.apache.oltu.oauth2.client</artifactId>
+      		<version>0.31-SNAPSHOT</version>
+    	</dependency>
+    	<dependency>
+      		<artifactId>org.apache.oltu.oauth2.common</artifactId>
+      		<groupId>org.apache.oltu.oauth2</groupId>
+      		<version>0.31-SNAPSHOT</version>
+    	</dependency>
+    	
     </dependencies>
 </project>

Modified: sling/whiteboard/asanso/openidconnect/src/main/java/org/apache/sling/auth/openidconnect/impl/OpenIDConnectAuthenticationHandler.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/openidconnect/src/main/java/org/apache/sling/auth/openidconnect/impl/OpenIDConnectAuthenticationHandler.java?rev=1469334&r1=1469333&r2=1469334&view=diff
==============================================================================
--- sling/whiteboard/asanso/openidconnect/src/main/java/org/apache/sling/auth/openidconnect/impl/OpenIDConnectAuthenticationHandler.java
(original)
+++ sling/whiteboard/asanso/openidconnect/src/main/java/org/apache/sling/auth/openidconnect/impl/OpenIDConnectAuthenticationHandler.java
Thu Apr 18 14:04:51 2013
@@ -19,18 +19,26 @@
 package org.apache.sling.auth.openidconnect.impl;
 
 import java.io.IOException;
+import java.util.Dictionary;
+
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import org.osgi.framework.Constants;
+import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.ConfigurationPolicy;
 import org.apache.felix.scr.annotations.Properties;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Service;
+import org.apache.oltu.oauth2.client.request.OAuthClientRequest;
+import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
+import org.apache.oltu.oauth2.common.message.types.ResponseType;
 import org.apache.sling.auth.core.spi.AuthenticationHandler;
 import org.apache.sling.auth.core.spi.AuthenticationInfo;
+import org.apache.sling.commons.osgi.OsgiUtil;
 
 @Component(
 		metatype = true,
@@ -46,10 +54,62 @@ public class OpenIDConnectAuthentication
 	
 	 /** default log */
     private final Logger log = LoggerFactory.getLogger(getClass());
+    
+    @Property
+    public static final String PROP_AUTHORIZATION_ENDPOINT= "oauth.authorization.endpoint";
+    
+    @Property
+    public static final String PROP_TOKEN_ENDPOINT= "oauth.token.endpoint";
+    
+    @Property
+    public static final String PROP_CLIENT_ID= "oauth.clientId";
+    
+    @Property
+    public static final String PROP_REDIRECT_URI= "oauth.redirect.uri";
+    
+    @Property
+    public static final String PROP_SCOPES= "oauth.scopes";
+    
+    private String authorizationEndpoint;
+    private String tokenEndpoint;
+    private String clientId;
+    private String redirectUri;
+    private String scopes;
+    
+    @Activate
+	protected void activate(ComponentContext componentContext) throws Exception {
+    	
+    	final Dictionary props = componentContext.getProperties();
+    	
+		authorizationEndpoint = OsgiUtil.toString(props.get(PROP_AUTHORIZATION_ENDPOINT),"");
+		tokenEndpoint = OsgiUtil.toString(props.get(PROP_TOKEN_ENDPOINT),"");
+    	clientId =  OsgiUtil.toString(props.get(PROP_CLIENT_ID),"");
+    	redirectUri =  OsgiUtil.toString(props.get(PROP_REDIRECT_URI),"");
+    	scopes =  OsgiUtil.toString(props.get(PROP_SCOPES),"");
+    }
 	
 
 	public AuthenticationInfo extractCredentials(HttpServletRequest request,
-			HttpServletResponse response) {
+			HttpServletResponse response) {				
+        try {
+			OAuthClientRequest clientRequest = OAuthClientRequest
+			.authorizationLocation(authorizationEndpoint)
+			.setClientId(clientId)
+			.setRedirectURI(redirectUri)
+			.setResponseType(ResponseType.CODE.toString())
+			.setScope(scopes)
+			.buildQueryMessage();
+			response.sendRedirect(clientRequest.getLocationUri());
+			return AuthenticationInfo.DOING_AUTH;
+			
+		} catch (OAuthSystemException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		
  		return null;
 	}
 



Mime
View raw message