Author: sohil.shah(a)jboss.com
Date: 2009-12-06 09:30:49 -0500 (Sun, 06 Dec 2009)
New Revision: 948
Modified:
components/sso/trunk/agent/src/main/java/org/gatein/sso/agent/opensso/OpenSSOAgent.java
components/sso/trunk/gatein-opensso-plugin/src/main/java/org/gatein/sso/opensso/plugin/AuthenticationPlugin.java
components/sso/trunk/packaging/opensso/pom.xml
components/sso/trunk/pom.xml
Log:
opensso integration - code stablization
Modified:
components/sso/trunk/agent/src/main/java/org/gatein/sso/agent/opensso/OpenSSOAgent.java
===================================================================
---
components/sso/trunk/agent/src/main/java/org/gatein/sso/agent/opensso/OpenSSOAgent.java 2009-12-05
22:19:09 UTC (rev 947)
+++
components/sso/trunk/agent/src/main/java/org/gatein/sso/agent/opensso/OpenSSOAgent.java 2009-12-06
14:30:49 UTC (rev 948)
@@ -21,6 +21,7 @@
*/
package org.gatein.sso.agent.opensso;
+import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
@@ -29,7 +30,6 @@
import javax.servlet.http.Cookie;
import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.exoplatform.web.security.Credentials;
import org.gatein.sso.agent.GenericSSOAgent;
@@ -117,7 +117,7 @@
}
}
}
-
+ //-------------------------------------------------------------------------------------------------------------------------------------------------------------------
private boolean isTokenValid(String token) throws Exception
{
HttpClient client = new HttpClient();
@@ -131,10 +131,10 @@
int status = client.executeMethod(post);
String response = post.getResponseBodyAsString();
- log.info("-------------------------------------------------------");
- log.info("Status: "+status);
- log.info("Response: "+response);
- log.info("-------------------------------------------------------");
+ log.debug("-------------------------------------------------------");
+ log.debug("Status: "+status);
+ log.debug("Response: "+response);
+ log.debug("-------------------------------------------------------");
if(response.contains(Boolean.TRUE.toString()))
{
@@ -157,7 +157,8 @@
HttpClient client = new HttpClient();
PostMethod post = null;
try
- {
+ {
+ String uid = null;
String url = this.openSSOUrl+"/identity/attributes";
post = new PostMethod(url);
post.addParameter("subjectid", token);
@@ -166,12 +167,19 @@
int status = client.executeMethod(post);
String response = post.getResponseBodyAsString();
- log.debug("Must Just Read the uid
attribute-------------------------------------------------------");
+ log.debug("--------------------------------------------------------");
log.debug("Status: "+status);
- log.debug("Response: "+response);
+ log.debug(response);
+ log.debug("--------------------------------------------------------");
+ if(response != null)
+ {
+ Properties properties = this.loadAttributes(response);
+ uid = properties.getProperty("uid");
+ }
- return "demo";
+
+ return uid;
}
finally
{
@@ -181,4 +189,44 @@
}
}
}
+
+ private Properties loadAttributes(String response) throws Exception
+ {
+ InputStream is = null;
+ try
+ {
+ Properties properties = new Properties();
+
+ String[] tokens = response.split("\n");
+ String name = null;
+ for(String token: tokens)
+ {
+ if(token.startsWith("userdetails.attribute.name"))
+ {
+ name = token.substring(token.indexOf("=")+1);
+ }
+ else if(token.startsWith("userdetails.attribute.value"))
+ {
+ String value = token.substring(token.indexOf("=")+1);
+
+ if(name != null)
+ {
+ properties.setProperty(name, value);
+ }
+
+ //cleanup
+ name = null;
+ }
+ }
+
+ return properties;
+ }
+ finally
+ {
+ if(is != null)
+ {
+ is.close();
+ }
+ }
+ }
}
Modified:
components/sso/trunk/gatein-opensso-plugin/src/main/java/org/gatein/sso/opensso/plugin/AuthenticationPlugin.java
===================================================================
---
components/sso/trunk/gatein-opensso-plugin/src/main/java/org/gatein/sso/opensso/plugin/AuthenticationPlugin.java 2009-12-05
22:19:09 UTC (rev 947)
+++
components/sso/trunk/gatein-opensso-plugin/src/main/java/org/gatein/sso/opensso/plugin/AuthenticationPlugin.java 2009-12-06
14:30:49 UTC (rev 948)
@@ -43,6 +43,9 @@
private String gateInHost;
private String gateInPort;
private String gateInContext;
+
+ private String username;
+ private String password;
public String getGateInHost()
{
@@ -91,25 +94,17 @@
{
try
{
- System.out.println("---------------------------------------------------------------------");
- System.out.println("Performing GateIn
Login..............................................");
- System.out.println("---------------------------------------------------------------------");
-
- String username = null;
- String password = null;
for (int i = 0; i < callbacks.length; i++)
{
Callback callback = callbacks[i];
if (callback instanceof NameCallback)
{
- username = ((NameCallback) callback).getName();
- System.out.println("Username: " + username);
+ this.username = ((NameCallback) callback).getName();
}
else if (callback instanceof PasswordCallback)
{
- password = new String(((PasswordCallback) callback).getPassword());
- System.out.println("Password: " + password);
+ this.password = new String(((PasswordCallback) callback).getPassword());
}
}
@@ -117,34 +112,26 @@
urlBuffer.append("http://" + this.gateInHost + ":" +
this.gateInPort + "/"
+ this.gateInContext + "/rest/sso/authcallback/auth/" + username +
"/"
+ password);
-
- System.out.println("-------------------------------------------------------------------");
- System.out.println("REST Request=" + urlBuffer.toString());
- System.out.println("-------------------------------------------------------------------");
-
- System.out.println("About to execute REST call........");
+
boolean success = this.executeRemoteCall(urlBuffer.toString());
-
- System.out.println("REST Call was a success....("+success+")");
+ if(!success)
+ {
+ throw new AuthLoginException("GateIn Login Callback Failed!!");
+ }
return ISAuthConstants.LOGIN_SUCCEED;
}
catch(Throwable e)
- {
- System.out.println("------------------------------------------------------");
- System.out.println("Exception :"+e.toString());
- System.out.println("Message :"+e.getMessage());
- System.out.println("------------------------------------------------------");
- e.printStackTrace();
+ {
throw new AuthLoginException(e);
}
}
public Principal getPrincipal()
{
- return new GateInPrincipal("demo");
+ return new GateInPrincipal(this.username);
}
-
+ //--------------------------------------------------------------------------------------------------------------------------------------------------------------------
private boolean executeRemoteCall(String authUrl) throws Exception
{
HttpClient client = new HttpClient();
Modified: components/sso/trunk/packaging/opensso/pom.xml
===================================================================
--- components/sso/trunk/packaging/opensso/pom.xml 2009-12-05 22:19:09 UTC (rev 947)
+++ components/sso/trunk/packaging/opensso/pom.xml 2009-12-06 14:30:49 UTC (rev 948)
@@ -158,6 +158,9 @@
<!-- copy thirdparty dependency -->
<copy
tofile="${basedir}/target/plugin/webapps/opensso/WEB-INF/lib/commons-httpclient.jar"
file="${settings.localRepository}/commons-httpclient/commons-httpclient/${version.commons-httpclient}/commons-httpclient-${version.commons-httpclient}.jar"
+ overwrite="true"/>
+ <copy
tofile="${basedir}/target/plugin/webapps/opensso/WEB-INF/lib/commons-logging.jar"
+
file="${settings.localRepository}/commons-logging/commons-logging/${version.commons-logging}/commons-logging-${version.commons-logging}.jar"
overwrite="true"/>
</tasks>
</configuration>
Modified: components/sso/trunk/pom.xml
===================================================================
--- components/sso/trunk/pom.xml 2009-12-05 22:19:09 UTC (rev 947)
+++ components/sso/trunk/pom.xml 2009-12-06 14:30:49 UTC (rev 948)
@@ -45,6 +45,7 @@
<version.log4j>1.2.14</version.log4j>
<version.jboss.logging>2.0.2.GA</version.jboss.logging>
<version.apache.logging>1.0.4-jboss</version.apache.logging>
+ <version.commons-logging>1.0.4</version.commons-logging>
<!-- cas -->
<version.cas>3.3.4</version.cas>
Show replies by date