throw new IllegalArgumentException("An authorization with the same IP address already exist");
}
}
}
AuthDetail authDetail = cachingTableAuthDetails.get(oldAuthToken);
if (authDetail != null) {
// Remove all IPs from the table, and add the new one
if (authDetail.getType() == NBAuthType.IP_WHITE_LIST) {
for (String ip : authDetail.getWhiteListedIps()) {
cachingTableAuthIpAddress.remove(ip);
}
}
}
String authToken = createTokenFromAuth(auth);
Auth auth2;
// Check that the token has changed or not
if (oldAuthToken.equals(authToken) == false) {
// Check that new token doesn't exist
auth2 = cachingTableAuth.get(authToken);
if (auth2 != null)
throw new IllegalArgumentException("An authorization with the same credentials already exist");
// If token has changed, update association table
cachingTableAuthIdToAuthToken.set(auth.getId(), authToken);
// Remove old auth
auth2 = cachingTableAuth.remove(oldAuthToken);
// Remove old details
cachingTableAuthDetails.remove(oldAuthToken);
} else {
auth2 = cachingTableAuth.get(authToken);
if (auth2 == null)
throw new IllegalArgumentException("An Authorization with that token doesn't exist");
}
auth.setPolicyContexts(auth2.getPolicyContexts());
if (authDetail != null) {
// Remove all IPs from the table, and add the new one
if (authDetail.getType() == NBAuthType.IP_WHITE_LIST) {
for (String ip : authDetail.getWhiteListedIps()) {
cachingTableAuthIpAddress.remove(ip);
}
}
}