-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
121 changed files
with
4,893 additions
and
3,606 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
language: java | ||
jdk: | ||
- oraclejdk7 | ||
- oraclejdk8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.jbei.auth; | ||
|
||
/** | ||
* An object specifying if a request is valid, and for which user. | ||
* | ||
* @author wcmorrell | ||
* @version 1.0 | ||
*/ | ||
public interface Authorization { | ||
|
||
/** | ||
* Pre-made invalid authorization object. | ||
*/ | ||
public static final Authorization INVALID = new Authorization() { | ||
@Override | ||
public boolean isValid() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getUserId() { | ||
return null; | ||
} | ||
}; | ||
|
||
/** | ||
* @return the user ID valid for the request | ||
*/ | ||
public String getUserId(); | ||
|
||
/** | ||
* @return {@code true} only if the request is validated | ||
*/ | ||
public boolean isValid(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* | ||
*/ | ||
package org.jbei.auth; | ||
|
||
import java.security.Key; | ||
|
||
/** | ||
* @author wcmorrell | ||
* @version 1.0 | ||
*/ | ||
public interface KeyTable { | ||
|
||
/** | ||
* @param keyId | ||
* @return the matching Key object, or {@code null} if not found | ||
*/ | ||
public abstract Key getKey(final String keyId); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* | ||
*/ | ||
package org.jbei.auth; | ||
|
||
import java.security.Key; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Simple KeyTable stores mapping of KeyID => Key in memory. | ||
* | ||
* @author wcmorrell | ||
* @version 1.0 | ||
*/ | ||
public class MemoryKeyTable extends HashMap<String, Key> implements KeyTable { | ||
|
||
private static final long serialVersionUID = 460597881793784549L; | ||
|
||
/** | ||
* Calls super HashMap constructor. | ||
*/ | ||
public MemoryKeyTable() { | ||
super(); | ||
} | ||
|
||
/** | ||
* Calls super HashMap constructor. | ||
* | ||
* @param initialCapacity the initial capacity | ||
* @param loadFactor the load factor | ||
* @throws IllegalArgumentException if the initial capacity is negative or the load factor is nonpositive | ||
*/ | ||
public MemoryKeyTable(final int initialCapacity, final float loadFactor) { | ||
super(initialCapacity, loadFactor); | ||
} | ||
|
||
/** | ||
* Calls super HashMap constructor. | ||
* | ||
* @param initialCapacity the initial capacity. | ||
* @throws IllegalArgumentException if the initial capacity is negative. | ||
*/ | ||
public MemoryKeyTable(final int initialCapacity) { | ||
super(initialCapacity); | ||
} | ||
|
||
/** | ||
* Calls super HashMap constructor. | ||
* | ||
* @param m the map whose mappings are to be placed in this map | ||
* @throws NullPointerException if the specified map is null | ||
*/ | ||
public MemoryKeyTable(final Map<? extends String, ? extends Key> m) { | ||
super(m); | ||
} | ||
|
||
@Override | ||
public Key getKey(final String keyId) { | ||
return get(keyId); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/org/jbei/auth/hmac/DefaultHmacSignature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.jbei.auth.hmac; | ||
|
||
import org.apache.commons.codec.binary.Base64; | ||
|
||
import javax.crypto.Mac; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
/** | ||
* TODO | ||
* | ||
* @author wcmorrell | ||
* @version 1.0 | ||
*/ | ||
public final class DefaultHmacSignature implements HmacSignature { | ||
|
||
private final Mac mac; | ||
private final String userId; | ||
|
||
private String signature = null; | ||
|
||
/** | ||
* @param mac | ||
* @param userId | ||
*/ | ||
public DefaultHmacSignature(final Mac mac, final String userId) { | ||
this.mac = mac; | ||
this.userId = userId; | ||
} | ||
|
||
@Override | ||
public InputStream filterInput(final InputStream stream) { | ||
return new HmacInputStream(stream, mac); | ||
} | ||
|
||
@Override | ||
public OutputStream filterOutput(final OutputStream stream) { | ||
return new HmacOutputStream(stream, mac); | ||
} | ||
|
||
@Override | ||
public String generateSignature() { | ||
if (signature == null) { | ||
final byte[] rawSignature = mac.doFinal(); | ||
signature = Base64.encodeBase64String(rawSignature); | ||
} | ||
return signature; | ||
} | ||
|
||
@Override | ||
public String getUserId() { | ||
return userId; | ||
} | ||
|
||
} |
Oops, something went wrong.