Author: chintana Date: Wed Sep 23 13:48:12 2009 New Revision: 818102 URL: http://svn.apache.org/viewvc?rev=818102&view=rev Log: WSO2 Carbon component that should be deployed on WSO2 Identity Server to add the custome SAML attribute "privatepersonalidentifier".
Added: incubator/stonehenge/trunk/stocktrader/wsas/identity/ incubator/stonehenge/trunk/stocktrader/wsas/identity/lib/ incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/ incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/pom.xml incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/ incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/main/ incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/main/java/ incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/main/java/org/ incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/main/java/org/wso2/ incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/main/java/org/wso2/carbon/ incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/main/java/org/wso2/carbon/identity/ incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/main/java/org/wso2/carbon/identity/stonehenge/ incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/main/java/org/wso2/carbon/identity/stonehenge/attributeservice/ incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/main/java/org/wso2/carbon/identity/stonehenge/attributeservice/StonehengeAttributeService.java incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/main/java/org/wso2/carbon/identity/stonehenge/attributeservice/internal/ incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/main/java/org/wso2/carbon/identity/stonehenge/attributeservice/internal/CustomAttributeServiceComponent.java incubator/stonehenge/trunk/stocktrader/wsas/identity/pom.xml Added: incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/pom.xml URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/pom.xml?rev=818102&view=auto ============================================================================== --- incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/pom.xml (added) +++ incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/pom.xml Wed Sep 23 13:48:12 2009 @@ -0,0 +1,167 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ + ~ Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + ~ + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <parent> + <groupId>org.wso2.carbon.identity.stonehenge</groupId> + <artifactId>identity-stonehenge-parent</artifactId> + <version>2.0.0.SNAPSHOT</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + <groupId>org.wso2.carbon.identity.stonehenge</groupId> + <artifactId>org.wso2.carbon.identity.stonehenge.attributeservice</artifactId> + <packaging>bundle</packaging> + <version>2.0.0.SNAPSHOT</version> + <name>WSO2 Carbon - Identity Attribute Service for Stonehenge</name> + <description>A custom wso2 products or service</description> + <url>http://www.wso2.com</url> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.0</version> + <configuration> + <source>1.5</source> + <target>1.5</target> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-scr-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <version>1.4.0</version> + <extensions>true</extensions> + <configuration> + <instructions> + <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName> + <Bundle-Name>${pom.artifactId}</Bundle-Name> + <Private-Package>org.wso2.carbon.identity.stonehenge.attributeservice.internal</Private-Package> + <Export-Package> + org.wso2.carbon.identity.stonehenge.attributeservice, + </Export-Package> + <Import-Package> + !org.wso2.carbon.identity.stonehenge.attributeservice, + org.wso2.carbon.identity.provider.*, + org.osgi.framework, + org.apache.axis2.*; version="${axis2.osgi.version.range}", + </Import-Package> + <DynamicImport-Package>*</DynamicImport-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + + <dependencies> + + <dependency> + <groupId>org.eclipse.osgi</groupId> + <artifactId>org.eclipse.osgi</artifactId> + <version>3.5.0.v20090520</version> + </dependency> + + <dependency> + <groupId>org.eclipse.osgi</groupId> + <artifactId>org.eclipse.osgi.services</artifactId> + <version>3.2.0.v20090520-1800</version> + </dependency> + + <dependency> + <groupId>org.eclipse.equinox</groupId> + <artifactId>org.eclipse.equinox.common</artifactId> + <version>3.5.0.v20090520-1800</version> + </dependency> + + <dependency> + <groupId>org.eclipse.equinox</groupId> + <artifactId>org.eclipse.equinox.ds</artifactId> + <version>1.1.0.v20090520-1800</version> + </dependency> + + <dependency> + <groupId>opensaml</groupId> + <artifactId>opensaml</artifactId> + <version>1.1.406</version> + </dependency> + + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>1.1.1</version> + </dependency> + + <dependency> + <groupId>org.wso2.carbon</groupId> + <artifactId>org.wso2.carbon.identity.provider</artifactId> + <version>2.0.0</version> + <scope>system</scope> + <systemPath>${basedir}/../lib/org.wso2.carbon.identity.provider-2.0.1.jar</systemPath> + </dependency> + + <dependency> + <groupId>org.wso2.carbon</groupId> + <artifactId>org.wso2.carbon.security.rampart</artifactId> + <version>2.0.0</version> + <scope>system</scope> + <systemPath>${basedir}/../lib/org.wso2.carbon.security.rampart-2.0.1.jar</systemPath> + </dependency> + + <dependency> + <groupId>org.apache.ws.commons.axiom.wso2</groupId> + <artifactId>axiom</artifactId> + <version>1.2.7.wso2v1</version> + <scope>system</scope> + <systemPath>${basedir}/../lib/axiom-1.2.7.wso2v1.jar</systemPath> + </dependency> + + <dependency> + <groupId>opensaml.wso2</groupId> + <artifactId>opensaml2</artifactId> + <version>2.0.0.alpha1-wso2v1</version> + <scope>system</scope> + <systemPath>${basedir}/../lib/opensaml2-2.0.0.alpha1-wso2v1.jar</systemPath> + </dependency> + + <dependency> + <groupId>org.apache.axis2.wso2</groupId> + <artifactId>axis2</artifactId> + <version>1.5.0.wso2v1</version> + <scope>system</scope> + <systemPath>${basedir}/../lib/axis2-1.5.0.wso2v2.jar</systemPath> + </dependency> + + <dependency> + <groupId>org.wso2.carbon</groupId> + <artifactId>org.wso2.carbon.security.rahas</artifactId> + <version>2.0.0</version> + <scope>system</scope> + <systemPath>${basedir}/../lib/org.wso2.carbon.security.rahas-2.0.1.jar</systemPath> + </dependency> + </dependencies> + +</project> Added: incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/main/java/org/wso2/carbon/identity/stonehenge/attributeservice/StonehengeAttributeService.java URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/main/java/org/wso2/carbon/identity/stonehenge/attributeservice/StonehengeAttributeService.java?rev=818102&view=auto ============================================================================== --- incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/main/java/org/wso2/carbon/identity/stonehenge/attributeservice/StonehengeAttributeService.java (added) +++ incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/main/java/org/wso2/carbon/identity/stonehenge/attributeservice/StonehengeAttributeService.java Wed Sep 23 13:48:12 2009 @@ -0,0 +1,132 @@ +package org.wso2.carbon.identity.stonehenge.attributeservice; + +import java.util.Arrays; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.soap.SOAPEnvelope; +import org.apache.axiom.soap.SOAPHeader; +import org.apache.axiom.soap.SOAPHeaderBlock; +import org.apache.axis2.context.MessageContext; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.rahas.RahasConstants; +import org.apache.rahas.RahasData; +import org.apache.rahas.impl.util.SAMLAttributeCallback; +import org.opensaml.Configuration; +import org.opensaml.SAMLAttribute; +import org.opensaml.SAMLException; +import org.opensaml.common.SAMLObjectBuilder; +import org.opensaml.saml2.core.Attribute; +import org.opensaml.saml2.core.AttributeValue; +import org.opensaml.xml.XMLObjectBuilderFactory; +import org.opensaml.xml.schema.XSString; +import org.opensaml.xml.schema.impl.XSStringBuilder; +import org.wso2.carbon.identity.provider.IdentityAttributeService; + +public class StonehengeAttributeService implements IdentityAttributeService { + + private static final String WSSE_NS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"; + private static final String WSSE_LN = "Security"; + private static final String USERNAME_TOKEN_LN = "UsernameToken"; + private static final String PASSWORD_LN = "Password"; + private static final QName SEC_HEADER = new QName(WSSE_NS, WSSE_LN); + private static final QName USERNAME_TOKEN = new QName(WSSE_NS, USERNAME_TOKEN_LN); + private static final QName PASSWORD = new QName(WSSE_NS, PASSWORD_LN); + + private static Log log = LogFactory.getLog(StonehengeAttributeService.class); + + public void handle(SAMLAttributeCallback attrCallback) throws SAMLException { + log.info("StonehengeAttributeService being called"); + RahasData data = null; + String userIdentifier = null; + String password = null; + + try { + data = attrCallback.getData(); + userIdentifier = data.getPrincipal().getName(); + password = getUserCredentials(MessageContext.getCurrentMessageContext().getEnvelope()); + log.info("User Identifier : " + userIdentifier); + log.info("User Password : " + password); + + if (RahasConstants.TOK_TYPE_SAML_20.equals(data.getTokenType())) { + if (attrCallback.getSAML2Attributes() != null + || attrCallback.getSAML2Attributes().length > 0) { + Attribute[] attributes = attrCallback.getSAML2Attributes(); + for (int i = 0; i < attributes.length; i++) { + log.info(attributes[i].getName()); + // Overriding and filtering. + if ("First Name".equals(attributes[i].getName())) { + attributes[i].setName("New Name"); + } + } + } + attrCallback.addAttributes(getSAML2Attribute("Custom Attribute", "Sample Value", "http://wso2.org/claims/customAttribute")); + } else { + // Retrieving all attribute values set before. + if (attrCallback.getAttributes() != null || attrCallback.getAttributes().length > 0) { + SAMLAttribute[] attributes = attrCallback.getAttributes(); + for (int i = 0; i < attributes.length; i++) { + log.info(attributes[i].toString()); + // Overriding and filtering. + if ("First Name".equals(attributes[i].getName())) { + attributes[i].setValues(Arrays.asList(new String[]{"New Name"})); + } + } + } + } + } catch (Exception e) { + log.error("Error occuerd while populating claim data", e); + } + } + + private Attribute getSAML2Attribute(String name, String value, String namespace) { + XMLObjectBuilderFactory builderFactory = null; + SAMLObjectBuilder<Attribute> attrBuilder = null; + Attribute attribute = null; + XSStringBuilder attributeValueBuilder = null; + XSString stringValue = null; + + builderFactory = Configuration.getBuilderFactory(); + attrBuilder = (SAMLObjectBuilder<Attribute>) builderFactory + .getBuilder(Attribute.DEFAULT_ELEMENT_NAME); + attribute = attrBuilder.buildObject(); + attribute.setName(name); + attribute.setNameFormat(namespace); + + attributeValueBuilder = (XSStringBuilder) builderFactory.getBuilder(XSString.TYPE_NAME); + stringValue = attributeValueBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, + XSString.TYPE_NAME); + stringValue.setValue(value); + attribute.getAttributeValues().add(stringValue); + return attribute; + } + + private String getUserCredentials(SOAPEnvelope envelope) { + SOAPHeaderBlock secHeader = null; + OMElement usernameToken = null; + + secHeader = getSecHeader(envelope); + if (secHeader == null) { + return null; + } + + usernameToken = secHeader.getFirstChildWithName(USERNAME_TOKEN); + if (usernameToken != null) { + OMElement userElem = usernameToken.getFirstChildWithName(PASSWORD); + if (userElem != null) { + return userElem.getText().trim(); + } + } + return null; + } + + private SOAPHeaderBlock getSecHeader(SOAPEnvelope envelope) { + SOAPHeader header = envelope.getHeader(); + if (header != null) { + return (SOAPHeaderBlock) header.getFirstChildWithName(SEC_HEADER); + } + return null; + } +} Added: incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/main/java/org/wso2/carbon/identity/stonehenge/attributeservice/internal/CustomAttributeServiceComponent.java URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/main/java/org/wso2/carbon/identity/stonehenge/attributeservice/internal/CustomAttributeServiceComponent.java?rev=818102&view=auto ============================================================================== --- incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/main/java/org/wso2/carbon/identity/stonehenge/attributeservice/internal/CustomAttributeServiceComponent.java (added) +++ incubator/stonehenge/trunk/stocktrader/wsas/identity/org.wso2.carbon.identity.stonehenge.attributeservice/src/main/java/org/wso2/carbon/identity/stonehenge/attributeservice/internal/CustomAttributeServiceComponent.java Wed Sep 23 13:48:12 2009 @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.wso2.carbon.identity.stonehenge.attributeservice.internal; + +import org.wso2.carbon.identity.provider.IdentityAttributeService; +import org.wso2.carbon.identity.stonehenge.attributeservice.StonehengeAttributeService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.service.component.ComponentContext; + +import java.util.Properties; + +/** + * @scr.component name="org.wso2.carbon.identity.samples.attributeservice" immediate="true" + */ +public class CustomAttributeServiceComponent { + private static Log log = LogFactory.getLog(CustomAttributeServiceComponent.class); + + public CustomAttributeServiceComponent() { + } + + protected void activate(ComponentContext ctxt) { + Properties props; + + try { + // This should ideally contain properties of MailTransportService as + // a collection of key/value pair. Here we do not require to add any elements. + props = new Properties(); + // Register the StonehengeAttributeService under IdentityAttributeService interface. + ctxt.getBundleContext().registerService(IdentityAttributeService.class.getName(), + new StonehengeAttributeService(), props); + + if (log.isDebugEnabled()) { + log.debug("Successfully registered the StonehengeAttributeService service"); + } + } catch (Throwable e) { + String message = null; + message = "Error while activating the org.wso2.carbon.identity.stonehenge.attributeservice bundle"; + log.error(message, e); + } + } + + protected void deactivate(ComponentContext ctxt) { + if (log.isDebugEnabled()) { + log.debug("org.wso2.carbon.identity.stonehenge.attributeservice bundle is deactivated"); + } + } +} \ No newline at end of file Added: incubator/stonehenge/trunk/stocktrader/wsas/identity/pom.xml URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/identity/pom.xml?rev=818102&view=auto ============================================================================== --- incubator/stonehenge/trunk/stocktrader/wsas/identity/pom.xml (added) +++ incubator/stonehenge/trunk/stocktrader/wsas/identity/pom.xml Wed Sep 23 13:48:12 2009 @@ -0,0 +1,100 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + <groupId>org.wso2.carbon.identity.stonehenge</groupId> + <artifactId>identity-stonehenge-parent</artifactId> + <packaging>pom</packaging> + <version>2.0.0.SNAPSHOT</version> + <name>WSO2 Identity Server Stonehenge - Parent Maven Module</name> + <description>identity-stonehenge-parent</description> + <url>http://wso2.org</url> + + <repositories> + <repository> + <id>wso2-maven2-repository</id> + <url>http://dist.wso2.org/maven2</url> + </repository> + <repository> + <id>apache-Incubating-repo</id> + <name>Maven Incubating Repository</name> + <url>http://people.apache.org/repo/m2-incubating-repository</url> + </repository> + <repository> + <id>apache-maven2-repo</id> + <name>Apache Maven2 Repository</name> + <url>http://repo1.maven.org/maven2/</url> + </repository> + </repositories> + + <pluginRepositories> + <pluginRepository> + <id>wso2-maven2-repository</id> + <url>http://dist.wso2.org/maven2</url> + </pluginRepository> + </pluginRepositories> + + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-scr-plugin</artifactId> + <version>1.0.10</version> + <executions> + <execution> + <id>generate-scr-scrdescriptor</id> + <goals> + <goal>scr</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.5</source> + <target>1.5</target> + </configuration> + </plugin> + </plugins> + </build> + + <modules> + <module>org.wso2.carbon.identity.stonehenge.attributeservice</module> + </modules> + + <properties> + <wso2carbon.version>${pom.version}</wso2carbon.version> + <server.name>WSO2Carbon</server.name> + <server.version>${pom.version}</server.version> + <axis2.transport.version>1.0.0.wso2v1</axis2.transport.version> + <axiom.version>1.2.7</axiom.version> + <tomcat.version>6.0.16</tomcat.version> + <jakarta.taglib.version>1.1.2</jakarta.taglib.version> + <sourceforge.ajaxtags.version>1.3.0.beta-rc7</sourceforge.ajaxtags.version> + <addressing.version>1.5</addressing.version> + <rampart.mar.version>1.41</rampart.mar.version> + <axis2.osgi.version>1.4.1.wso2</axis2.osgi.version> + <wss4j.version>1.5.4</wss4j.version> + <derby.version>10.2.2.0</derby.version> + <neethi.version>2.0.4</neethi.version> + <stax.version>1.0.1</stax.version> + <spring.version>2.5.1</spring.version> + <h2.engine.version>1.1.112</h2.engine.version> + <wso2.h2.orbit.version>${h2.engine.version}.wso2v1</wso2.h2.orbit.version> + + <axis2.version>1.5-wso2v1</axis2.version> + <axis2.orbit.version>1.5.0.wso2v1</axis2.orbit.version> + <axis2.osgi.version.range>[1.5.0.wso2, 1.6.0)</axis2.osgi.version.range> + <axiom.osgi.version.range>[1.2.8, 1.3.0)</axiom.osgi.version.range> + <neethi.osgi.version.range>[2.0.4, 3.0.0)</neethi.osgi.version.range> + </properties> + + +</project>