Skip to content

Commit

Permalink
JAMES-1959 Extract JWT to an other maven project
Browse files Browse the repository at this point in the history
  • Loading branch information
chibenwa committed Mar 15, 2017
1 parent 3ac2368 commit f1a087f
Show file tree
Hide file tree
Showing 14 changed files with 317 additions and 33 deletions.
Expand Up @@ -34,6 +34,7 @@
import org.apache.james.jmap.utils.MailboxBasedHtmlTextExtractor; import org.apache.james.jmap.utils.MailboxBasedHtmlTextExtractor;
import org.apache.james.jmap.utils.SystemMailboxesProvider; import org.apache.james.jmap.utils.SystemMailboxesProvider;
import org.apache.james.jmap.utils.SystemMailboxesProviderImpl; import org.apache.james.jmap.utils.SystemMailboxesProviderImpl;
import org.apache.james.jwt.JwtConfiguration;
import org.apache.james.lifecycle.api.Configurable; import org.apache.james.lifecycle.api.Configurable;
import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxManager.SearchCapabilities; import org.apache.james.mailbox.MailboxManager.SearchCapabilities;
Expand Down Expand Up @@ -89,6 +90,12 @@ JMAPConfiguration provideConfiguration(PropertiesProvider propertiesProvider, Fi
.build(); .build();
} }


@Provides
@Singleton
JwtConfiguration providesJwtConfiguration(JMAPConfiguration jmapConfiguration) {
return new JwtConfiguration(jmapConfiguration.getJwtPublicKeyPem());
}

private Optional<String> loadPublicKey(FileSystem fileSystem, Optional<String> jwtPublickeyPemUrl) { private Optional<String> loadPublicKey(FileSystem fileSystem, Optional<String> jwtPublickeyPemUrl) {
return jwtPublickeyPemUrl.map(Throwing.function(url -> FileUtils.readFileToString(fileSystem.getFile(url)))); return jwtPublickeyPemUrl.map(Throwing.function(url -> FileUtils.readFileToString(fileSystem.getFile(url))));
} }
Expand Down
6 changes: 6 additions & 0 deletions server/pom.xml
Expand Up @@ -109,6 +109,7 @@
<module>protocols/webadmin-integration-test</module> <module>protocols/webadmin-integration-test</module>


<module>testing</module> <module>testing</module>
<module>protocols/jwt</module>
</modules> </modules>


<distributionManagement> <distributionManagement>
Expand Down Expand Up @@ -805,6 +806,11 @@
<artifactId>james-server-data-ldap-integration-testing</artifactId> <artifactId>james-server-data-ldap-integration-testing</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>james-server-jwt</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.james</groupId> <groupId>org.apache.james</groupId>
<artifactId>james-server-protocols-lmtp</artifactId> <artifactId>james-server-protocols-lmtp</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions server/protocols/jmap/pom.xml
Expand Up @@ -215,6 +215,10 @@
<groupId>org.apache.james</groupId> <groupId>org.apache.james</groupId>
<artifactId>james-server-jetty</artifactId> <artifactId>james-server-jetty</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>james-server-jwt</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.apache.james</groupId> <groupId>org.apache.james</groupId>
<artifactId>james-server-lifecycle-api</artifactId> <artifactId>james-server-lifecycle-api</artifactId>
Expand Down
Expand Up @@ -23,10 +23,10 @@
import javax.inject.Inject; import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;


import org.apache.james.jmap.crypto.JwtTokenVerifier;
import org.apache.james.jmap.exceptions.MailboxSessionCreationException; import org.apache.james.jmap.exceptions.MailboxSessionCreationException;
import org.apache.james.jmap.exceptions.NoValidAuthHeaderException; import org.apache.james.jmap.exceptions.NoValidAuthHeaderException;
import org.apache.james.jmap.utils.HeadersAuthenticationExtractor; import org.apache.james.jmap.utils.HeadersAuthenticationExtractor;
import org.apache.james.jwt.JwtTokenVerifier;
import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.exception.MailboxException;
Expand Down
Expand Up @@ -29,10 +29,10 @@


import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;


import org.apache.james.jmap.crypto.JwtTokenVerifier;
import org.apache.james.jmap.exceptions.MailboxSessionCreationException; import org.apache.james.jmap.exceptions.MailboxSessionCreationException;
import org.apache.james.jmap.exceptions.NoValidAuthHeaderException; import org.apache.james.jmap.exceptions.NoValidAuthHeaderException;
import org.apache.james.jmap.utils.HeadersAuthenticationExtractor; import org.apache.james.jmap.utils.HeadersAuthenticationExtractor;
import org.apache.james.jwt.JwtTokenVerifier;
import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.exception.MailboxException;
Expand Down
245 changes: 245 additions & 0 deletions server/protocols/jwt/pom.xml
@@ -0,0 +1,245 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>james-server</artifactId>
<groupId>org.apache.james</groupId>
<version>3.0.0-beta6-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>james-server-jwt</artifactId>
<packaging>jar</packaging>

<name>Apache James :: Server :: JWT</name>

<profiles>
<profile>
<id>noTest</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>disable-build-for-older-jdk</id>
<activation>
<jdk>(,1.8)</jdk>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
<execution>
<id>jar</id>
<phase>none</phase>
</execution>
<execution>
<id>test-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>default-test</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>default-install</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>default-resources</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testResources</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<executions>
<execution>
<id>attach-descriptor</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>build-for-jdk-8</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<dependencies>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj-3.version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>animal-sniffer-java-8</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java18</artifactId>
<version>1.0</version>
</signature>
</configuration>
<executions>
<execution>
<id>check_java_8</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>


</project>
@@ -0,0 +1,34 @@
/****************************************************************
* 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. *
****************************************************************/

package org.apache.james.jwt;

import java.util.Optional;

public class JwtConfiguration {
private final Optional<String> jwtPublicKeyPem;

public JwtConfiguration(Optional<String> jwtPublicKeyPem) {
this.jwtPublicKeyPem = jwtPublicKeyPem;
}

public Optional<String> getJwtPublicKeyPem() {
return jwtPublicKeyPem;
}
}
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations * * specific language governing permissions and limitations *
* under the License. * * under the License. *
****************************************************************/ ****************************************************************/
package org.apache.james.jmap.crypto; package org.apache.james.jwt;


import javax.inject.Inject; import javax.inject.Inject;


Expand Down
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations * * specific language governing permissions and limitations *
* under the License. * * under the License. *
****************************************************************/ ****************************************************************/
package org.apache.james.jmap.crypto; package org.apache.james.jwt;


public class MissingOrInvalidKeyException extends RuntimeException { public class MissingOrInvalidKeyException extends RuntimeException {
} }

0 comments on commit f1a087f

Please sign in to comment.