Merge pull request #1982 from abstractj/KEYCLOAK-1919

Make use of display name by default for TOTP
This commit is contained in:
Stian Thorgersen 2016-01-06 14:26:05 +01:00
commit b2a3918fc3
3 changed files with 4 additions and 5 deletions

View file

@ -41,11 +41,9 @@ public class TotpBean {
private final String totpSecretEncoded; private final String totpSecretEncoded;
private final boolean enabled; private final boolean enabled;
private final String contextUrl; private final String contextUrl;
private final String realmName;
private final String keyUri; private final String keyUri;
public TotpBean(KeycloakSession session, RealmModel realm, UserModel user, URI baseUri) { public TotpBean(KeycloakSession session, RealmModel realm, UserModel user, URI baseUri) {
this.realmName = realm.getName();
this.enabled = session.users().configuredForCredentialType(realm.getOTPPolicy().getType(), realm, user); this.enabled = session.users().configuredForCredentialType(realm.getOTPPolicy().getType(), realm, user);
this.contextUrl = baseUri.getPath(); this.contextUrl = baseUri.getPath();

View file

@ -39,11 +39,9 @@ public class TotpBean {
private final String totpSecretEncoded; private final String totpSecretEncoded;
private final boolean enabled; private final boolean enabled;
private final String contextUrl; private final String contextUrl;
private final String realmName;
private final String keyUri; private final String keyUri;
public TotpBean(RealmModel realm, UserModel user, URI baseUri) { public TotpBean(RealmModel realm, UserModel user, URI baseUri) {
this.realmName = realm.getName();
this.enabled = user.isOtpEnabled(); this.enabled = user.isOtpEnabled();
this.contextUrl = baseUri.getPath(); this.contextUrl = baseUri.getPath();

View file

@ -97,8 +97,11 @@ public class OTPPolicy implements Serializable {
public String getKeyURI(RealmModel realm, UserModel user, String secret) { public String getKeyURI(RealmModel realm, UserModel user, String secret) {
String displayName = realm.getDisplayName();
String uri = null; String uri = null;
uri = "otpauth://" + type + "/" + realm.getName() + ":" + user.getUsername() + "?secret=" +
if (displayName == null || displayName.isEmpty()) { displayName = realm.getName(); }
uri = "otpauth://" + type + "/" + displayName + ":" + user.getUsername() + "?secret=" +
Base32.encode(secret.getBytes()) + "&digits=" + digits + "&algorithm=" + algToKeyUriAlg.get(algorithm); Base32.encode(secret.getBytes()) + "&digits=" + digits + "&algorithm=" + algToKeyUriAlg.get(algorithm);
try { try {
uri += "&issuer=" + URLEncoder.encode(realm.getName(), "UTF-8"); uri += "&issuer=" + URLEncoder.encode(realm.getName(), "UTF-8");