}
@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().getUsername());
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 RegionWidgetImpl(Long.toString(securityToken.getModuleId()),
"-1",
new RegionImpl("-1", new PageImpl("-1", userService.getUserByUsername(securityToken.getOwnerId()).getId()), -1));
//Create and return the newly encrypted token
return getEncryptedSecurityToken(regionWidget, new WidgetImpl("-1", securityToken.getAppUrl()));
}