You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2011/09/20 17:57:20 UTC
svn commit: r1173209 [38/49] - in /abdera/abdera2: ./ .settings/ activities/
activities/src/ activities/src/main/ activities/src/main/java/
activities/src/main/java/org/ activities/src/main/java/org/apache/
activities/src/main/java/org/apache/abdera2/ ...
Added: abdera/abdera2/pom.xml
URL: http://svn.apache.org/viewvc/abdera/abdera2/pom.xml?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/pom.xml (added)
+++ abdera/abdera2/pom.xml Tue Sep 20 15:56:46 2011
@@ -0,0 +1,576 @@
+<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.apache.abdera2</groupId>
+ <artifactId>abdera2</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Abdera2</name>
+ <version>2.0-SNAPSHOT</version>
+ <description>Atom Specification Implementation</description>
+ <inceptionYear>2006</inceptionYear>
+ <url>http://abdera.apache.org</url>
+
+ <organization>
+ <name>Apache Software Foundation</name>
+ <url>http://www.apache.org/</url>
+ </organization>
+
+ <issueManagement>
+ <system>JIRA</system>
+ <url>https://issues.apache.org/jira/browse/ABDERA</url>
+ </issueManagement>
+
+ <mailingLists>
+ <mailingList>
+ <name>Abdera Developer List</name>
+ <subscribe>dev-subscribe@abdera.apache.org</subscribe>
+ <unsubscribe>dev-unsubscribe@abdera.apache.org</unsubscribe>
+ <post>dev@abdera.apache.org</post>
+ <archive>http://mail-archives.apache.org/mod_mbox/abdera-dev/</archive>
+ </mailingList>
+ <mailingList>
+ <name>Abdera User List</name>
+ <subscribe>user-subscribe@abdera.apache.org</subscribe>
+ <unsubscribe>user-unsubscribe@abdera.apache.org</unsubscribe>
+ <post>user@abdera.apache.org</post>
+ <archive>http://mail-archives.apache.org/mod_mbox/abdera-user/</archive>
+ </mailingList>
+ <mailingList>
+ <name>Abdera Source Control List</name>
+ <subscribe>commits-subscribe@abdera.apache.org</subscribe>
+ <unsubscribe>commits-unsubscribe@abdera.apache.org</unsubscribe>
+ <archive>http://mail-archives.apache.org/mod_mbox/abdera-commits/</archive>
+ </mailingList>
+ </mailingLists>
+
+ <licenses>
+ <license>
+ <name>The Apache Software License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/abdera/java/tags/abdera-2.0</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/abdera/java/tags/abdera-2.0</developerConnection>
+ <url>http://svn.apache.org/repos/asf/abdera/java/tags/abdera-2.0</url>
+ </scm>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.7</version>
+ <configuration>
+ <source>1.5</source>
+ <links>
+ <link>http://java.sun.com/j2se/1.5.0/docs/api/</link>
+ </links>
+ <aggregate>true</aggregate>
+ <excludePackageNames></excludePackageNames>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jxr-plugin</artifactId>
+ <version>2.2</version>
+ <configuration>
+ <aggregate>true</aggregate>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-report-plugin</artifactId>
+ <version>2.6</version>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>cobertura-maven-plugin</artifactId>
+ <version>2.4</version>
+ </plugin>
+ </plugins>
+ </reporting>
+
+ <build>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.2</version>
+ <configuration>
+ <archive>
+ <manifestEntries>
+ <Specification-Title>${project.name}</Specification-Title>
+ <Specification-Vendor>The Apache Software Foundation</Specification-Vendor>
+ <Specification-Version>${project.version}</Specification-Version>
+ <Implementation-Title>${project.name}</Implementation-Title>
+ <Implementation-Vendor-Id>org.apache</Implementation-Vendor-Id>
+ <Implementation-Vendor>The Apache Software Foundation</Implementation-Vendor>
+ <Implementation-Version>${project.version}</Implementation-Version>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-release-plugin</artifactId>
+ <version>2.1</version>
+ <configuration>
+ <tagBase>https://svn.apache.org/repos/asf/abdera/java/tags</tagBase>
+ <useReleaseProfile>false</useReleaseProfile>
+ <preparationGoals>clean install</preparationGoals>
+ <goals>deploy</goals>
+ <arguments>-Pdeploy</arguments>
+ <autoVersionSubmodules>true</autoVersionSubmodules>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-remote-resources-plugin</artifactId>
+ <version>1.0</version>
+ <executions>
+ <execution>
+ <id>compile</id>
+ <goals>
+ <goal>process</goal>
+ </goals>
+ <configuration>
+ <resourceBundles>
+ <resourceBundle>org.apache:apache-jar-resource-bundle:1.3</resourceBundle>
+ </resourceBundles>
+ <supplementalModels>
+ <supplementalModel>${topDir}/etc/notice-supplements.xml</supplementalModel>
+ </supplementalModels>
+ <properties>
+ <projectName>Apache Abdera2</projectName>
+ </properties>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>cobertura-maven-plugin</artifactId>
+ <version>2.4</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>clean</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <version>2.1.2</version>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>2.1.0</version>
+ <extensions>true</extensions>
+ <inherited>true</inherited>
+ <configuration>
+ <instructions>
+ <Export-Package>${abdera.osgi.exports}</Export-Package>
+ <Import-Package>${abdera.osgi.imports}</Import-Package>
+ <Embed-Dependency>${abdera.osgi.embed.dependencies}</Embed-Dependency>
+ <_versionpolicy>[$(version;==;$(@)),$(version;+;$(@)))</_versionpolicy>
+ </instructions>
+ <versions>
+ <abdera.osgi.version.clean>${project.version}</abdera.osgi.version.clean>
+ </versions>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>cleanVersions</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.6</version>
+ <configuration>
+ <excludes>
+ <exclude>**/*TestSuite*</exclude>
+ <exclude>**/*$*</exclude>
+ <exclude>**/TestAdapter*</exclude>
+ <exclude>**/TestChannelServlet*</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-gpg-plugin</artifactId>
+ <version>1.1</version>
+ <executions>
+ <execution>
+ <id>sign-artifacts</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>sign</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <version>0.6</version>
+ </plugin>
+
+ <plugin>
+ <groupId>com.google.code.maven-license-plugin</groupId>
+ <artifactId>maven-license-plugin</artifactId>
+ <version>1.4.0</version>
+ <configuration>
+ <basedir>${basedir}</basedir>
+ <header>${basedir}/etc/license.txt</header>
+ <quiet>false</quiet>
+ <failIfMissing>true</failIfMissing>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
+ </build>
+
+ <profiles>
+ <profile>
+ <id>java6</id>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.7</version>
+ <configuration>
+ <source>1.6</source>
+ <links>
+ <link>http://java.sun.com/javase/6/docs/api/</link>
+ </links>
+ <aggregate>true</aggregate>
+ <excludePackageNames></excludePackageNames>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ </profile>
+ <profile>
+ <id>deploy</id>
+ <modules>
+ <module>distribution</module>
+ </modules>
+ </profile>
+ <profile>
+ <id>no-online-tests</id>
+ <activation>
+ <property>
+ <name>offline-tests</name>
+ <value>false</value>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>**/*TestSuite*</exclude>
+ <exclude>**/*$*</exclude>
+ <exclude>**/*TestAdapter*</exclude>
+ <exclude>**/FeedValidatorTest.java</exclude>
+ <exclude>**/DSigThirdPartyVerifyTest.java</exclude>
+ <exclude>**/AtomConformanceTest.java</exclude>
+ <exclude>**/TestChannelServlet*</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+ <repositories>
+ <repository>
+ <id>java.net2</id>
+ <name>Repository hosting the jee6 artifacts</name>
+ <url>http://download.java.net/maven/2</url>
+ </repository>
+ </repositories>
+
+ <dependencyManagement>
+ <dependencies>
+
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.5</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>4.1.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpmime</artifactId>
+ <version>4.1.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpcore</artifactId>
+ <version>4.1.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient-cache</artifactId>
+ <version>4.1.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>1.7.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.ws.commons.axiom</groupId>
+ <artifactId>axiom</artifactId>
+ <version>1.2.12</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.ws.commons.axiom</groupId>
+ <artifactId>axiom-impl</artifactId>
+ <version>1.2.12</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-activation_1.1_spec</artifactId>
+ <version>1.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax</groupId>
+ <artifactId>javaee-web-api</artifactId>
+ <version>6.0</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.ibm.icu</groupId>
+ <artifactId>icu4j</artifactId>
+ <version>4.8.1.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.9</version>
+ <scope>test, compile, package</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ <version>3.2.6</version>
+ <scope>runtime</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>jaxen</groupId>
+ <artifactId>jaxen</artifactId>
+ <version>1.1.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>jdom</groupId>
+ <artifactId>jdom</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xom</groupId>
+ <artifactId>xom</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.santuario</groupId>
+ <artifactId>xmlsec</artifactId>
+ <version>1.4.5</version>
+ </dependency>
+
+ <dependency>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ <version>2.9.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ <version>2.0.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-server</artifactId>
+ <version>8.0.0.v20110901</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-servlet</artifactId>
+ <version>8.0.0.v20110901</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.8.5</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>3.0</version>
+ </dependency>
+
+ </dependencies>
+ </dependencyManagement>
+
+ <modules>
+ <module>common</module>
+ <module>core</module>
+ <module>server</module>
+ <module>activities</module>
+ <module>client</module>
+ <module>ext</module>
+ <module>security</module>
+ <module>test</module>
+ </modules>
+
+ <distributionManagement>
+ <snapshotRepository>
+ <id>apache.snapshots</id>
+ <name>Apache Development Snapshot Repository</name>
+ <url>scp://people.apache.org/www/people.apache.org/repo/m2-snapshot-repository</url>
+ </snapshotRepository>
+
+ <repository>
+ <id>apache.releases</id>
+ <name>Apache Release Distribution Repository</name>
+ <url>scp://people.apache.org/www/people.apache.org/repo/m2-ibiblio-rsync-repository</url>
+ </repository>
+ </distributionManagement>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <jetty.version>6.1.24</jetty.version>
+ <easymock.version>3.0</easymock.version>
+ <topDir>${basedir}</topDir>
+ <abdera.osgi.imports>${abdera.osgi.abdera.imports},${abdera.osgi.default.imports}</abdera.osgi.imports>
+ <abdera.osgi.exports>${abdera.osgi.default.exports};version=${project.version};-noimport:=true</abdera.osgi.exports>
+ <abdera.osgi.abdera.imports>org.apache.abdera.*;version="[$(version;===;${abdera.osgi.version.clean}),$(version;==+;${abdera.osgi.version.clean}))"</abdera.osgi.abdera.imports>
+ <abdera.osgi.default.imports>*</abdera.osgi.default.imports>
+ <abdera.osgi.default.exports>org.apache.abdera.*</abdera.osgi.default.exports>
+ <abdera.osgi.embed.dependencies></abdera.osgi.embed.dependencies>
+ </properties>
+
+</project>
Propchange: abdera/abdera2/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/security/pom.xml
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/pom.xml?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/security/pom.xml (added)
+++ abdera/abdera2/security/pom.xml Tue Sep 20 15:56:46 2011
@@ -0,0 +1,72 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.abdera2</groupId>
+ <artifactId>abdera2</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>abdera2-security</artifactId>
+ <packaging>bundle</packaging>
+ <name>Abdera2 Security</name>
+ <version>2.0-SNAPSHOT</version>
+ <description>Atom Publishing Protocol Security Implementation</description>
+
+ <properties>
+ <topDir>${basedir}/..</topDir>
+ <!--
+ <abdera.osgi.default.exports>
+ org.apache.abdera.protocol.client.*
+ </abdera.osgi.default.exports>
+ <abdera.osgi.default.imports>
+ org.apache.commons.codec*;version="[1.5,2)",
+ *
+ </abdera.osgi.default.imports>
+ -->
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.abdera2</groupId>
+ <artifactId>abdera2-core</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.abdera2</groupId>
+ <artifactId>abdera2-common</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.abdera2</groupId>
+ <artifactId>abdera2-server</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.santuario</groupId>
+ <artifactId>xmlsec</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Propchange: abdera/abdera2/security/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Encryption.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Encryption.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Encryption.java (added)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Encryption.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.security;
+
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
+
+/**
+ * Interface used for encrypting/decrypting Abdera documents.
+ */
+public interface Encryption {
+
+ /**
+ * Encrypt the document using the specified options
+ *
+ * @param doc The document to encrypt
+ * @param options The encryption options
+ * @return The encrypted document
+ * @throws org.apache.abdera.security.SecurityException if the encryption failed
+ */
+ <T extends Element>Document<T> encrypt(Document<?> doc, EncryptionOptions options) throws SecurityException;
+
+ /**
+ * Decrypt the document using the specified options
+ *
+ * @param doc The document to decrypt
+ * @param options The decryption options
+ * @return The decrypted document
+ * @throws org.apache.abdera.security.SecurityException if the decryption failed
+ */
+ <T extends Element>Document<T> decrypt(Document<?> doc, EncryptionOptions options) throws SecurityException;
+
+ /**
+ * Returns true if this specified document has been encrypted
+ */
+ boolean isEncrypted(Document<?> doc) throws SecurityException;
+
+ /**
+ * Returns the default encryption/decryption options
+ *
+ * @see org.apache.abdera.security.EncryptionOptions
+ */
+ EncryptionOptions getDefaultEncryptionOptions();
+
+}
Propchange: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Encryption.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/EncryptionOptions.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/EncryptionOptions.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/EncryptionOptions.java (added)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/EncryptionOptions.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.security;
+
+import java.security.Key;
+
+/**
+ * Provides access to the information necessary to encrypt or decrypt a document
+ */
+public interface EncryptionOptions extends SecurityOptions {
+
+ /**
+ * Return the secret key used to encrypt/decrypt the document content
+ */
+ Key getDataEncryptionKey();
+
+ /**
+ * Set the secret key used to encrypt/decrypt the document content
+ */
+ EncryptionOptions setDataEncryptionKey(Key key);
+
+ /**
+ * Return the secret key used to encrypt/decrypt the data encryption key
+ */
+ Key getKeyEncryptionKey();
+
+ /**
+ * Set the secret key used to encrypt/decrypt the data encryption key
+ */
+ EncryptionOptions setKeyEncryptionKey(Key key);
+
+ /**
+ * Return the cipher algorithm used to decrypt/encrypt the data encryption key The default is
+ * "http://www.w3.org/2001/04/xmlenc#kw-aes128"
+ */
+ String getKeyCipherAlgorithm();
+
+ /**
+ * Set the cipher algorithm used to decrypt/encrypt the data encryption key The default is
+ * "http://www.w3.org/2001/04/xmlenc#kw-aes128"
+ */
+ EncryptionOptions setKeyCipherAlgorithm(String alg);
+
+ /**
+ * Return the cipher algorithm used to decrypt/encrypt the document content The default is
+ * "http://www.w3.org/2001/04/xmlenc#aes128-cbc"
+ */
+ String getDataCipherAlgorithm();
+
+ /**
+ * Set the cipher algorithm used to decyrpt/encrypt the document content The default is
+ * "http://www.w3.org/2001/04/xmlenc#aes128-cbc"
+ */
+ EncryptionOptions setDataCipherAlgorithm(String alg);
+
+ /**
+ * Return true if the encryption should include information about the key The default is false
+ */
+ boolean includeKeyInfo();
+
+ /**
+ * Set whether the encryption should include information about the key The default is false
+ */
+ EncryptionOptions setIncludeKeyInfo(boolean includeKeyInfo);
+
+}
Propchange: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/EncryptionOptions.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Security.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Security.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Security.java (added)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Security.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.security;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.Discover;
+import org.apache.abdera2.util.Configuration;
+
+/**
+ * The AbderaSecurity class provides the entry point for using XML Digital Signatures and XML Encryption with Abdera.
+ */
+public class Security {
+
+ private final Abdera abdera;
+ private final Encryption encryption;
+ private final Signature signature;
+
+ public Security() {
+ this(Abdera.getInstance());
+ }
+
+ public Security(Abdera abdera) {
+ this.abdera = abdera;
+ this.encryption = newEncryption();
+ this.signature = newSignature();
+ }
+
+ public Security(Configuration config) {
+ this(new Abdera(config));
+ }
+
+ private Abdera getAbdera() {
+ return abdera;
+ }
+
+ /**
+ * Acquire a new XML Encryption provider instance
+ */
+ public Encryption newEncryption() {
+ return (Encryption)Discover.locate(Encryption.class,
+ "org.apache.abdera2.security.xmlsec.XmlEncryption",
+ getAbdera());
+ }
+
+ /**
+ * Acquire a shared XML Encryption provider instance
+ */
+ public Encryption getEncryption() {
+ return encryption;
+ }
+
+ /**
+ * Acquire a new XML Digital Signature provider instance
+ */
+ public Signature newSignature() {
+ return (Signature)Discover.locate(Signature.class,
+ "org.apache.abdera2.security.xmlsec.XmlSignature",
+ getAbdera());
+ }
+
+ /**
+ * Acquire a shared XML Digital Signature provider instance
+ */
+ public Signature getSignature() {
+ return signature;
+ }
+
+}
Propchange: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Security.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/SecurityException.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/SecurityException.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/SecurityException.java (added)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/SecurityException.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.security;
+
+public class SecurityException extends RuntimeException {
+
+ private static final long serialVersionUID = 7981088993260681788L;
+
+ public SecurityException() {
+ super();
+ }
+
+ public SecurityException(String message) {
+ super(message);
+ }
+
+ public SecurityException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public SecurityException(Throwable cause) {
+ super(cause);
+ }
+
+}
Propchange: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/SecurityException.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/SecurityOptions.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/SecurityOptions.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/SecurityOptions.java (added)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/SecurityOptions.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.security;
+
+import org.apache.abdera2.parser.Parser;
+
+/**
+ * Base interface for EncryptionOptions and SignatureOptions
+ */
+public interface SecurityOptions {
+
+ Parser getParser();
+
+ <T extends SecurityOptions> T setParser(Parser parser);
+
+}
Propchange: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/SecurityOptions.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Signature.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Signature.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Signature.java (added)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Signature.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.security;
+
+import java.security.cert.X509Certificate;
+
+import org.apache.abdera2.model.Element;
+import org.apache.xml.security.keys.KeyInfo;
+
+/**
+ * Interface used for digitally signing and verifying Abdera elements
+ */
+public interface Signature {
+
+ /**
+ * Return true if the element has been digitally signed
+ */
+ boolean isSigned(Element element) throws SecurityException;
+
+ /**
+ * Adds a digital signature to the specified element
+ */
+ <T extends Element> T sign(T element, SignatureOptions options) throws SecurityException;
+
+ /**
+ * Verifies that the digitally signed element is valid
+ */
+ boolean verify(Element element, SignatureOptions options) throws SecurityException;
+
+ /**
+ * Returns a listing of X.509 certificates of valid digital signatures in the element
+ */
+ X509Certificate[] getValidSignatureCertificates(Element element, SignatureOptions options)
+ throws SecurityException;
+
+ KeyInfo getSignatureKeyInfo(Element element, SignatureOptions options) throws SecurityException;
+
+ /**
+ * Returns the default signing options
+ *
+ * @see org.apache.abdera.security.SignatureOptions
+ */
+ SignatureOptions getDefaultSignatureOptions() throws SecurityException;
+
+ <T extends Element> T removeInvalidSignatures(T element, SignatureOptions options) throws SecurityException;
+
+}
Propchange: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/Signature.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/SignatureOptions.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/SignatureOptions.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/SignatureOptions.java (added)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/SignatureOptions.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.security;
+
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.cert.X509Certificate;
+
+/**
+ * Provides access to the information necessary to signed an Abdera element
+ */
+public interface SignatureOptions extends SecurityOptions {
+
+ String getSigningAlgorithm();
+
+ SignatureOptions setSigningAlgorithm(String algorithm);
+
+ /**
+ * Return the private key with which to sign the element
+ */
+ PrivateKey getSigningKey();
+
+ /**
+ * Set the private key with which to sign the element
+ */
+ SignatureOptions setSigningKey(PrivateKey privateKey);
+
+ /**
+ * Return the X.509 cert to associated with the signature
+ */
+ X509Certificate getCertificate();
+
+ /**
+ * Set the X.509 cert to associate with the signature
+ */
+ SignatureOptions setCertificate(X509Certificate cert);
+
+ /**
+ * Get the public key associated with the signature
+ */
+ PublicKey getPublicKey();
+
+ /**
+ * Set the public key to associate with the signature
+ */
+ SignatureOptions setPublicKey(PublicKey publickey);
+
+ SignatureOptions addReference(String href);
+
+ String[] getReferences();
+
+ /**
+ * True if atom:link/@href and atom:content/@src targets should be included in the signature
+ */
+ SignatureOptions setSignLinks(boolean signlinks);
+
+ /**
+ * True if atom:link/@href and atom:content/@src targets should be included in the signature
+ */
+ boolean isSignLinks();
+
+ /**
+ * Only sign links whose link rels match those provided in the list
+ */
+ SignatureOptions setSignedLinkRels(String... rel);
+
+ /**
+ * Get the list of link relations to sign
+ */
+ String[] getSignLinkRels();
+}
Propchange: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/SignatureOptions.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/Constants.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/Constants.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/Constants.java (added)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/Constants.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.security.util;
+
+import javax.xml.namespace.QName;
+
+public final class Constants {
+
+ public static final String CONTENT_ENCRYPTED = "Content-Encrypted";
+ public static final String ACCEPT_ENCRYPTION = "Accept-Encryption";
+
+ Constants() {
+ }
+
+ public static final String DSIG_NS = "http://www.w3.org/2000/09/xmldsig#";
+ public static final String XENC_NS = "http://www.w3.org/2001/04/xmlenc#";
+ public static final String LN_SIGNATURE = "Signature";
+ public static final String LN_ENCRYPTEDDATA = "EncryptedData";
+ public static final String DSIG_PREFIX = "dsig";
+ public static final String XENC_PREFIX = "xenc";
+
+ public static final QName SIGNATURE = new QName(DSIG_NS, LN_SIGNATURE, DSIG_PREFIX);
+ public static final QName ENCRYPTEDDATA = new QName(XENC_NS, LN_ENCRYPTEDDATA, XENC_PREFIX);
+
+}
Propchange: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/Constants.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/DHContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/DHContext.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/DHContext.java (added)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/DHContext.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.security.util;
+
+import java.io.Serializable;
+import java.math.BigInteger;
+import java.security.AlgorithmParameterGenerator;
+import java.security.AlgorithmParameters;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.Key;
+import java.security.KeyFactory;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.InvalidParameterSpecException;
+import java.security.spec.X509EncodedKeySpec;
+
+import javax.crypto.KeyAgreement;
+import javax.crypto.spec.DHParameterSpec;
+
+import org.apache.abdera2.security.Encryption;
+import org.apache.abdera2.security.EncryptionOptions;
+import org.apache.axiom.om.util.Base64;
+import org.apache.xml.security.encryption.XMLCipher;
+
+/**
+ * Implements the Diffie-Hellman Key Exchange details for both parties Party A: DHContext context_a = new DHContext();
+ * String req = context_a.getRequestString(); Party B: DHContext context_b = new DHContext(req); EncryptionOptions
+ * options = context_b.getEncryptionOptions(enc); // encrypt String ret = context_b.getResponseString(); Party A:
+ * context_a.setPublicKey(ret); EncryptionOptions options = context_a.getEncryptionOptions(enc); // decrypt
+ */
+public class DHContext implements Cloneable, Serializable {
+
+ private static final long serialVersionUID = 9145945368596071015L;
+ BigInteger p = null, g = null;
+ int l = 0;
+ private KeyPair keyPair;
+ private Key publicKey;
+
+ public DHContext() {
+ try {
+ init();
+ } catch (Exception e) {
+ }
+ }
+
+ public DHContext(String dh) {
+ try {
+ init(dh);
+ } catch (Exception e) {
+ }
+ }
+
+ private DHContext(KeyPair keyPair, BigInteger p, BigInteger g, int l) {
+ this.keyPair = keyPair;
+ this.p = p;
+ this.g = g;
+ this.l = l;
+ }
+
+ public String getRequestString() {
+ StringBuilder buf = new StringBuilder();
+ buf.append(
+ String.format(
+ "DH p=%s, g=%s, k=%s",
+ p.toString(),
+ g.toString(),
+ Base64.encode(keyPair.getPublic().getEncoded())));
+ return buf.toString();
+ }
+
+ public String getResponseString() {
+ StringBuilder buf = new StringBuilder();
+ buf.append(
+ String.format(
+ "DH k=%s",
+ Base64.encode(keyPair.getPublic().getEncoded())));
+ return buf.toString();
+ }
+
+ private void init() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException,
+ InvalidParameterSpecException, InvalidKeySpecException {
+ AlgorithmParameterGenerator pgen = AlgorithmParameterGenerator.getInstance("DH");
+ pgen.init(512);
+ AlgorithmParameters params = pgen.generateParameters();
+ DHParameterSpec dhspec = (DHParameterSpec)params.getParameterSpec(DHParameterSpec.class);
+ KeyPairGenerator keypairgen = KeyPairGenerator.getInstance("DH");
+ keypairgen.initialize(dhspec);
+ keyPair = keypairgen.generateKeyPair();
+ p = dhspec.getP();
+ g = dhspec.getG();
+ l = dhspec.getL();
+ }
+
+ private void init(String dh) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException,
+ InvalidKeySpecException {
+ String[] segments = dh.split("\\s+", 2);
+ if (!segments[0].equalsIgnoreCase("DH"))
+ throw new IllegalArgumentException();
+ String[] params = segments[1].split("\\s*,\\s*");
+ byte[] key = null;
+ for (String param : params) {
+ String name = param.substring(0, param.indexOf("="));
+ String value = param.substring(param.indexOf("=") + 1);
+ if (name.equalsIgnoreCase("p"))
+ p = new BigInteger(value);
+ else if (name.equalsIgnoreCase("g"))
+ g = new BigInteger(value);
+ else if (name.equalsIgnoreCase("k"))
+ key = Base64.decode(value);
+ }
+ init(p, g, l, key);
+ }
+
+ private void init(BigInteger p, BigInteger g, int l, byte[] key) throws NoSuchAlgorithmException,
+ InvalidAlgorithmParameterException, InvalidKeySpecException {
+ DHParameterSpec spec = new DHParameterSpec(p, g, l);
+ KeyPairGenerator keypairgen = KeyPairGenerator.getInstance("DH");
+ keypairgen.initialize(spec);
+ keyPair = keypairgen.generateKeyPair();
+ publicKey = decode(key);
+ }
+
+ public KeyPair getKeyPair() {
+ return keyPair;
+ }
+
+ public Key getPublicKey() {
+ return publicKey;
+ }
+
+ private Key decode(byte[] key) throws NoSuchAlgorithmException, InvalidKeySpecException {
+ X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(key);
+ KeyFactory keyFact = KeyFactory.getInstance("DH");
+ return keyFact.generatePublic(x509KeySpec);
+ }
+
+ public DHContext setPublicKey(String dh) throws NoSuchAlgorithmException, InvalidKeySpecException {
+ String[] segments = dh.split("\\s+", 2);
+ if (!segments[0].equalsIgnoreCase("DH"))
+ throw new IllegalArgumentException();
+ String[] tokens = segments[1].split("\\s*,\\s*");
+ byte[] key = null;
+ for (String token : tokens) {
+ String name = token.substring(0, token.indexOf("="));
+ String value = token.substring(token.indexOf("=") + 1);
+ if (name.equalsIgnoreCase("k"))
+ key = Base64.decode(value);
+ }
+ publicKey = decode(key);
+ return this;
+ }
+
+ public Key generateSecret() throws NoSuchAlgorithmException, InvalidKeyException {
+ KeyAgreement ka = KeyAgreement.getInstance("DH");
+ ka.init(keyPair.getPrivate());
+ ka.doPhase(publicKey, true);
+ return ka.generateSecret("DESede");
+ }
+
+ public EncryptionOptions getEncryptionOptions(Encryption enc) throws InvalidKeyException, NoSuchAlgorithmException {
+ EncryptionOptions options = enc.getDefaultEncryptionOptions();
+ options.setDataEncryptionKey(generateSecret());
+ options.setDataCipherAlgorithm(XMLCipher.TRIPLEDES);
+ return options;
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ if (publicKey != null)
+ throw new CloneNotSupportedException();
+ // create a copy, not an actual clone
+ return new DHContext(keyPair, p, g, l);
+ }
+
+}
Propchange: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/DHContext.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/EncryptionBase.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/EncryptionBase.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/EncryptionBase.java (added)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/EncryptionBase.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.security.util;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.security.Encryption;
+import org.apache.abdera2.security.SecurityException;
+
+public abstract class EncryptionBase extends SecurityBase implements Encryption {
+
+ public EncryptionBase(Abdera abdera) {
+ super(abdera);
+ }
+
+ public boolean isEncrypted(Document<?> doc) throws SecurityException {
+ Element el = doc.getRoot();
+ return el.getQName().equals(Constants.ENCRYPTEDDATA);
+ }
+
+}
Propchange: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/EncryptionBase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/KeyHelper.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/KeyHelper.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/KeyHelper.java (added)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/KeyHelper.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.security.util;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.cert.Certificate;
+import java.security.Key;
+import java.security.KeyFactory;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.PublicKey;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.security.spec.X509EncodedKeySpec;
+
+import javax.crypto.KeyGenerator;
+import javax.crypto.SecretKey;
+
+import org.apache.commons.codec.binary.Hex;
+
+public class KeyHelper {
+
+ public static void saveKeystore(KeyStore ks, String file, String password) throws KeyStoreException,
+ NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException {
+ ks.store(new FileOutputStream(file), password.toCharArray());
+ }
+
+ public static KeyStore loadKeystore(String file, String pass) throws KeyStoreException, NoSuchAlgorithmException,
+ CertificateException, IOException {
+ KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
+ InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
+ if (in == null)
+ in = new FileInputStream(file);
+ ks.load(in, pass.toCharArray());
+ return ks;
+ }
+
+ public static KeyStore loadKeystore(String type, String file, String pass) throws KeyStoreException,
+ NoSuchAlgorithmException, CertificateException, IOException {
+ KeyStore ks = KeyStore.getInstance(type);
+ InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
+ if (in == null)
+ in = new FileInputStream(file);
+ ks.load(in, pass.toCharArray());
+ return ks;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T extends Key> T getKey(KeyStore ks, String alias, String pass) throws KeyStoreException,
+ NoSuchAlgorithmException, UnrecoverableKeyException {
+ return (T)ks.getKey(alias, pass.toCharArray());
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T extends Certificate> T getCertificate(KeyStore ks, String alias) throws KeyStoreException {
+ return (T)ks.getCertificate(alias);
+ }
+
+ public static KeyPair generateKeyPair(String type, int size) throws NoSuchAlgorithmException,
+ NoSuchProviderException {
+ KeyPairGenerator keyGen = KeyPairGenerator.getInstance(type);
+ SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
+ keyGen.initialize(size, random);
+ random.setSeed(System.currentTimeMillis());
+ return keyGen.generateKeyPair();
+ }
+
+ public static KeyPair generateKeyPair(String type, int size, String provider) throws NoSuchAlgorithmException,
+ NoSuchProviderException {
+ KeyPairGenerator keyGen = KeyPairGenerator.getInstance(type, provider);
+ SecureRandom random = SecureRandom.getInstance("SHA1PRNG", provider);
+ keyGen.initialize(size, random);
+ random.setSeed(System.currentTimeMillis());
+ return keyGen.generateKeyPair();
+ }
+
+ public static SecretKey generateSecretKey(String type, int size) throws NoSuchAlgorithmException,
+ NoSuchProviderException {
+ KeyGenerator keyGenerator = KeyGenerator.getInstance(type);
+ keyGenerator.init(size);
+ return keyGenerator.generateKey();
+ }
+
+ public static Key generateKey(String type) throws NoSuchAlgorithmException {
+ KeyGenerator keygen = KeyGenerator.getInstance(type);
+ keygen.init(new SecureRandom());
+ return keygen.generateKey();
+ }
+
+ public static SecretKey generateSecretKey(String type, int size, String provider) throws NoSuchAlgorithmException,
+ NoSuchProviderException {
+ KeyGenerator keyGenerator = KeyGenerator.getInstance(type, provider);
+ keyGenerator.init(size);
+ return keyGenerator.generateKey();
+ }
+
+ public static PublicKey generatePublicKey(String hex) {
+ try {
+ if (hex == null || hex.trim().length() == 0)
+ return null;
+ byte[] data = Hex.decodeHex(hex.toCharArray());
+ X509EncodedKeySpec keyspec = new X509EncodedKeySpec(data);
+ KeyFactory keyfactory = KeyFactory.getInstance("RSA");
+ return keyfactory.generatePublic(keyspec);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static boolean prepareDefaultJceProvider() {
+ return prepareJceProvider(
+ "org.bouncycastle.jce.provider.BouncyCastleProvider");
+ }
+
+ public static boolean prepareJceProvider(Class<?> provider) {
+ try {
+ Provider p = (Provider)provider.newInstance();
+ Security.addProvider(p);
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ public static boolean prepareJceProvider(String className) {
+ try {
+ Class<?> provider = Class.forName(className);
+ return prepareJceProvider(provider);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+}
+
Propchange: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/KeyHelper.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/SecurityBase.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/SecurityBase.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/SecurityBase.java (added)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/SecurityBase.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.security.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.security.SecurityOptions;
+
+public abstract class SecurityBase {
+
+ protected final Abdera abdera;
+
+ protected SecurityBase(Abdera abdera) {
+ this.abdera = abdera;
+ }
+
+ protected Abdera getAbdera() {
+ return abdera;
+ }
+
+ protected org.w3c.dom.Document fomToDom(Document<?> doc, SecurityOptions options) {
+ org.w3c.dom.Document dom = null;
+ if (doc != null) {
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ doc.writeTo(out);
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setValidating(false);
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ dom = db.parse(in);
+ } catch (Exception e) {
+ }
+ }
+ return dom;
+ }
+
+ protected Document<?> domToFom(org.w3c.dom.Document dom, SecurityOptions options) {
+ Document<?> doc = null;
+ if (dom != null) {
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer t = tf.newTransformer();
+ t.transform(new DOMSource(dom), new StreamResult(out));
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+ doc = options.getParser().parse(in);
+ } catch (Exception e) {
+ }
+ }
+ return doc;
+ }
+
+ protected org.w3c.dom.Element fomToDom(Element element, SecurityOptions options) {
+ org.w3c.dom.Element dom = null;
+ if (element != null) {
+ try {
+ ByteArrayInputStream in = new ByteArrayInputStream(element.toString().getBytes());
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setValidating(false);
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ dom = db.parse(in).getDocumentElement();
+ } catch (Exception e) {
+ }
+ }
+ return dom;
+ }
+
+ protected Element domToFom(org.w3c.dom.Element element, SecurityOptions options) {
+ Element el = null;
+ if (element != null) {
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer t = tf.newTransformer();
+ t.transform(new DOMSource(element), new StreamResult(out));
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+ el = options.getParser().parse(in).getRoot();
+ } catch (Exception e) {
+ }
+ }
+ return el;
+ }
+}
Propchange: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/SecurityBase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/SignatureBase.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/SignatureBase.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/SignatureBase.java (added)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/SignatureBase.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.security.util;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.ExtensibleElement;
+import org.apache.abdera2.security.Signature;
+
+public abstract class SignatureBase extends SecurityBase implements Signature {
+
+ protected SignatureBase(Abdera abdera) {
+ super(abdera);
+ }
+
+ public boolean isSigned(Element element) {
+ if (element instanceof ExtensibleElement)
+ return ((ExtensibleElement)element).getExtension(Constants.SIGNATURE) != null;
+ else
+ return false;
+ }
+
+}
Propchange: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/SignatureBase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AESEncryptedResponseFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AESEncryptedResponseFilter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AESEncryptedResponseFilter.java (added)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AESEncryptedResponseFilter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.security.util.filters;
+
+import java.security.PublicKey;
+import java.security.cert.X509Certificate;
+import java.security.interfaces.RSAPublicKey;
+
+import org.apache.abdera2.common.protocol.RequestContext;
+import org.apache.abdera2.common.protocol.RequestContext.Scope;
+import org.apache.abdera2.common.protocol.ResponseContext;
+import org.apache.abdera2.security.Encryption;
+import org.apache.abdera2.security.EncryptionOptions;
+import org.apache.abdera2.security.util.KeyHelper;
+import org.apache.xml.security.encryption.XMLCipher;
+
+/**
+ * <pre>
+ * <filter>
+ * <filter-name>enc filter</filter-name>
+ * <filter-class>com.test.EncryptedResponseFilter</filter-class>
+ * </filter>
+ * <filter-mapping>
+ * <filter-name>enc filter</filter-name>
+ * <servlet-name>TestServlet</servlet-name>
+ * </filter-mapping>
+ * </pre>
+ */
+public class AESEncryptedResponseFilter extends AbstractEncryptedResponseFilter {
+
+ public static final String PUBLICKEY = "X-PublicKey";
+
+ protected X509Certificate[] getCerts(RequestContext request) {
+ return (X509Certificate[])request.getAttribute(Scope.REQUEST, "javax.servlet.request.X509Certificate");
+ }
+
+ protected PublicKey getPublicKey(RequestContext request) {
+ String header = request.getHeader(PUBLICKEY);
+ PublicKey pkey = KeyHelper.generatePublicKey(header);
+ if (pkey == null)
+ pkey = retrievePublicKey(request);
+ return pkey;
+ }
+
+ protected boolean doEncryption(RequestContext request, Object arg) {
+ return arg != null && arg instanceof RSAPublicKey;
+ }
+
+ protected Object initArg(RequestContext request) {
+ return getPublicKey(request);
+ }
+
+ protected PublicKey retrievePublicKey(RequestContext request) {
+ X509Certificate[] cert = getCerts(request);
+ return cert != null ? cert[0].getPublicKey() : null;
+ }
+
+ protected EncryptionOptions initEncryptionOptions(RequestContext request,
+ ResponseContext response,
+ Encryption enc,
+ Object arg) {
+ try {
+ EncryptionOptions options = enc.getDefaultEncryptionOptions();
+ options.setDataEncryptionKey(KeyHelper.generateKey("AES"));
+ options.setKeyEncryptionKey((PublicKey)arg);
+ options.setKeyCipherAlgorithm(XMLCipher.RSA_v1dot5);
+ options.setIncludeKeyInfo(true);
+ return options;
+ } catch (Exception e) {
+ return null;
+ }
+ }
+}
Propchange: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AESEncryptedResponseFilter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedRequestFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedRequestFilter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedRequestFilter.java (added)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedRequestFilter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.security.util.filters;
+
+import java.io.IOException;
+import java.security.Provider;
+import java.security.Security;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.protocol.RequestContext;
+import org.apache.abdera2.common.protocol.ResponseContext;
+import org.apache.abdera2.common.protocol.Filter;
+import org.apache.abdera2.common.protocol.FilterChain;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.parser.ParseException;
+import org.apache.abdera2.parser.Parser;
+import org.apache.abdera2.parser.ParserOptions;
+import org.apache.abdera2.protocol.server.context.AtompubRequestContext;
+import org.apache.abdera2.security.Encryption;
+import org.apache.abdera2.security.EncryptionOptions;
+
+public abstract class AbstractEncryptedRequestFilter implements Filter {
+
+ // The methods that allow encrypted bodies
+ protected final List<String> methods = new ArrayList<String>();
+
+ protected AbstractEncryptedRequestFilter() {
+ this("POST", "PUT");
+ }
+
+ protected AbstractEncryptedRequestFilter(String... methods) {
+ for (String method : methods)
+ this.methods.add(method);
+ initProvider();
+ }
+
+ protected void initProvider() {
+ }
+
+ protected void addProvider(Provider provider) {
+ if (Security.getProvider(provider.getName()) == null)
+ Security.addProvider(provider);
+ }
+
+ public <S extends ResponseContext>S filter(RequestContext request, FilterChain chain) {
+ bootstrap(request);
+ String method = request.getMethod();
+ if (methods.contains(method.toUpperCase())) {
+ return chain.next(new DecryptingRequestContextWrapper(request));
+ } else
+ return chain.next(request);
+ }
+
+ protected abstract void bootstrap(RequestContext request);
+
+ protected abstract Object initArg(RequestContext request);
+
+ protected abstract EncryptionOptions initEncryptionOptions(RequestContext request, Encryption encryption, Object arg);
+
+ private class DecryptingRequestContextWrapper extends AtompubRequestContext {
+ public DecryptingRequestContextWrapper(RequestContext request) {
+ super(request);
+ }
+ @SuppressWarnings("unchecked")
+ public <T extends Element> Document<T> getDocument(Parser parser, ParserOptions options) throws ParseException,
+ IOException {
+ Document<Element> doc = super.getDocument();
+ try {
+ if (doc != null) {
+ Abdera abdera = getAbdera();
+ Encryption enc = new org.apache.abdera2.security.Security(abdera).getEncryption();
+ if (enc.isEncrypted(doc)) {
+ Object arg = initArg((AtompubRequestContext)request);
+ EncryptionOptions encoptions = initEncryptionOptions((AtompubRequestContext)request, enc, arg);
+ doc = enc.decrypt(doc, encoptions);
+ }
+ }
+ } catch (Exception e) {
+ }
+ return (Document<T>)doc;
+ }
+ }
+}
Propchange: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedRequestFilter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedResponseFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedResponseFilter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedResponseFilter.java (added)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedResponseFilter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.security.util.filters;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.security.Provider;
+import java.security.Security;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.protocol.RequestContext;
+import org.apache.abdera2.common.protocol.ResponseContext;
+import org.apache.abdera2.common.protocol.Filter;
+import org.apache.abdera2.common.protocol.FilterChain;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.protocol.server.AtompubResponseContext;
+import org.apache.abdera2.protocol.server.context.ResponseContextWrapper;
+import org.apache.abdera2.protocol.server.impl.AbstractAtompubProvider;
+import org.apache.abdera2.security.Encryption;
+import org.apache.abdera2.security.EncryptionOptions;
+import org.apache.abdera2.writer.Writer;
+
+public abstract class AbstractEncryptedResponseFilter implements Filter {
+
+ public AbstractEncryptedResponseFilter() {
+ initProvider();
+ }
+
+ protected void initProvider() {
+ }
+
+ protected void addProvider(Provider provider) {
+ if (Security.getProvider(provider.getName()) == null)
+ Security.addProvider(provider);
+ }
+
+ @SuppressWarnings("unchecked")
+ public <S extends ResponseContext>S filter(RequestContext request, FilterChain chain) {
+ Object arg = initArg(request);
+ if (doEncryption(request, arg)) {
+ return (S)new EncryptingResponseContext(AbstractAtompubProvider.getAbdera(request), request, chain.next(request), arg);
+ } else {
+ return chain.next(request);
+ }
+ }
+
+ protected abstract boolean doEncryption(RequestContext request, Object arg);
+
+ protected abstract EncryptionOptions initEncryptionOptions(RequestContext request,
+ ResponseContext response,
+ Encryption enc,
+ Object arg);
+
+ protected abstract Object initArg(RequestContext request);
+
+ private class EncryptingResponseContext extends ResponseContextWrapper {
+
+ private final RequestContext request;
+ private final Abdera abdera;
+ private final Object arg;
+
+ public EncryptingResponseContext(Abdera abdera, RequestContext request, ResponseContext response, Object arg) {
+ super((AtompubResponseContext)response);
+ this.abdera = abdera;
+ this.request = request;
+ this.arg = arg;
+ }
+
+ public void writeTo(OutputStream out, Writer writer) throws IOException {
+ try {
+ encrypt(out, null);
+ } catch (Exception se) {
+ throw new RuntimeException(se);
+ }
+ }
+
+ public void writeTo(OutputStream out) throws IOException {
+ try {
+ encrypt(out, null);
+ } catch (Exception se) {
+ throw new RuntimeException(se);
+ }
+ }
+
+ private void encrypt(OutputStream aout, Writer writer) throws Exception {
+ Document<Element> doc = null;
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ if (writer == null)
+ super.writeTo(out);
+ else
+ super.writeTo(out, writer);
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+ doc = abdera.getParser().parse(in);
+ } catch (Exception e) {
+ }
+ if (doc != null) {
+ Encryption enc = new org.apache.abdera2.security.Security(abdera).getEncryption();
+ EncryptionOptions options = initEncryptionOptions(request, response, enc, arg);
+ doc = enc.encrypt(doc, options);
+ }
+ if (doc != null)
+ doc.writeTo(aout);
+ else
+ throw new RuntimeException("There was an error encrypting the response");
+ }
+ }
+}
Propchange: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedResponseFilter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain