Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
GTNSSO-23 OpenSSO/OpenAM Agent doesn't work well when gatein is on Wi…
Browse files Browse the repository at this point in the history
…ndows and OpenAM is on *NIX based system
  • Loading branch information
mposolda committed Apr 29, 2013
1 parent d64af01 commit f7419bd
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 6 deletions.
Expand Up @@ -28,10 +28,9 @@
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.ValueParam;
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
import org.gatein.sso.agent.GenericAgent;
Expand All @@ -53,17 +52,41 @@ public class OpenSSOAgentImpl extends GenericAgent implements OpenSSOAgent
// HttpSession attribute, which will be used to check that response message from CDC contains same ID of InResponseTo as the ID, which we used in OpenSSOCDLoginRedirectFilter
public static final String IN_RESPONSE_TO_ATTR = "OpenSSOAgent.InResponseTo";

// Possible line separators on various OS
private static final String WINDOWS_SEPARATOR = "\r\n";
private static final String UNIX_SEPARATOR = "\n";
private static final String MAC_SEPARATOR = "\r";

private static final String[] LINE_SEPARATORS = new String[] { WINDOWS_SEPARATOR, UNIX_SEPARATOR, MAC_SEPARATOR };

private static Logger log = LoggerFactory.getLogger(OpenSSOAgentImpl.class);
private static OpenSSOAgentImpl singleton;

private String cookieName;
private String serverUrl;
private final String lineSeparator;

private CDMessageParser cdcMessageParser = new CDMessageParser();

public OpenSSOAgentImpl(InitParams params)
{
// TODO: Read serverUrl and cookieName from params
// TODO: Read serverUrl and cookieName from params
if (params == null)
{
this.lineSeparator = null;
return;
}

ValueParam lineSeparatorParam = params.getValueParam("lineSeparator");
if (lineSeparatorParam != null)
{
this.lineSeparator = lineSeparatorParam.getValue();
}
else
{
this.lineSeparator = null;
}

log.debug("Agent configured with line separator: " + this.lineSeparator);
}

public void setCookieName(String cookieName)
Expand Down Expand Up @@ -289,7 +312,7 @@ protected Properties loadAttributes(String response) throws Exception
{
Properties properties = new Properties();

String[] tokens = response.split(System.getProperty("line.separator"));
String[] tokens = response.split(getLineSeparator(response));
String name = null;
for(String token: tokens)
{
Expand Down Expand Up @@ -322,6 +345,27 @@ else if(token.startsWith("userdetails.attribute.value"))
}
}

// Use configured line separator or try to "guess" it from LINE_SEPARATORS set
private String getLineSeparator(String response)
{
if (this.lineSeparator != null)
{
return lineSeparator;
}
else
{
for (String current : LINE_SEPARATORS)
{
if (response.contains(current))
{
return current;
}
}

throw new IllegalArgumentException("Can't obtain line separator from response string: " + response);
}
}

private void throwIllegalStateException(String message)
{
log.warn(message);
Expand Down
@@ -0,0 +1,75 @@
/*
* JBoss, a division of Red Hat
* Copyright 2012, Red Hat Middleware, LLC, and individual
* contributors as indicated by the @authors tag. See the
* copyright.txt in the distribution for a full listing of
* individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.gatein.sso.agent.opensso;

import java.util.Properties;

import junit.framework.TestCase;

/**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/
public class TestParseSubject extends TestCase
{

private String LINUX_STRING = "userdetails.token.id=AQIC5wM2LY4SgtrcwwIrICaSkhcmXs5P-DmDBAc8itxVUt8Lo.*AAJTSQACMDE.*\nuserdetails.attribute.name=uid\nuserdetails.attribute.value=johny\nuserdetails.attribute.name=sn\nuserdetails.attribute.value=johnysn\nuserdetails.attribute.name=userpassword\nuserdetails.attribute.value={SSHA}Ug4jcPDG54L/dZGzvP6AbjjRllvXyDqK0et2Xw==";
private String WINDOWS_STRING = "userdetails.token.id=AQIC5wM2LY4SfcwwIrICaSkhcmXs5P-DmDBAc8itxVUt8Lo.*AAJTSQACMDE.*\r\nuserdetails.attribute.name=uid\r\nuserdetails.attribute.value=root\r\nuserdetails.attribute.name=sn\r\nuserdetails.attribute.value=rootsn\r\nuserdetails.attribute.name=userpassword\r\nuserdetails.attribute.value={SSHA}Ug4jcPDG54L/dZGzvP6AbjjRllvXyDqK0et2Xw==";
private String MAC_STRING = "userdetails.token.id=AQIC5wM2LY4SfcwwIrICaSkhcmXs5P-DmDBAc8itxVUt8Lo.*AAJTSQACMDE.*\ruserdetails.attribute.name=uid\ruserdetails.attribute.value=mary\ruserdetails.attribute.name=sn\ruserdetails.attribute.value=marysn\ruserdetails.attribute.name=userpassword\ruserdetails.attribute.value={SSHA}Ug4jcPDG54L/dZGzvP6AbjjRllvXyDqK0et2Xw==";

public void testParseSubject() throws Exception
{
TestOpenSSOAgentImpl agent = new TestOpenSSOAgentImpl();

// Test linux properties
Properties linuxProps = agent.loadAttributes(LINUX_STRING);
assertEquals("johny", linuxProps.get("uid"));
assertEquals("johnysn", linuxProps.get("sn"));

// Test windows properties
Properties windowsProps = agent.loadAttributes(WINDOWS_STRING);
assertEquals("root", windowsProps.get("uid"));
assertEquals("rootsn", windowsProps.get("sn"));

// Test linux properties
Properties macProps = agent.loadAttributes(MAC_STRING);
assertEquals("mary", macProps.get("uid"));
assertEquals("marysn", macProps.get("sn"));
}

// Just to access protected method
private class TestOpenSSOAgentImpl extends OpenSSOAgentImpl
{

public TestOpenSSOAgentImpl()
{
super(null);
}

protected Properties loadAttributes(String response) throws Exception
{
return super.loadAttributes(response);
}

}
}

0 comments on commit f7419bd

Please sign in to comment.