}
@Override
public String refreshEncryptedSecurityToken(String encryptedSecurityToken) throws SecurityTokenException {
//Decrypt the current token
SecurityToken securityToken = this.decryptSecurityToken(encryptedSecurityToken);
//Make sure the person is authorized to refresh this token
String userId = String.valueOf(userService.getAuthenticatedUser().getId());
if (!securityToken.getViewerId().equalsIgnoreCase(userId)) {
throw new SecurityTokenException("Illegal attempt by user " + userId +
" to refresh security token with a viewerId of " + securityToken.getViewerId());
}
//Create a new RegionWidget instance from it so we can use it to generate a new encrypted token
RegionWidget regionWidget = new RegionWidget(securityToken.getModuleId(),
new Widget(-1L, securityToken.getAppUrl()),
new Region(-1L, new Page(-1L, new User(Long.valueOf(securityToken.getOwnerId())))));
//Create and return the newly encrypted token
return getEncryptedSecurityToken(regionWidget);
}