if there's only one key, return it as the default

pull/516/head
Justin Richer 2013-09-16 16:56:28 -04:00
parent fb2f2f9792
commit b75d77495a
2 changed files with 26 additions and 3 deletions

View File

@ -102,7 +102,9 @@ public class DefaultJwtEncryptionAndDecryptionService implements JwtEncryptionAn
throw new IllegalArgumentException("Tried to load a key from a keystore without a 'kid' field: " + key);
}
}
buildEncryptersAndDecrypters();
}
@ -116,7 +118,14 @@ public class DefaultJwtEncryptionAndDecryptionService implements JwtEncryptionAn
}
public String getDefaultEncryptionKeyId() {
return defaultEncryptionKeyId;
if (defaultEncryptionKeyId != null) {
return defaultEncryptionKeyId;
} else if (keys.size() == 1) {
// if there's only one key in the map, it's the default
return keys.keySet().iterator().next();
} else {
return null;
}
}
public void setDefaultEncryptionKeyId(String defaultEncryptionKeyId) {
@ -124,7 +133,14 @@ public class DefaultJwtEncryptionAndDecryptionService implements JwtEncryptionAn
}
public String getDefaultDecryptionKeyId() {
return defaultDecryptionKeyId;
if (defaultDecryptionKeyId != null) {
return defaultDecryptionKeyId;
} else if (keys.size() == 1) {
// if there's only one key in the map, it's the default
return keys.keySet().iterator().next();
} else {
return null;
}
}
public void setDefaultDecryptionKeyId(String defaultDecryptionKeyId) {

View File

@ -109,7 +109,14 @@ public class DefaultJwtSigningAndValidationService implements JwtSigningAndValid
* @return the defaultSignerKeyId
*/
public String getDefaultSignerKeyId() {
return defaultSignerKeyId;
if (defaultSignerKeyId != null) {
return defaultSignerKeyId;
} else if (keys.size() == 1) {
// if there's only one key, it's the default
return keys.keySet().iterator().next();
} else {
return null;
}
}
/**