Updated our ClientDetailsEntity *TokenTimeout fields to be *ValiditySeconds, which are now typed as proper Integers in the SECOAUTH ClientDetails interface

pull/105/merge
Amanda Anganes 2012-06-26 13:54:01 -04:00
parent b41b4f2e6a
commit 81d1af40bd
7 changed files with 56 additions and 63 deletions

View File

@ -69,8 +69,8 @@ public class ClientDetailsEntity implements ClientDetails {
private String clientName = ""; private String clientName = "";
private String clientDescription = ""; private String clientDescription = "";
private boolean allowRefresh = false; // do we allow refresh tokens for this client? private boolean allowRefresh = false; // do we allow refresh tokens for this client?
private Integer accessTokenTimeout = 0; // in seconds private Integer accessTokenValiditySeconds = 0; // in seconds
private Integer refreshTokenTimeout = 0; // in seconds private Integer refreshTokenValiditySeconds = 0; // in seconds
private String owner = ""; // userid of who registered it private String owner = ""; // userid of who registered it
private Set<String> registeredRedirectUri = new HashSet<String>(); private Set<String> registeredRedirectUri = new HashSet<String>();
private Set<String> resourceIds = new HashSet<String>(); private Set<String> resourceIds = new HashSet<String>();
@ -272,35 +272,43 @@ public class ClientDetailsEntity implements ClientDetails {
this.allowRefresh = allowRefresh; this.allowRefresh = allowRefresh;
} }
/** @Override
* @param accessTokenTimeout Lifetime of access tokens, in seconds (optional - leave null for no timeout)
*/
@Basic @Basic
public Integer getAccessTokenTimeout() { public Integer getAccessTokenValiditySeconds() {
return accessTokenTimeout; return accessTokenValiditySeconds;
} }
/** /**
* @param accessTokenTimeout the accessTokenTimeout to set * @param accessTokenTimeout the accessTokenTimeout to set
*/ */
public void setAccessTokenTimeout(Integer accessTokenTimeout) { public void setAccessTokenValiditySeconds(Integer accessTokenValiditySeconds) {
this.accessTokenTimeout = accessTokenTimeout; this.accessTokenValiditySeconds = accessTokenValiditySeconds;
} }
/**
* @return the refreshTokenTimeout @Override
*/
@Basic @Basic
public Integer getRefreshTokenTimeout() { public Integer getRefreshTokenValiditySeconds() {
return refreshTokenTimeout; return refreshTokenValiditySeconds;
} }
/** /**
* @param refreshTokenTimeout Lifetime of refresh tokens, in seconds (optional - leave null for no timeout) * @param refreshTokenTimeout Lifetime of refresh tokens, in seconds (optional - leave null for no timeout)
*/ */
public void setRefreshTokenTimeout(Integer refreshTokenTimeout) { public void setRefreshTokenValiditySeconds(Integer refreshTokenValiditySeconds) {
this.refreshTokenTimeout = refreshTokenTimeout; this.refreshTokenValiditySeconds = refreshTokenValiditySeconds;
} }
//TODO: implement fully with db table or get removed from interface
@Override
@Transient
public Map<String, Object> getAdditionalInformation() {
return this.additionalInformation;
}
public void setAdditionalInformation(Map<String, Object> map) {
this.additionalInformation = map;
}
/** /**
* @return the owner * @return the owner
@ -487,8 +495,8 @@ public class ClientDetailsEntity implements ClientDetails {
* @param accessTokenTimeout * @param accessTokenTimeout
* @see org.mitre.oauth2.model.ClientDetailsEntity#setAccessTokenTimeout(java.lang.Long) * @see org.mitre.oauth2.model.ClientDetailsEntity#setAccessTokenTimeout(java.lang.Long)
*/ */
public ClientDetailsEntityBuilder setAccessTokenTimeout(int accessTokenTimeout) { public ClientDetailsEntityBuilder setAccessValiditySeconds(int accessTokenValiditySeconds) {
instance.setAccessTokenTimeout(accessTokenTimeout); instance.setAccessTokenValiditySeconds(accessTokenValiditySeconds);
return this; return this;
} }
@ -496,8 +504,8 @@ public class ClientDetailsEntity implements ClientDetails {
* @param refreshTokenTimeout * @param refreshTokenTimeout
* @see org.mitre.oauth2.model.ClientDetailsEntity#setRefreshTokenTimeout(java.lang.Long) * @see org.mitre.oauth2.model.ClientDetailsEntity#setRefreshTokenTimeout(java.lang.Long)
*/ */
public ClientDetailsEntityBuilder setRefreshTokenTimeout(int refreshTokenTimeout) { public ClientDetailsEntityBuilder setRefreshTokenValiditySeconds(int refreshTokenValiditySeconds) {
instance.setRefreshTokenTimeout(refreshTokenTimeout); instance.setRefreshTokenValiditySeconds(refreshTokenValiditySeconds);
return this; return this;
} }
@ -538,28 +546,6 @@ public class ClientDetailsEntity implements ClientDetails {
} }
@Override
public int getAccessTokenValiditySeconds() {
return accessTokenTimeout;
}
@Override
public int getRefreshTokenValiditySeconds() {
return refreshTokenTimeout;
}
public void setAdditionalInformation(Map<String, Object> map) {
this.additionalInformation = map;
}
//TODO: implement fully with db table or get removed from interface
@Override
@Transient
public Map<String, Object> getAdditionalInformation() {
return this.additionalInformation;
}
/* *//** /* *//**
* @return the contacts * @return the contacts
*//* *//*

View File

@ -4,7 +4,7 @@ CREATE TABLE clientdetails (
clientName VARCHAR(256), clientName VARCHAR(256),
clientDescription VARCHAR(2000), clientDescription VARCHAR(2000),
allowRefresh TINYINT, allowRefresh TINYINT,
accessTokenTimeout BIGINT, accessTokenValiditySeconds BIGINT,
refreshTokenTimeout BIGINT, refreshTokenValiditySeconds BIGINT,
owner VARCHAR(256) owner VARCHAR(256)
); );

View File

@ -99,8 +99,8 @@ public class DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEnt
client.setClientName(name); client.setClientName(name);
client.setClientDescription(description); client.setClientDescription(description);
client.setAllowRefresh(allowRefresh); client.setAllowRefresh(allowRefresh);
client.setAccessTokenTimeout(accessTokenTimeout); client.setAccessTokenValiditySeconds(accessTokenTimeout);
client.setRefreshTokenTimeout(refreshTokenTimeout); client.setRefreshTokenValiditySeconds(refreshTokenTimeout);
client.setResourceIds(resourceIds); client.setResourceIds(resourceIds);
client.setOwner(owner); client.setOwner(owner);

View File

@ -111,8 +111,8 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
// make it expire if necessary // make it expire if necessary
// TODO: pending upstream updates, check for 0 or -1 value here // TODO: pending upstream updates, check for 0 or -1 value here
if (client.getAccessTokenTimeout() != null && client.getAccessTokenTimeout() > 0) { if (client.getAccessTokenValiditySeconds() != null && client.getAccessTokenValiditySeconds() > 0) {
Date expiration = new Date(System.currentTimeMillis() + (client.getAccessTokenTimeout() * 1000L)); Date expiration = new Date(System.currentTimeMillis() + (client.getAccessTokenValiditySeconds() * 1000L));
token.setExpiration(expiration); token.setExpiration(expiration);
} }
@ -124,8 +124,8 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
OAuth2RefreshTokenEntity refreshToken = refreshTokenFactory.createNewRefreshToken(); OAuth2RefreshTokenEntity refreshToken = refreshTokenFactory.createNewRefreshToken();
// make it expire if necessary // make it expire if necessary
if (client.getRefreshTokenTimeout() != null) { if (client.getRefreshTokenValiditySeconds() != null) {
Date expiration = new Date(System.currentTimeMillis() + (client.getRefreshTokenTimeout() * 1000L)); Date expiration = new Date(System.currentTimeMillis() + (client.getRefreshTokenValiditySeconds() * 1000L));
refreshToken.setExpiration(expiration); refreshToken.setExpiration(expiration);
} }
@ -198,8 +198,8 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
token.setClient(client); token.setClient(client);
if (client.getAccessTokenTimeout() != null) { if (client.getAccessTokenValiditySeconds() != null) {
Date expiration = new Date(System.currentTimeMillis() + (client.getAccessTokenTimeout() * 1000L)); Date expiration = new Date(System.currentTimeMillis() + (client.getAccessTokenValiditySeconds() * 1000L));
token.setExpiration(expiration); token.setExpiration(expiration);
} }

View File

@ -188,8 +188,8 @@ public class OAuthClientAPI {
client.setClientName(name); client.setClientName(name);
client.setClientDescription(description); client.setClientDescription(description);
client.setAllowRefresh(allowRefresh); client.setAllowRefresh(allowRefresh);
client.setAccessTokenTimeout(accessTokenTimeout); client.setAccessTokenValiditySeconds(accessTokenTimeout);
client.setRefreshTokenTimeout(refreshTokenTimeout); client.setRefreshTokenValiditySeconds(refreshTokenTimeout);
client.setOwner(owner); client.setOwner(owner);
clientService.updateClient(client, client); clientService.updateClient(client, client);

View File

@ -55,10 +55,12 @@ public class UserInfoEndpoint {
/** /**
* Get information about the user as specified in the accessToken->idToken included in this request * Get information about the user as specified in the accessToken->idToken included in this request
* *
* @param accessToken the Access Token associated with this request * @param accessToken the Access Token associated with this request
* @param schema the data schema to use, default is openid * @param schema the data schema to use, default is openid
* @param mav the ModelAndView object associated with this request * @param mav the ModelAndView object associated with this request
* @return JSON or JWT response containing UserInfo data * @return JSON or JWT response containing UserInfo data
* @throws UsernameNotFoundException if the user does not exist or cannot be found
* @throws UnknownUserInfoSchemaException if an unknown schema is used
*/ */
@RequestMapping(value="/userinfo", method= {RequestMethod.GET, RequestMethod.POST}) @RequestMapping(value="/userinfo", method= {RequestMethod.GET, RequestMethod.POST})
public ModelAndView getInfo(Principal p, @RequestParam("schema") String schema, ModelAndView mav) { public ModelAndView getInfo(Principal p, @RequestParam("schema") String schema, ModelAndView mav) {
@ -78,6 +80,11 @@ public class UserInfoEndpoint {
} }
String userId = p.getName(); String userId = p.getName();
UserInfo userInfo = userInfoService.getByUserId(userId); UserInfo userInfo = userInfoService.getByUserId(userId);
if (userInfo == null) {
throw new UsernameNotFoundException("Invalid User");
}
return new ModelAndView(viewName, "userInfo", userInfo); return new ModelAndView(viewName, "userInfo", userInfo);
} }

@ -1 +1 @@
Subproject commit 90b223a4b0dc89cac723690da7b7dc9b360620e0 Subproject commit 2a3e2636d0c85620fbd495b40c5ef8fe11a94eba