Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Password Management Token & Server/Client IP Address check #4693

Merged
merged 14 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ public static class Reset implements Serializable {
*/
private boolean securityQuestionsEnabled = true;

/**
* Whether the Password Management Token will contain the server IP Address.
*/
private boolean includeServerIpAddress = true;

/**
* Whether the Password Management Token will contain the client IP Address.
*/
private boolean includeClientIpAddress = true;

/**
* How long in minutes should the password expiration link remain valid.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5298,6 +5298,9 @@ To learn more about this topic, [please review this guide](../installation/Passw

# cas.authn.pm.reset.expirationMinutes=1
# cas.authn.pm.reset.securityQuestionsEnabled=true
# Whether the Password Management Token will contain the client or server IP Address.
# cas.authn.pm.reset.includeServerIpAddress=true
# cas.authn.pm.reset.includeClientIpAddress=true

# Automatically log in after successful password change
# cas.authn.pm.autoLogin=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public String parseToken(final String token) {
try {
val json = this.cipherExecutor.decode(token);
val claims = JwtClaims.parse(json);
val resetProperties = properties.getReset();

if (!claims.getIssuer().equals(issuer)) {
LOGGER.error("Token issuer does not match CAS");
Expand All @@ -74,11 +75,11 @@ public String parseToken(final String token) {
}

val holder = ClientInfoHolder.getClientInfo();
if (!claims.getStringClaimValue("origin").equals(holder.getServerIpAddress())) {
if (resetProperties.isIncludeServerIpAddress() && !claims.getStringClaimValue("origin").equals(holder.getServerIpAddress())) {
LOGGER.error("Token origin server IP address does not match CAS");
return null;
}
if (!claims.getStringClaimValue("client").equals(holder.getClientIpAddress())) {
if (resetProperties.isIncludeClientIpAddress() && !claims.getStringClaimValue("client").equals(holder.getClientIpAddress())) {
LOGGER.error("Token client IP address does not match CAS");
return null;
}
Expand All @@ -102,16 +103,21 @@ public String createToken(final String to) {
try {
val token = UUID.randomUUID().toString();
val claims = new JwtClaims();
val resetProperties = properties.getReset();
claims.setJwtId(token);
claims.setIssuer(issuer);
claims.setAudience(issuer);
claims.setExpirationTimeMinutesInTheFuture(properties.getReset().getExpirationMinutes());
claims.setExpirationTimeMinutesInTheFuture(resetProperties.getExpirationMinutes());
claims.setIssuedAtToNow();

val holder = ClientInfoHolder.getClientInfo();
if (holder != null) {
claims.setStringClaim("origin", holder.getServerIpAddress());
claims.setStringClaim("client", holder.getClientIpAddress());
if (resetProperties.isIncludeServerIpAddress()) {
claims.setStringClaim("origin", holder.getServerIpAddress());
}
if (resetProperties.isIncludeClientIpAddress()) {
claims.setStringClaim("client", holder.getClientIpAddress());
}
}
claims.setSubject(to);
LOGGER.debug("Creating password management token for [{}]", to);
Expand Down