Skip to content

Commit

Permalink
update validator
Browse files Browse the repository at this point in the history
  • Loading branch information
imidya committed Jul 20, 2015
1 parent 0a7fb8e commit c886344
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
3 changes: 0 additions & 3 deletions JettyServer.xml
Expand Up @@ -27,7 +27,6 @@
<Set name="SpawnOrShrinkAt">2</Set>
</New>
</Set>

<Set name="handler">
<New id="Handlers" class="org.mortbay.jetty.handler.HandlerCollection">
<Set name="handlers">
Expand All @@ -46,10 +45,8 @@
</Set>
</New>
</Set>

<Set name="stopAtShutdown">true</Set>
<Set name="sendServerVersion">true</Set>
<Set name="sendDateHeader">true</Set>
<Set name="gracefulShutdown">1000</Set>

</Configure>
Expand Up @@ -12,31 +12,32 @@ public class TokenValidator {
private final static int EXPIRED_TIME = 60;

public static boolean verify(long accountId, String clientPublicToken,
String clientDisposableToken, long timestamp) {
String clientDisposableToken, long timestamp) throws Exception {
TokenObject token = TokenObject.get(accountId, clientPublicToken);
String disposableToken;
try {
disposableToken = genDisposable(token.getPublicToken(), token.getPrivateToken(), timestamp);
} catch (Exception e) {
e.printStackTrace();
return false;
}

if (CHECK_TIME) {
long currentTime = System.currentTimeMillis();
if (currentTime - timestamp > EXPIRED_TIME) {
return false;
throw new Exception("Request is expired");
}
}

if (CHECK_PUBLIC_TOKEN) {
if (!clientPublicToken.equals(token.getPublicToken())) {
return false;
throw new Exception("Public token error");
}
}

if (CHECK_DISPOSABLE_TOKEN) {
if (!clientDisposableToken.equals(disposableToken)) {
return false;
throw new Exception("Token is not acceptable");
}
}

Expand Down

0 comments on commit c886344

Please sign in to comment.