-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from RootServices/release-1.0
Release 1.0
- Loading branch information
Showing
23 changed files
with
983 additions
and
0 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
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,151 @@ | ||
<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> | ||
|
||
<name>Otter</name> | ||
<description>Mirco web framework for servlet api 3.1</description> | ||
<groupId>org.rootservices</groupId> | ||
<artifactId>otter</artifactId> | ||
<packaging>jar</packaging> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<url>https://github.com/RootServices/otter</url> | ||
<licenses> | ||
<license> | ||
<url>https://github.com/RootServices/otter/blob/development/LICENSE</url> | ||
</license> | ||
</licenses> | ||
<scm> | ||
<url>https://github.com/RootServices/otter</url> | ||
</scm> | ||
<developers> | ||
<developer> | ||
<id>tmackenzie</id> | ||
</developer> | ||
</developers> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
<servlet.version>3.1.0</servlet.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>${servlet.version}</version> | ||
</dependency> | ||
|
||
<!-- Test Dependencies --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-all</artifactId> | ||
<version>1.9.5</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.5</version> | ||
<configuration> | ||
<parallel>methods</parallel> | ||
<threadCount>5</threadCount> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.1</version> | ||
<configuration> | ||
<source>${java.version}</source> | ||
<target>${java.version}</target> | ||
<showDeprecation>true</showDeprecation> | ||
<showWarnings>true</showWarnings> | ||
<compilerArgument>-Xlint:unchecked</compilerArgument> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>2.4</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<version>2.9.1</version> | ||
<executions> | ||
<execution> | ||
<id>attach-javadocs</id> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<distributionManagement> | ||
<snapshotRepository> | ||
<id>sonatype-nexus-snapshots</id> | ||
<name>Sonatype Nexus snapshot repository</name> | ||
<url>https://oss.sonatype.org/content/repositories/snapshots</url> | ||
</snapshotRepository> | ||
<repository> | ||
<id>sonatype-nexus-staging</id> | ||
<name>Sonatype Nexus release repository</name> | ||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url> | ||
</repository> | ||
</distributionManagement> | ||
|
||
<profiles> | ||
<profile> | ||
<id>release-sign-artifacts</id> | ||
<activation> | ||
<property> | ||
<name>performRelease</name> | ||
<value>true</value> | ||
</property> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-gpg-plugin</artifactId> | ||
<version>1.4</version> | ||
<configuration> | ||
<passphrase>${gpg.passphrase}</passphrase> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>sign-artifacts</id> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>sign</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/rootservices/otter/QueryStringToMap.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,13 @@ | ||
package org.rootservices.otter; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Created by tommackenzie on 4/22/15. | ||
*/ | ||
public interface QueryStringToMap { | ||
Map<String, List<String>> run(Optional<String> queryString) throws UnsupportedEncodingException; | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/org/rootservices/otter/QueryStringToMapImpl.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,36 @@ | ||
package org.rootservices.otter; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.net.URLDecoder; | ||
import java.util.*; | ||
|
||
/** | ||
* Created by tommackenzie on 4/22/15. | ||
*/ | ||
public class QueryStringToMapImpl implements QueryStringToMap { | ||
|
||
@Override | ||
public Map<String, List<String>> run(Optional<String> queryString) throws UnsupportedEncodingException { | ||
Map<String, List<String>> parameters = new HashMap<String, List<String>>(); | ||
if ( queryString.isPresent() && !queryString.get().isEmpty()) { | ||
String decoded = URLDecoder.decode(queryString.get(), "UTF-8"); | ||
String[] parts = decoded.split("&"); | ||
|
||
for (String part : parts) { | ||
String[] nameAndValue = part.split("="); | ||
List<String> items; | ||
if (parameters.containsKey(nameAndValue[0])) { | ||
items = parameters.get(nameAndValue[0]); | ||
} else { | ||
items = new ArrayList<>(); | ||
|
||
} | ||
if (nameAndValue.length == 2) { | ||
items.add(nameAndValue[1]); | ||
} | ||
parameters.put(nameAndValue[0], items); | ||
} | ||
} | ||
return parameters; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/org/rootservices/otter/authentication/HttpBasicEntity.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,30 @@ | ||
package org.rootservices.otter.authentication; | ||
|
||
/** | ||
* Created by tommackenzie on 6/4/15. | ||
*/ | ||
public class HttpBasicEntity { | ||
private String user; | ||
private String password; | ||
|
||
public HttpBasicEntity(String user, String password) { | ||
this.user = user; | ||
this.password = password; | ||
} | ||
|
||
public String getUser() { | ||
return user; | ||
} | ||
|
||
public void setUser(String user) { | ||
this.user = user; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/rootservices/otter/authentication/ParseHttpBasic.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,10 @@ | ||
package org.rootservices.otter.authentication; | ||
|
||
import org.rootservices.otter.authentication.exception.HttpBasicException; | ||
|
||
/** | ||
* Created by tommackenzie on 6/4/15. | ||
*/ | ||
public interface ParseHttpBasic { | ||
HttpBasicEntity run(String header) throws HttpBasicException; | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/org/rootservices/otter/authentication/ParseHttpBasicImpl.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,46 @@ | ||
package org.rootservices.otter.authentication; | ||
|
||
import org.rootservices.otter.authentication.exception.HttpBasicException; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.util.Base64; | ||
|
||
/** | ||
* Created by tommackenzie on 6/4/15. | ||
*/ | ||
public class ParseHttpBasicImpl implements ParseHttpBasic { | ||
|
||
@Override | ||
public HttpBasicEntity run(String header) throws HttpBasicException { | ||
|
||
if (header == null || header.isEmpty()) { | ||
throw new HttpBasicException("header is null or empty"); | ||
} | ||
|
||
String[] encodedCredentials = header.split("Basic "); | ||
|
||
if ( encodedCredentials.length != 2 || encodedCredentials[1].isEmpty()) { | ||
throw new HttpBasicException("header is not Basic authentication scheme"); | ||
} | ||
|
||
byte[] decodedBasicCredentialsBytes = null; | ||
decodedBasicCredentialsBytes = Base64.getDecoder().decode(encodedCredentials[1].getBytes()); | ||
|
||
String decodedBasicCredentials = null; | ||
try { | ||
decodedBasicCredentials = new String(decodedBasicCredentialsBytes, "UTF-8"); | ||
} catch (UnsupportedEncodingException e) { | ||
throw new HttpBasicException("Could not convert bytes to UTF-8 string"); | ||
} | ||
|
||
String[] parsedCredentials = decodedBasicCredentials.split(":"); | ||
|
||
if ( parsedCredentials.length != 2 || parsedCredentials[0].isEmpty() || parsedCredentials[1].isEmpty()) { | ||
throw new HttpBasicException("Could not parse header"); | ||
} | ||
HttpBasicEntity entity = new HttpBasicEntity( | ||
parsedCredentials[0], parsedCredentials[1] | ||
); | ||
return entity; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/org/rootservices/otter/authentication/exception/HttpBasicException.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,12 @@ | ||
package org.rootservices.otter.authentication.exception; | ||
|
||
/** | ||
* Created by tommackenzie on 6/4/15. | ||
*/ | ||
public class HttpBasicException extends Exception { | ||
|
||
public HttpBasicException(String message) { | ||
super(message); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/org/rootservices/otter/router/GetServletURI.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,8 @@ | ||
package org.rootservices.otter.router; | ||
|
||
/** | ||
* Created by tommackenzie on 5/2/15. | ||
*/ | ||
public interface GetServletURI { | ||
String run(String baseURI, Class clazz); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/org/rootservices/otter/router/GetServletURIImpl.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,21 @@ | ||
package org.rootservices.otter.router; | ||
|
||
import javax.servlet.annotation.WebServlet; | ||
|
||
/** | ||
* Created by tommackenzie on 5/2/15. | ||
*/ | ||
public class GetServletURIImpl implements GetServletURI { | ||
|
||
@Override | ||
public String run(String baseURI, Class clazz) { | ||
WebServlet webServlet = (WebServlet) clazz.getAnnotation(WebServlet.class); | ||
|
||
// prevent duplicate "/" | ||
if (baseURI.endsWith("/") && webServlet.value()[0].startsWith("/")) { | ||
baseURI = baseURI.substring(0, baseURI.length()-1); | ||
} | ||
return baseURI + webServlet.value()[0]; | ||
|
||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/org/rootservices/otter/security/RandomString.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,8 @@ | ||
package org.rootservices.otter.security; | ||
|
||
/** | ||
* Created by tommackenzie on 8/5/15. | ||
*/ | ||
public interface RandomString { | ||
String run(); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/org/rootservices/otter/security/RandomStringImpl.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,23 @@ | ||
package org.rootservices.otter.security; | ||
|
||
import java.math.BigInteger; | ||
import java.security.SecureRandom; | ||
|
||
/** | ||
* Created by tommackenzie on 8/5/15. | ||
*/ | ||
public class RandomStringImpl implements RandomString { | ||
|
||
private SecureRandom secureRandom = new SecureRandom(); | ||
|
||
public RandomStringImpl() {} | ||
|
||
public RandomStringImpl(SecureRandom secureRandom) { | ||
this.secureRandom = secureRandom; | ||
} | ||
|
||
@Override | ||
public String run() { | ||
return new BigInteger(130, secureRandom).toString(32); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/rootservices/otter/security/csrf/Csrf.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,13 @@ | ||
package org.rootservices.otter.security.csrf; | ||
|
||
import org.rootservices.otter.security.csrf.exception.CsrfException; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Created by tommackenzie on 4/9/16. | ||
*/ | ||
public interface Csrf { | ||
void checkTokens(HttpServletRequest httpRequest) throws CsrfException; | ||
} |
Oops, something went wrong.