This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://bugzilla.redhat.com/show_bug.cgi?id=1172618 Squashed commit of the following: commit 7dcf92e Author: Alex Eng <aeng@redhat.com> Date: Thu Mar 26 15:29:00 2015 +1000 Fix 'download-tmx missing quote' commit 9297d20 Author: Alex Eng <aeng@redhat.com> Date: Tue Mar 24 16:20:33 2015 +1000 Remove single quote on API Key in error message commit 4127de2 Author: Alex Eng <aeng@redhat.com> Date: Tue Mar 24 15:17:29 2015 +1000 Add release notes commit e390c86 Merge: bd0d3e8 fe9939d Author: Alex Eng <aeng@redhat.com> Date: Tue Mar 24 15:16:33 2015 +1000 Merge branch 'release' into rhbz1172618 commit bd0d3e8 Author: Alex Eng <aeng@redhat.com> Date: Tue Mar 24 13:17:07 2015 +1000 Add authentication check for TMX REST commit e7ec0cf Author: Alex Eng <aeng@redhat.com> Date: Tue Mar 24 07:16:37 2015 +1000 Fix RawRestTest commit ff97eab Merge: 65b6188 fd1eab8 Author: Alex Eng <aeng@redhat.com> Date: Tue Mar 24 06:53:20 2015 +1000 Merge branch 'release' into rhbz1172618 commit 65b6188 Author: Alex Eng <aeng@redhat.com> Date: Mon Mar 23 13:04:36 2015 +1000 Refactor rate limiter key, fix functional test commit 8a7343b Author: Alex Eng <aeng@redhat.com> Date: Mon Mar 23 11:43:26 2015 +1000 Add ZANATA_PROXY_HEADER for proxy-header scan commit 30a3ae7 Author: Alex Eng <aeng@redhat.com> Date: Sun Mar 22 01:04:40 2015 +1000 Refactor test and RestLimitingSynchronousDispatcher from PR review commit a49a516 Author: Alex Eng <aeng@redhat.com> Date: Fri Mar 20 15:56:16 2015 +1000 Fix checkstyle commit ec6bea8 Author: Alex Eng <aeng@redhat.com> Date: Fri Mar 20 15:55:02 2015 +1000 Add unit test and integration test for anonymous REST request commit 3bf93ab Author: Alex Eng <aeng@redhat.com> Date: Thu Mar 19 09:18:22 2015 +1000 Allow anonymous REST request for READ: https://bugzilla.redhat.com/show_bug.cgi?id=1172618
- Loading branch information
Alex Eng
committed
Mar 29, 2015
1 parent
97545b4
commit 8ccbfa1
Showing
20 changed files
with
745 additions
and
113 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
72 changes: 72 additions & 0 deletions
72
zanata-war/src/main/java/org/zanata/limits/RateLimiterToken.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,72 @@ | ||
/* | ||
* Copyright 2015, Red Hat, Inc. and individual contributors as indicated by the | ||
* @author tags. See the copyright.txt file in the distribution for a full | ||
* listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it under the | ||
* terms of the GNU Lesser General Public License as published by the Free | ||
* Software Foundation; either version 2.1 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this software; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF | ||
* site: http://www.fsf.org. | ||
*/ | ||
|
||
package org.zanata.limits; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
/** | ||
* Token used for rate limiter queue. | ||
* | ||
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a> | ||
*/ | ||
@EqualsAndHashCode | ||
@ToString | ||
public class RateLimiterToken { | ||
|
||
@Getter | ||
private final String value; | ||
|
||
@Getter | ||
private final TYPE type; | ||
|
||
public static enum TYPE { | ||
USERNAME, API_KEY, IP_ADDRESS; | ||
} | ||
|
||
public RateLimiterToken(TYPE type, String value) { | ||
this.type = type; | ||
this.value = value; | ||
} | ||
|
||
/** | ||
* Generate key from username | ||
*/ | ||
public static RateLimiterToken fromUsername(String username) { | ||
return new RateLimiterToken(TYPE.USERNAME, username); | ||
} | ||
|
||
/** | ||
* Generate key from api key | ||
*/ | ||
public static RateLimiterToken fromApiKey(String apiKey) { | ||
return new RateLimiterToken(TYPE.API_KEY, apiKey); | ||
} | ||
|
||
/** | ||
* Generate key from ip address | ||
*/ | ||
public static RateLimiterToken fromIPAddress(String ipAddress) { | ||
return new RateLimiterToken(TYPE.IP_ADDRESS, ipAddress); | ||
} | ||
} |
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
25 changes: 0 additions & 25 deletions
25
zanata-war/src/main/java/org/zanata/rest/HeaderHelper.java
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
zanata-war/src/main/java/org/zanata/rest/InvalidApiKeyUtil.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,31 @@ | ||
package org.zanata.rest; | ||
|
||
/** | ||
* Utility for invalid API key exception. | ||
* | ||
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a> | ||
*/ | ||
public class InvalidApiKeyUtil { | ||
public static final String message = "Invalid API key"; | ||
|
||
public static String getMessage(String username, String apiKey, | ||
String additionalMessage) { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(getMessage(username, apiKey)) | ||
.append(" ").append(additionalMessage); | ||
return sb.toString(); | ||
} | ||
|
||
public static String getMessage(String username, String apiKey) { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(message).append(" for user: [").append(username).append("]") | ||
.append(" apiKey: [").append(apiKey).append("]."); | ||
return sb.toString(); | ||
} | ||
|
||
public static String getMessage(String additionalMessage) { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(message).append(". ").append(additionalMessage); | ||
return sb.toString(); | ||
} | ||
} |
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
Oops, something went wrong.