Skip to content

Commit

Permalink
#1 migrate code to new stand alone repo
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-conway committed Aug 7, 2019
0 parents commit db157eb
Show file tree
Hide file tree
Showing 15 changed files with 465 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
**/.classpath
.DS_Store
**/nb-configuration.xml
**/.springBeans
**/testing.properties
**/metalnx.testing.properties
**/*.eml
**/Scripts
.idea
*.iml
.project
.idea
.metadata
.DS_Store
Servers
.settings
.classpath
target
mvn-repo
bin
*.war
*.log
*/nbactions.xml
*.eml
nbactions.xml
testing.properties
*/test-output
JargonVersion.java
**/${test.option.mount.basedir}
**/*.*~
*.*~
.dbeaver*
test.metalnx.properties
**/.vscode/
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Added

### Changed

### Removed

29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2017, DataNet Federation Consortium
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

Jargon Extensions API for irods-ext


# Project: Jargon Extensions JWT
### Date:
### Release Version: 4.3.1.0-SNAPSHOT
### git tag:

## Description

Supports JWT creation and decoding for iRODS related microservices t

## Requirements

* Jargon depends on Java 1.8+
* Jargon is built using Apache Maven2, see POM for dependencies

## Libraries

Jargon-core uses Maven for dependency management. See the pom.xml file for references to various dependencies.

Note that the following bug and feature requests are logged in GitHub with related commit information [[https://github.com/DICE-UNC/jargon-extensions-jwt/issues]]

151 changes: 151 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.irods</groupId>
<artifactId>jargon-pom</artifactId>
<version>4.3.1.0-SNAPSHOT</version>
</parent>
<artifactId>irodsext-jwt-service</artifactId>
<name>irodsext-jwt-service</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>dice.repository snaps</id>
<name>dice.repository.snapshots</name>
<url>https://raw.github.com/DICE-UNC/DICE-Maven/master/snapshots</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</repository>
<repository>
<id>dice.repository</id>
<name>dice.repository</name>
<url>https://raw.github.com/DICE-UNC/DICE-Maven/master/releases</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</repository>
<repository>
<id>netbeans.repository</id>
<name>netbeans.repository</name>
<url>http://bits.netbeans.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</repository>
</repositories>
<description>Tools for managing jwts used by associated microservices</description>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>0</id>
<phase>validate</phase>
<configuration>
<tasks>
<delete
file="${basedir}/src/test/resources/testing.properties" />
<touch
file="${basedir}/src/test/resources/testing.properties"
mkdirs="true" />
<echo
file="${basedir}/src/test/resources/testing.properties"
append="true">
test.confirm=${jargon.test.confirm}
test.data.directory=${jargon.test.data.directory}
test.irods.admin=${jargon.test.irods.admin}
test.irods.admin.password=${jargon.test.irods.admin.password}
test.irods.user=${jargon.test.irods.user}
test.irods.password=${jargon.test.irods.password}
test.irods.resource=${jargon.test.irods.resource}
test2.irods.user=${jargon.test.irods.user2}
test2.irods.password=${jargon.test.irods.password2}
test2.irods.resource=${jargon.test.irods.resource2}
test3.irods.user=${jargon.test.irods.user3}
test3.irods.password=${jargon.test.irods.password3}
test3.irods.resource=${jargon.test.irods.resource3}
test.irods.host=${jargon.test.irods.host}
test.irods.port=${jargon.test.irods.port}
test.irods.zone=${jargon.test.irods.zone}
test.resource.group=${jargon.test.resource.group}
test.irods.userDN=${jargon.test.irods.userDN}
test.irods.scratch.subdir=${jargon.test.irods.scratch.subdir}
</echo>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<debug>true</debug>
</configuration>
</plugin>
</plugins>
</build>

</project>
Empty file added src/main/java/.gitinclude
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
*
*/
package org.irods.jargon.irodsext.jwt;

import java.security.Key;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;

/**
* @author Mike Conway - NIEHS
*
*/
public class JwtIssueServiceImpl {

public static final Logger log = LoggerFactory.getLogger(JwtIssueServiceImpl.class);

private final JwtServiceConfig jwtServiceConfig;
private final Key myKey;

/**
* Constructor with configs
*
* @param jwtServiceConfig {@link JwtServiceConfig}
*/
public JwtIssueServiceImpl(final JwtServiceConfig jwtServiceConfig) {
if (jwtServiceConfig == null) {
throw new IllegalArgumentException("null jwtServiceConfig");
}

this.jwtServiceConfig = jwtServiceConfig;
myKey = Keys.hmacShaKeyFor(jwtServiceConfig.getSecret().getBytes());
}

public String issueJwtToken(final String subject) {
log.info("issueJwtToken()");

if (subject == null || subject.isEmpty()) {
throw new IllegalArgumentException("null or empty subject");
}

String signedJwt = Jwts.builder().setSubject(subject).setIssuer(jwtServiceConfig.getIssuer())
.setIssuedAt(new Date()).signWith(myKey).compact();
return signedJwt;

}

public Jws<Claims> decodeJwtToken(final String token) {
log.info("decodeJwtToken()");

if (token == null || token.isEmpty()) {
throw new IllegalArgumentException("null or empty token");
}

Jws<Claims> claims = Jwts.parser().setSigningKey(myKey).parseClaimsJws(token);
return claims;

}

}
59 changes: 59 additions & 0 deletions src/main/java/org/irods/jargon/irodsext/jwt/JwtServiceConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
*
*/
package org.irods.jargon.irodsext.jwt;

/**
* Basic configs for a service to issue and decode jwts used in iRODS
* microservices
*
* @author Mike Conway - NIEHS
*
*/
public class JwtServiceConfig {

/**
* Issuer typically in reverse dns name format, used as "iss" in the JWT
*/
private String issuer = "";
/**
* Secret used to sign tokens given the provided algo
*/
private String secret = "";
/**
* Signing algo used in JWT
*/
private String algo = "";

public String getIssuer() {
return issuer;
}

public void setIssuer(String issuer) {
this.issuer = issuer;
}

public String getSecret() {
return secret;
}

public void setSecret(String secret) {
this.secret = secret;
}

public String getAlgo() {
return algo;
}

public void setAlgo(String algo) {
this.algo = algo;
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("JwtServiceConfig [issuer=").append(issuer).append(", algo=").append(algo).append("]");
return builder.toString();
}

}
9 changes: 9 additions & 0 deletions src/main/java/org/irods/jargon/irodsext/jwt/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

/**
* Utils and services to support use of JWT tokens in Jargon extensions and
* microservices
*
* @author Mike Conway - NIEHS
*
*/
package org.irods.jargon.irodsext.jwt;
Empty file added src/main/resources/.gitinclude
Empty file.
Empty file added src/test/java/.gitinclude
Empty file.
Loading

0 comments on commit db157eb

Please sign in to comment.