Author: anil.saldhana(a)jboss.com
Date: 2009-10-12 14:39:08 -0400 (Mon, 12 Oct 2009)
New Revision: 851
Added:
identity-federation/trunk/jboss-identity-web/src/test/java/org/jboss/test/identity/federation/web/saml/
identity-federation/trunk/jboss-identity-web/src/test/java/org/jboss/test/identity/federation/web/saml/handlers/
identity-federation/trunk/jboss-identity-web/src/test/java/org/jboss/test/identity/federation/web/saml/handlers/SAML2AttributeHandlerUnitTestCase.java
Modified:
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/impl/DefaultSAML2HandlerChainConfig.java
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/impl/DefaultSAML2HandlerRequest.java
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/interfaces/SAML2Handler.java
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/interfaces/SAML2HandlerRequest.java
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/filters/SPFilter.java
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/BaseSAML2Handler.java
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/RolesGenerationHandler.java
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/SAML2AttributeHandler.java
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/SAML2AuthenticationHandler.java
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/SAML2IssuerTrustHandler.java
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/SAML2LogOutHandler.java
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/servlets/IDPServlet.java
identity-federation/trunk/jboss-identity-web/src/test/resources/saml2/logout/idp/WEB-INF/jboss-idfed.xml
Log:
JBID-198: saml2 handler arch
Modified:
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/impl/DefaultSAML2HandlerChainConfig.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/impl/DefaultSAML2HandlerChainConfig.java 2009-10-12
17:45:53 UTC (rev 850)
+++
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/impl/DefaultSAML2HandlerChainConfig.java 2009-10-12
18:39:08 UTC (rev 851)
@@ -33,6 +33,10 @@
public class DefaultSAML2HandlerChainConfig extends BaseHandlerConfig
implements SAML2HandlerChainConfig
{
+ public DefaultSAML2HandlerChainConfig()
+ {
+ }
+
public DefaultSAML2HandlerChainConfig(Map<String,Object> map)
{
this.params = map;
Modified:
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/impl/DefaultSAML2HandlerRequest.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/impl/DefaultSAML2HandlerRequest.java 2009-10-12
17:45:53 UTC (rev 850)
+++
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/impl/DefaultSAML2HandlerRequest.java 2009-10-12
18:39:08 UTC (rev 851)
@@ -27,6 +27,7 @@
import org.jboss.identity.federation.core.interfaces.ProtocolContext;
import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerRequest;
+import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2Handler.HANDLER_TYPE;
import org.jboss.identity.federation.saml.v2.SAML2Object;
import org.jboss.identity.federation.saml.v2.assertion.NameIDType;
Modified:
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/interfaces/SAML2Handler.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/interfaces/SAML2Handler.java 2009-10-12
17:45:53 UTC (rev 850)
+++
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/interfaces/SAML2Handler.java 2009-10-12
18:39:08 UTC (rev 851)
@@ -33,6 +33,15 @@
public interface SAML2Handler
{
/**
+ * Processing Point - idp side
+ * or service side
+ */
+ public enum HANDLER_TYPE
+ {
+ IDP,SP;
+ };
+
+ /**
* Initialize the handler
* @param handlerConfig Handler Config
*/
@@ -55,7 +64,16 @@
*/
void generateSAMLRequest(SAML2HandlerRequest request,
SAML2HandlerResponse response) throws ProcessingException;
+
+
/**
+ * Get the type of handler
+ * - handler at IDP or SP
+ * @return
+ */
+ HANDLER_TYPE getType();
+
+ /**
* Handle a SAML2 RequestAbstractType
* @param requestAbstractType
* @param resultingDocument
Modified:
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/interfaces/SAML2HandlerRequest.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/interfaces/SAML2HandlerRequest.java 2009-10-12
17:45:53 UTC (rev 850)
+++
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/interfaces/SAML2HandlerRequest.java 2009-10-12
18:39:08 UTC (rev 851)
@@ -34,14 +34,6 @@
*/
public interface SAML2HandlerRequest
{
- /**
- * Processing Point - idp side
- * or service side
- */
- public enum HANDLER_TYPE
- {
- IDP,SP;
- };
public enum GENERATE_REQUEST_TYPE
{
@@ -60,13 +52,6 @@
* @return
*/
SAML2Object getSAML2Object();
-
- /**
- * Get the type of handler
- * - handler at IDP or SP
- * @return
- */
- HANDLER_TYPE getType();
/**
* Return the type of SAML request
Modified:
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/filters/SPFilter.java
===================================================================
---
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/filters/SPFilter.java 2009-10-12
17:45:53 UTC (rev 850)
+++
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/filters/SPFilter.java 2009-10-12
18:39:08 UTC (rev 851)
@@ -82,8 +82,8 @@
import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerChainConfig;
import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerRequest;
import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerResponse;
-import
org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerRequest.GENERATE_REQUEST_TYPE;
-import
org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerRequest.HANDLER_TYPE;
+import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2Handler.HANDLER_TYPE;
+import
org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerRequest.GENERATE_REQUEST_TYPE;
import org.jboss.identity.federation.core.saml.v2.util.AssertionUtil;
import org.jboss.identity.federation.core.saml.v2.util.DocumentUtil;
import org.jboss.identity.federation.core.saml.v2.util.HandlerUtil;
@@ -389,15 +389,15 @@
Handlers handlers =
ConfigurationUtil.getHandlers(context.getResourceAsStream("/WEB-INF/jbid-handlers.xml"));
chain.addAll(HandlerUtil.getHandlers(handlers));
- Map<String, Object> configOptions = new HashMap<String, Object>();
- configOptions.put(GeneralConstants.CONFIGURATION, spConfiguration);
+ Map<String, Object> chainConfigOptions = new HashMap<String,
Object>();
+ chainConfigOptions.put(GeneralConstants.CONFIGURATION, spConfiguration);
- SAML2HandlerChainConfig handlerConfig = new
DefaultSAML2HandlerChainConfig(configOptions);
+ SAML2HandlerChainConfig handlerChainConfig = new
DefaultSAML2HandlerChainConfig(chainConfigOptions);
Set<SAML2Handler> samlHandlers = chain.handlers();
for(SAML2Handler handler: samlHandlers)
{
- handler.initChainConfig(handlerConfig);
+ handler.initChainConfig(handlerChainConfig);
}
}
catch(Exception e)
Modified:
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/BaseSAML2Handler.java
===================================================================
---
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/BaseSAML2Handler.java 2009-10-12
17:45:53 UTC (rev 850)
+++
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/BaseSAML2Handler.java 2009-10-12
18:39:08 UTC (rev 851)
@@ -24,6 +24,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
+import org.jboss.identity.federation.core.config.IDPType;
import org.jboss.identity.federation.core.exceptions.ConfigurationException;
import org.jboss.identity.federation.core.exceptions.ProcessingException;
import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2Handler;
@@ -31,6 +32,7 @@
import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerConfig;
import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerRequest;
import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerResponse;
+import org.jboss.identity.federation.web.constants.GeneralConstants;
import org.jboss.identity.federation.web.core.HTTPContext;
/**
@@ -42,6 +44,7 @@
{
protected SAML2HandlerConfig handlerConfig = null;
protected SAML2HandlerChainConfig handlerChainConfig = null;
+ protected HANDLER_TYPE handlerType;
/**
* Initialize the handler
@@ -57,8 +60,24 @@
throws ConfigurationException
{
this.handlerChainConfig = handlerChainConfig;
+ Object config =
this.handlerChainConfig.getParameter(GeneralConstants.CONFIGURATION);
+ if(config instanceof IDPType)
+ this.handlerType = HANDLER_TYPE.IDP;
+ else
+ this.handlerType = HANDLER_TYPE.SP;
}
+
+ /**
+ * Get the type of handler
+ * - handler at IDP or SP
+ * @return
+ */
+ public HANDLER_TYPE getType()
+ {
+ return this.handlerType;
+ }
+
public void reset() throws ProcessingException
{
}
Modified:
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/RolesGenerationHandler.java
===================================================================
---
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/RolesGenerationHandler.java 2009-10-12
17:45:53 UTC (rev 850)
+++
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/RolesGenerationHandler.java 2009-10-12
18:39:08 UTC (rev 851)
@@ -86,7 +86,7 @@
return ;
//only handle IDP side
- if(request.getType() == SAML2HandlerRequest.HANDLER_TYPE.SP)
+ if(getType() == HANDLER_TYPE.SP)
return;
HTTPContext httpContext = (HTTPContext) request.getContext();
Modified:
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/SAML2AttributeHandler.java
===================================================================
---
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/SAML2AttributeHandler.java 2009-10-12
17:45:53 UTC (rev 850)
+++
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/SAML2AttributeHandler.java 2009-10-12
18:39:08 UTC (rev 851)
@@ -85,12 +85,12 @@
@SuppressWarnings("unchecked")
public void handleRequestType(SAML2HandlerRequest request, SAML2HandlerResponse
response) throws ProcessingException
{
- //Do not handle log out request interaction
+ //Do not handle log out request interaction
if(request.getSAML2Object() instanceof LogoutRequestType)
return ;
//only handle IDP side
- if(request.getType() == SAML2HandlerRequest.HANDLER_TYPE.SP)
+ if(getType() == HANDLER_TYPE.SP)
return;
HTTPContext httpContext = (HTTPContext) request.getContext();
Modified:
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/SAML2AuthenticationHandler.java
===================================================================
---
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/SAML2AuthenticationHandler.java 2009-10-12
17:45:53 UTC (rev 850)
+++
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/SAML2AuthenticationHandler.java 2009-10-12
18:39:08 UTC (rev 851)
@@ -80,7 +80,7 @@
if(request.getSAML2Object() instanceof AuthnRequestType == false)
return ;
- if(request.getType() == SAML2HandlerRequest.HANDLER_TYPE.IDP)
+ if(getType() == HANDLER_TYPE.IDP)
{
idp.handleRequestType(request, response);
}
@@ -96,7 +96,7 @@
if(request.getSAML2Object() instanceof ResponseType == false)
return ;
- if(request.getType() == SAML2HandlerRequest.HANDLER_TYPE.IDP)
+ if(getType() == HANDLER_TYPE.IDP)
{
idp.handleStatusResponseType(request, response);
}
@@ -112,7 +112,7 @@
if(GENERATE_REQUEST_TYPE.AUTH != request.getTypeOfRequestToBeGenerated())
return;
- if(request.getType() == SAML2HandlerRequest.HANDLER_TYPE.IDP)
+ if(getType() == HANDLER_TYPE.IDP)
{
idp.generateSAMLRequest(request, response);
}
Modified:
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/SAML2IssuerTrustHandler.java
===================================================================
---
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/SAML2IssuerTrustHandler.java 2009-10-12
17:45:53 UTC (rev 850)
+++
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/SAML2IssuerTrustHandler.java 2009-10-12
18:39:08 UTC (rev 851)
@@ -51,7 +51,7 @@
public void handleRequestType(SAML2HandlerRequest request, SAML2HandlerResponse
response) throws ProcessingException
{
- if(request.getType() == SAML2HandlerRequest.HANDLER_TYPE.IDP)
+ if(getType() == HANDLER_TYPE.IDP)
{
idp.handleRequestType(request, response);
}
@@ -64,7 +64,7 @@
public void handleStatusResponseType(SAML2HandlerRequest request, SAML2HandlerResponse
response)
throws ProcessingException
{
- if(request.getType() == SAML2HandlerRequest.HANDLER_TYPE.IDP)
+ if(getType() == HANDLER_TYPE.IDP)
{
idp.handleStatusResponseType(request, response);
}
Modified:
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/SAML2LogOutHandler.java
===================================================================
---
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/SAML2LogOutHandler.java 2009-10-12
17:45:53 UTC (rev 850)
+++
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/handlers/saml2/SAML2LogOutHandler.java 2009-10-12
18:39:08 UTC (rev 851)
@@ -86,7 +86,7 @@
return;
- if(request.getType() == SAML2HandlerRequest.HANDLER_TYPE.IDP)
+ if(getType() == HANDLER_TYPE.IDP)
{
idp.generateSAMLRequest(request, response);
}
@@ -105,7 +105,7 @@
if(request.getSAML2Object() instanceof LogoutRequestType == false)
return ;
- if(request.getType() == SAML2HandlerRequest.HANDLER_TYPE.IDP)
+ if(getType() == HANDLER_TYPE.IDP)
{
idp.handleRequestType(request, response);
}
@@ -129,7 +129,7 @@
if(request.getSAML2Object() instanceof StatusResponseType == false)
return ;
- if(request.getType() == SAML2HandlerRequest.HANDLER_TYPE.IDP)
+ if(getType() == HANDLER_TYPE.IDP)
{
idp.handleStatusResponseType(request, response);
}
Modified:
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/servlets/IDPServlet.java
===================================================================
---
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/servlets/IDPServlet.java 2009-10-12
17:45:53 UTC (rev 850)
+++
identity-federation/trunk/jboss-identity-web/src/main/java/org/jboss/identity/federation/web/servlets/IDPServlet.java 2009-10-12
18:39:08 UTC (rev 851)
@@ -66,8 +66,8 @@
import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerChain;
import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerChainConfig;
import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerRequest;
-import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerResponse;
-import
org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerRequest.HANDLER_TYPE;
+import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerResponse;
+import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2Handler.HANDLER_TYPE;
import org.jboss.identity.federation.core.saml.v2.util.HandlerUtil;
import org.jboss.identity.federation.saml.v2.SAML2Object;
import org.jboss.identity.federation.saml.v2.protocol.RequestAbstractType;
@@ -93,7 +93,7 @@
protected transient IDPType idpConfiguration = null;
- private transient RoleGenerator rg = new DefaultRoleGenerator();
+ private transient RoleGenerator roleGenerator = new DefaultRoleGenerator();
private transient DelegatedAttributeManager attribManager = new
DelegatedAttributeManager();
@@ -152,15 +152,16 @@
handlers =
ConfigurationUtil.getHandlers(context.getResourceAsStream("/WEB-INF/jbid-handlers.xml"));
chain.addAll(HandlerUtil.getHandlers(handlers));
- Map<String, Object> configOptions = new HashMap<String, Object>();
- configOptions.put(GeneralConstants.ROLE_GENERATOR, rg);
+ Map<String, Object> chainConfigOptions = new HashMap<String,
Object>();
+ chainConfigOptions.put(GeneralConstants.ROLE_GENERATOR, roleGenerator);
+ chainConfigOptions.put(GeneralConstants.CONFIGURATION, idpConfiguration);
- SAML2HandlerChainConfig handlerConfig = new
DefaultSAML2HandlerChainConfig(configOptions);
+ SAML2HandlerChainConfig handlerChainConfig = new
DefaultSAML2HandlerChainConfig(chainConfigOptions);
Set<SAML2Handler> samlHandlers = chain.handlers();
for(SAML2Handler handler: samlHandlers)
{
- handler.initChainConfig(handlerConfig);
+ handler.initChainConfig(handlerChainConfig);
}
}
@@ -355,7 +356,7 @@
saml2HandlerRequest.setRelayState(relayState);
Map<String, Object> requestOptions = new HashMap<String,
Object>();
- requestOptions.put(GeneralConstants.ROLE_GENERATOR, rg);
+ requestOptions.put(GeneralConstants.ROLE_GENERATOR, roleGenerator);
requestOptions.put(GeneralConstants.ASSERTIONS_VALIDITY,
this.assertionValidity);
requestOptions.put(GeneralConstants.CONFIGURATION,
this.idpConfiguration);
Map<String,Object> attribs =
this.attribManager.getAttributes(userPrincipal, attributeKeys);
@@ -366,7 +367,7 @@
List<String> roles = (List<String>)
session.getAttribute(GeneralConstants.ROLES_ID);
if(roles == null)
{
- roles = rg.generateRoles(userPrincipal);
+ roles = roleGenerator.generateRoles(userPrincipal);
session.setAttribute(GeneralConstants.ROLES_ID, roles);
}
@@ -620,7 +621,7 @@
try
{
Class<?> clazz =
SecurityActions.getContextClassLoader().loadClass(rgName);
- rg = (RoleGenerator) clazz.newInstance();
+ roleGenerator = (RoleGenerator) clazz.newInstance();
}
catch (Exception e)
{
Added:
identity-federation/trunk/jboss-identity-web/src/test/java/org/jboss/test/identity/federation/web/saml/handlers/SAML2AttributeHandlerUnitTestCase.java
===================================================================
---
identity-federation/trunk/jboss-identity-web/src/test/java/org/jboss/test/identity/federation/web/saml/handlers/SAML2AttributeHandlerUnitTestCase.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-web/src/test/java/org/jboss/test/identity/federation/web/saml/handlers/SAML2AttributeHandlerUnitTestCase.java 2009-10-12
18:39:08 UTC (rev 851)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jboss.test.identity.federation.web.saml.handlers;
+
+import java.security.Principal;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.jboss.identity.federation.core.config.IDPType;
+import org.jboss.identity.federation.core.constants.AttributeConstants;
+import org.jboss.identity.federation.core.interfaces.AttributeManager;
+import org.jboss.identity.federation.core.saml.v2.holders.IssuerInfoHolder;
+import org.jboss.identity.federation.core.saml.v2.impl.DefaultSAML2HandlerChainConfig;
+import org.jboss.identity.federation.core.saml.v2.impl.DefaultSAML2HandlerConfig;
+import org.jboss.identity.federation.core.saml.v2.impl.DefaultSAML2HandlerRequest;
+import org.jboss.identity.federation.core.saml.v2.impl.DefaultSAML2HandlerResponse;
+import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2Handler;
+import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerChainConfig;
+import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerConfig;
+import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerRequest;
+import org.jboss.identity.federation.core.saml.v2.interfaces.SAML2HandlerResponse;
+import org.jboss.identity.federation.saml.v2.SAML2Object;
+import org.jboss.identity.federation.web.constants.GeneralConstants;
+import org.jboss.identity.federation.web.core.HTTPContext;
+import org.jboss.identity.federation.web.handlers.saml2.SAML2AttributeHandler;
+import org.jboss.test.identity.federation.web.mock.MockHttpServletRequest;
+import org.jboss.test.identity.federation.web.mock.MockHttpServletResponse;
+import org.jboss.test.identity.federation.web.mock.MockHttpSession;
+import org.jboss.test.identity.federation.web.mock.MockServletContext;
+
+/**
+ * Unit test the {@code SAML2AttributeHandler}
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Oct 12, 2009
+ */
+public class SAML2AttributeHandlerUnitTestCase extends TestCase
+{
+ private static String name = "anil";
+ private static String email = "anil@test";
+
+ @SuppressWarnings("unchecked")
+ public void testAttributes() throws Exception
+ {
+ SAML2AttributeHandler handler = new SAML2AttributeHandler();
+
+ SAML2HandlerChainConfig chainConfig = new DefaultSAML2HandlerChainConfig();
+ SAML2HandlerConfig handlerConfig = new DefaultSAML2HandlerConfig();
+
+ Map<String,Object> chainOptions = new HashMap<String, Object>();
+ IDPType idpType = new IDPType();
+ idpType.setAttributeManager(TestAttributeManager.class.getName());
+ chainOptions.put(GeneralConstants.CONFIGURATION, idpType);
+ 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);
+
+ SAML2Object saml2Object = new SAML2Object(){};
+
+ IssuerInfoHolder issuerInfo = new
IssuerInfoHolder("http://localhost:8080/idp/");
+ SAML2HandlerRequest request = new DefaultSAML2HandlerRequest(httpContext,
+ issuerInfo.getIssuer(), saml2Object, SAML2Handler.HANDLER_TYPE.IDP);
+ SAML2HandlerResponse response = new DefaultSAML2HandlerResponse();
+
+ session.setAttribute(GeneralConstants.PRINCIPAL_ID, new Principal()
+ {
+ public String getName()
+ {
+ return name;
+ }});
+ handler.handleRequestType(request, response);
+
+ Map<String, Object> attribs = (Map<String, Object>)
session.getAttribute(GeneralConstants.ATTRIBUTES);
+ assertNotNull("Attributes are not null", attribs);
+ assertEquals(email,attribs.get(AttributeConstants.EMAIL_ADDRESS));
+ }
+
+ public static class TestAttributeManager implements AttributeManager
+ {
+ public Map<String, Object> getAttributes(Principal userPrincipal,
List<String> attributeKeys)
+ {
+ Map<String,Object> attribs = new HashMap<String, Object>();
+
+ if(name.equals(userPrincipal.getName()))
+ {
+ attribs.put(AttributeConstants.EMAIL_ADDRESS, email);
+ }
+ return attribs;
+ }
+ }
+}
\ No newline at end of file
Modified:
identity-federation/trunk/jboss-identity-web/src/test/resources/saml2/logout/idp/WEB-INF/jboss-idfed.xml
===================================================================
---
identity-federation/trunk/jboss-identity-web/src/test/resources/saml2/logout/idp/WEB-INF/jboss-idfed.xml 2009-10-12
17:45:53 UTC (rev 850)
+++
identity-federation/trunk/jboss-identity-web/src/test/resources/saml2/logout/idp/WEB-INF/jboss-idfed.xml 2009-10-12
18:39:08 UTC (rev 851)
@@ -1,5 +1,6 @@
<JBossIDP xmlns="urn:jboss:identity-federation:config:1.0"
- AttributeManager="">
+ AttributeManager=""
+
RoleGenerator="org.jboss.identity.federation.core.impl.EmptyRoleGenerator">
<IdentityURL>http://localhost:8080/idp/</IdentityURL>
</JBossIDP>