Author: anil.saldhana(a)jboss.com
Date: 2011-03-03 10:01:17 -0500 (Thu, 03 Mar 2011)
New Revision: 794
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/impl/BaseHandlerConfig.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/impl/DefaultSAML2HandlerChainConfig.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/interfaces/SAML2MapBasedConfig.java
federation/trunk/picketlink-web/src/main/java/org/picketlink/identity/federation/web/handlers/saml2/SAML2AuthenticationHandler.java
federation/trunk/picketlink-web/src/test/java/org/picketlink/test/identity/federation/web/saml/handlers/SAML2AuthenticationHandlerUnitTestCase.java
federation/trunk/picketlink-web/src/test/java/org/picketlink/test/identity/federation/web/saml/handlers/SAML2SignatureHandlerUnitTestCase.java
Log:
PLFED-156: nameid format customization
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/impl/BaseHandlerConfig.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/impl/BaseHandlerConfig.java 2011-03-03
12:52:05 UTC (rev 793)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/impl/BaseHandlerConfig.java 2011-03-03
15:01:17 UTC (rev 794)
@@ -41,7 +41,7 @@
{
return params.containsKey(key);
}
-
+
/**
* @see SAML2HandlerChainConfig#getParameter(String)
*/
@@ -50,6 +50,13 @@
return params.get(parameterName);
}
+ /**
+ * @see
org.picketlink.identity.federation.core.saml.v2.interfaces.SAML2MapBasedConfig#addParameter(java.lang.String,
java.lang.Object)
+ */
+ public void addParameter(String parameterName, Object value)
+ {
+ this.params.put(parameterName, value);
+ }
public void set(Map<String, Object> options)
{
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/impl/DefaultSAML2HandlerChainConfig.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/impl/DefaultSAML2HandlerChainConfig.java 2011-03-03
12:52:05 UTC (rev 793)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/impl/DefaultSAML2HandlerChainConfig.java 2011-03-03
15:01:17 UTC (rev 794)
@@ -30,15 +30,14 @@
* @author Anil.Saldhana(a)redhat.com
* @since Oct 10, 2009
*/
-public class DefaultSAML2HandlerChainConfig extends BaseHandlerConfig
-implements SAML2HandlerChainConfig
-{
+public class DefaultSAML2HandlerChainConfig extends BaseHandlerConfig implements
SAML2HandlerChainConfig
+{
public DefaultSAML2HandlerChainConfig()
- {
+ {
}
-
- public DefaultSAML2HandlerChainConfig(Map<String,Object> map)
+
+ public DefaultSAML2HandlerChainConfig(Map<String, Object> map)
{
- this.params = map;
+ this.params.putAll(map);
}
}
\ No newline at end of file
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/interfaces/SAML2MapBasedConfig.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/interfaces/SAML2MapBasedConfig.java 2011-03-03
12:52:05 UTC (rev 793)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/interfaces/SAML2MapBasedConfig.java 2011-03-03
15:01:17 UTC (rev 794)
@@ -35,17 +35,24 @@
* @return
*/
boolean containsKey(String key);
-
+
/**
* Get a parameter from the chain config
* @param parameterName
* @return
*/
- public Object getParameter(String parameterName);
-
+ public Object getParameter(String parameterName);
+
/**
+ * Add a parameter
+ * @param parameterName
+ * @param value
+ */
+ public void addParameter(String parameterName, Object value);
+
+ /**
* Set the options
* @param options
*/
- void set(Map<String,Object> options);
+ void set(Map<String, Object> options);
}
\ No newline at end of file
Modified:
federation/trunk/picketlink-web/src/main/java/org/picketlink/identity/federation/web/handlers/saml2/SAML2AuthenticationHandler.java
===================================================================
---
federation/trunk/picketlink-web/src/main/java/org/picketlink/identity/federation/web/handlers/saml2/SAML2AuthenticationHandler.java 2011-03-03
12:52:05 UTC (rev 793)
+++
federation/trunk/picketlink-web/src/main/java/org/picketlink/identity/federation/web/handlers/saml2/SAML2AuthenticationHandler.java 2011-03-03
15:01:17 UTC (rev 794)
@@ -333,7 +333,7 @@
String id = IDGenerator.create("ID_");
//Check if there is a nameid policy
- String nameIDFormat = (String)
request.getOptions().get(GeneralConstants.NAMEID_FORMAT);
+ String nameIDFormat = (String)
handlerConfig.getParameter(GeneralConstants.NAMEID_FORMAT);
if (StringUtil.isNotNull(nameIDFormat))
{
samlRequest.setNameIDFormat(nameIDFormat);
Modified:
federation/trunk/picketlink-web/src/test/java/org/picketlink/test/identity/federation/web/saml/handlers/SAML2AuthenticationHandlerUnitTestCase.java
===================================================================
---
federation/trunk/picketlink-web/src/test/java/org/picketlink/test/identity/federation/web/saml/handlers/SAML2AuthenticationHandlerUnitTestCase.java 2011-03-03
12:52:05 UTC (rev 793)
+++
federation/trunk/picketlink-web/src/test/java/org/picketlink/test/identity/federation/web/saml/handlers/SAML2AuthenticationHandlerUnitTestCase.java 2011-03-03
15:01:17 UTC (rev 794)
@@ -88,6 +88,7 @@
SAML2HandlerChainConfig chainConfig = new DefaultSAML2HandlerChainConfig();
SAML2HandlerConfig handlerConfig = new DefaultSAML2HandlerConfig();
+ handlerConfig.addParameter(GeneralConstants.NAMEID_FORMAT,
JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get());
Map<String, Object> chainOptions = new HashMap<String, Object>();
SPType spType = new SPType();
@@ -116,7 +117,6 @@
SAML2HandlerRequest request = new DefaultSAML2HandlerRequest(httpContext,
issuerInfo.getIssuer(), docHolder,
SAML2Handler.HANDLER_TYPE.SP);
request.setTypeOfRequestToBeGenerated(GENERATE_REQUEST_TYPE.AUTH);
- request.addOption(GeneralConstants.NAMEID_FORMAT,
JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get());
SAML2HandlerResponse response = new DefaultSAML2HandlerResponse();
handler.generateSAMLRequest(request, response);
Modified:
federation/trunk/picketlink-web/src/test/java/org/picketlink/test/identity/federation/web/saml/handlers/SAML2SignatureHandlerUnitTestCase.java
===================================================================
---
federation/trunk/picketlink-web/src/test/java/org/picketlink/test/identity/federation/web/saml/handlers/SAML2SignatureHandlerUnitTestCase.java 2011-03-03
12:52:05 UTC (rev 793)
+++
federation/trunk/picketlink-web/src/test/java/org/picketlink/test/identity/federation/web/saml/handlers/SAML2SignatureHandlerUnitTestCase.java 2011-03-03
15:01:17 UTC (rev 794)
@@ -41,8 +41,8 @@
import
org.picketlink.identity.federation.core.saml.v2.interfaces.SAML2HandlerChainConfig;
import org.picketlink.identity.federation.core.saml.v2.interfaces.SAML2HandlerConfig;
import org.picketlink.identity.federation.core.saml.v2.interfaces.SAML2HandlerRequest;
+import
org.picketlink.identity.federation.core.saml.v2.interfaces.SAML2HandlerRequest.GENERATE_REQUEST_TYPE;
import org.picketlink.identity.federation.core.saml.v2.interfaces.SAML2HandlerResponse;
-import
org.picketlink.identity.federation.core.saml.v2.interfaces.SAML2HandlerRequest.GENERATE_REQUEST_TYPE;
import org.picketlink.identity.federation.newmodel.saml.v2.protocol.AuthnRequestType;
import org.picketlink.identity.federation.web.constants.GeneralConstants;
import org.picketlink.identity.federation.web.core.HTTPContext;
@@ -71,60 +71,62 @@
String issuerValue = "http://sp";
AuthnRequestType authnRequest = saml2Request.createAuthnRequestType(id,
assertionConsumerURL, destination,
issuerValue);
-
+
Document authDoc = saml2Request.convert(authnRequest);
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
KeyPair keypair = kpg.genKeyPair();
-
+
SAML2SignatureGenerationHandler handler = new SAML2SignatureGenerationHandler();
-
+
SAML2HandlerChainConfig chainConfig = new DefaultSAML2HandlerChainConfig();
SAML2HandlerConfig handlerConfig = new DefaultSAML2HandlerConfig();
-
- Map<String,Object> chainOptions = new HashMap<String, Object>();
- IDPType idpType = new IDPType();
+
+ Map<String, Object> chainOptions = new HashMap<String, Object>();
+ IDPType idpType = new IDPType();
chainOptions.put(GeneralConstants.CONFIGURATION, idpType);
chainOptions.put(GeneralConstants.KEYPAIR, keypair);
- chainConfig.set(chainOptions);
-
+ chainConfig.set(chainOptions);
+
//Initialize the handler
handler.initChainConfig(chainConfig);
handler.initHandlerConfig(handlerConfig);
-
+
//Create a Protocol Context
MockHttpSession session = new MockHttpSession();
MockServletContext servletContext = new MockServletContext();
MockHttpServletRequest servletRequest = new MockHttpServletRequest(session,
"POST");
MockHttpServletResponse servletResponse = new MockHttpServletResponse();
HTTPContext httpContext = new HTTPContext(servletRequest, servletResponse,
servletContext);
-
+
SAMLDocumentHolder docHolder = new SAMLDocumentHolder(authnRequest, authDoc);
IssuerInfoHolder issuerInfo = new
IssuerInfoHolder("http://localhost:8080/idp/");
- SAML2HandlerRequest request = new DefaultSAML2HandlerRequest(httpContext,
- issuerInfo.getIssuer(), docHolder, SAML2Handler.HANDLER_TYPE.IDP);
+ SAML2HandlerRequest request = new DefaultSAML2HandlerRequest(httpContext,
issuerInfo.getIssuer(), docHolder,
+ SAML2Handler.HANDLER_TYPE.IDP);
request.setTypeOfRequestToBeGenerated(GENERATE_REQUEST_TYPE.AUTH);
-
+
SAML2HandlerResponse response = new DefaultSAML2HandlerResponse();
-
- request.addOption(GeneralConstants.SENDER_PUBLIC_KEY, keypair.getPublic());
-
- (new SAML2AuthenticationHandler()).generateSAMLRequest(request, response);
+
+ request.addOption(GeneralConstants.SENDER_PUBLIC_KEY, keypair.getPublic());
+
+ SAML2AuthenticationHandler authHandler = new SAML2AuthenticationHandler();
+ authHandler.initHandlerConfig(handlerConfig);
+ authHandler.generateSAMLRequest(request, response);
+
handler.generateSAMLRequest(request, response);
Document signedDoc = response.getResultingDocument();
-
+
assertNotNull("Signed Doc is not null", signedDoc);
SAMLDocumentHolder signedHolder = new SAMLDocumentHolder(signedDoc);
- request = new DefaultSAML2HandlerRequest(httpContext,
- issuerInfo.getIssuer(), signedHolder,
+ request = new DefaultSAML2HandlerRequest(httpContext, issuerInfo.getIssuer(),
signedHolder,
SAML2Handler.HANDLER_TYPE.SP);
-
- request.addOption(GeneralConstants.SENDER_PUBLIC_KEY, keypair.getPublic());
-
+
+ request.addOption(GeneralConstants.SENDER_PUBLIC_KEY, keypair.getPublic());
+
SAML2SignatureValidationHandler validHandler = new
SAML2SignatureValidationHandler();
validHandler.initChainConfig(chainConfig);
validHandler.initHandlerConfig(handlerConfig);
-
- validHandler.handleStatusResponseType(request, response);
- }
+
+ validHandler.handleStatusResponseType(request, response);
+ }
}
\ No newline at end of file