Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Commit

Permalink
Change expiresIn parameter from Integer to Long to avoid overflows. S…
Browse files Browse the repository at this point in the history
…OCIAL-356
  • Loading branch information
habuma committed Jun 27, 2013
1 parent 49f938a commit 8e55ade
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
Expand Up @@ -36,7 +36,7 @@ public AccessGrant(String accessToken) {
this(accessToken, null, null, null);
}

public AccessGrant(String accessToken, String scope, String refreshToken, Integer expiresIn) {
public AccessGrant(String accessToken, String scope, String refreshToken, Long expiresIn) {
this.accessToken = accessToken;
this.scope = scope;
this.refreshToken = refreshToken;
Expand Down
Expand Up @@ -230,7 +230,7 @@ protected AccessGrant postForAccessGrant(String accessTokenUrl, MultiValueMap<St
* @param response all parameters from the response received in the access token exchange.
* @return an {@link AccessGrant}
*/
protected AccessGrant createAccessGrant(String accessToken, String scope, String refreshToken, Integer expiresIn, Map<String, Object> response) {
protected AccessGrant createAccessGrant(String accessToken, String scope, String refreshToken, Long expiresIn, Map<String, Object> response) {
return new AccessGrant(accessToken, scope, refreshToken, expiresIn);
}

Expand Down Expand Up @@ -279,9 +279,9 @@ private AccessGrant extractAccessGrant(Map<String, Object> result) {
}

// Retrieves object from map into an Integer, regardless of the object's actual type. Allows for flexibility in object type (eg, "3600" vs 3600).
private Integer getIntegerValue(Map<String, Object> map, String key) {
private Long getIntegerValue(Map<String, Object> map, String key) {
try {
return Integer.valueOf(String.valueOf(map.get(key))); // normalize to String before creating integer value;
return Long.valueOf(String.valueOf(map.get(key))); // normalize to String before creating integer value;
} catch (NumberFormatException e) {
return null;
}
Expand Down
Expand Up @@ -341,7 +341,7 @@ public void removeConnectionNoOp() {

@Test
public void addConnection() {
Connection<TestFacebookApi> connection = connectionFactory.createConnection(new AccessGrant("123456789", null, "987654321", 3600));
Connection<TestFacebookApi> connection = connectionFactory.createConnection(new AccessGrant("123456789", null, "987654321", 3600L));
connectionRepository.addConnection(connection);
Connection<TestFacebookApi> restoredConnection = connectionRepository.getPrimaryConnection(TestFacebookApi.class);
assertEquals(connection, restoredConnection);
Expand All @@ -350,7 +350,7 @@ public void addConnection() {

@Test(expected=DuplicateConnectionException.class)
public void addConnectionDuplicate() {
Connection<TestFacebookApi> connection = connectionFactory.createConnection(new AccessGrant("123456789", null, "987654321", 3600));
Connection<TestFacebookApi> connection = connectionFactory.createConnection(new AccessGrant("123456789", null, "987654321", 3600L));
connectionRepository.addConnection(connection);
connectionRepository.addConnection(connection);
}
Expand Down Expand Up @@ -482,10 +482,10 @@ public AccessGrant exchangeCredentialsForAccess(String username, String password
return null;
}
public AccessGrant refreshAccess(String refreshToken, MultiValueMap<String, String> additionalParameters) {
return new AccessGrant("765432109", "read", "654321098", 3600);
return new AccessGrant("765432109", "read", "654321098", 3600L);
}
public AccessGrant refreshAccess(String refreshToken, String scope, MultiValueMap<String, String> additionalParameters) {
return new AccessGrant("765432109", "read", "654321098", 3600);
return new AccessGrant("765432109", "read", "654321098", 3600L);
}
public AccessGrant authenticateClient() {
return null;
Expand Down
Expand Up @@ -288,7 +288,7 @@ public void removeConnectionNoOp() {

@Test
public void addConnection() {
Connection<TestFacebookApi> connection = facebookConnectionFactory.createConnection(new AccessGrant("123456789", null, "987654321", 3600));
Connection<TestFacebookApi> connection = facebookConnectionFactory.createConnection(new AccessGrant("123456789", null, "987654321", 3600L));
connectionRepository.addConnection(connection);
Connection<TestFacebookApi> restoredConnection = connectionRepository.getPrimaryConnection(TestFacebookApi.class);
assertEquals(connection, restoredConnection);
Expand All @@ -297,7 +297,7 @@ public void addConnection() {

@Test(expected=DuplicateConnectionException.class)
public void addConnectionDuplicate() {
Connection<TestFacebookApi> connection = facebookConnectionFactory.createConnection(new AccessGrant("123456789", null, "987654321", 3600));
Connection<TestFacebookApi> connection = facebookConnectionFactory.createConnection(new AccessGrant("123456789", null, "987654321", 3600L));
connectionRepository.addConnection(connection);
connectionRepository.addConnection(connection);
}
Expand Down Expand Up @@ -435,10 +435,10 @@ public AccessGrant exchangeCredentialsForAccess(String username, String password
return null;
}
public AccessGrant refreshAccess(String refreshToken, MultiValueMap<String, String> additionalParameters) {
return new AccessGrant("765432109", "read", "654321098", 3600);
return new AccessGrant("765432109", "read", "654321098", 3600L);
}
public AccessGrant refreshAccess(String refreshToken, String scope, MultiValueMap<String, String> additionalParameters) {
return new AccessGrant("765432109", "read", "654321098", 3600);
return new AccessGrant("765432109", "read", "654321098", 3600L);
}
public AccessGrant authenticateClient() {
return null;
Expand Down
Expand Up @@ -32,25 +32,25 @@ public String buildAuthenticateUrl(GrantType grantType, OAuth2Parameters paramet
}

public AccessGrant exchangeForAccess(String authorizationGrant, String redirectUri, MultiValueMap<String, String> additionalParameters) {
return new AccessGrant("12345", null, "23456", 3600);
return new AccessGrant("12345", null, "23456", 3600L);
}

public AccessGrant exchangeCredentialsForAccess(String username, String password, MultiValueMap<String, String> additionalParameters) {
return new AccessGrant("12345", null, "23456", 3600);
return new AccessGrant("12345", null, "23456", 3600L);
}

public AccessGrant refreshAccess(String refreshToken, MultiValueMap<String, String> additionalParameters) {
return new AccessGrant("12345", null, "23456", 3600);
return new AccessGrant("12345", null, "23456", 3600L);
}

public AccessGrant refreshAccess(String refreshToken, String scope, MultiValueMap<String, String> additionalParameters) {
return new AccessGrant("12345", null, "23456", 3600);
return new AccessGrant("12345", null, "23456", 3600L);
}
public AccessGrant authenticateClient() {
return new AccessGrant("12345", null, null, 3600);
return new AccessGrant("12345", null, null, 3600L);
}
public AccessGrant authenticateClient(String scope) {
return new AccessGrant("12345", null, null, 3600);
return new AccessGrant("12345", null, null, 3600L);
}

}

0 comments on commit 8e55ade

Please sign in to comment.