-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from Jonbeckas/migrate-totp
feat: add support for migrating totp
- Loading branch information
Showing
9 changed files
with
358 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/main/java/com/danielfrak/code/keycloak/providers/rest/remote/LegacyTotp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.danielfrak.code.keycloak.providers.rest.remote; | ||
|
||
import java.util.Objects; | ||
|
||
public class LegacyTotp { | ||
|
||
private String secret; | ||
private String name; | ||
private int digits; | ||
private int period; | ||
private String algorithm; | ||
private String encoding; | ||
|
||
public String getSecret() { | ||
return this.secret; | ||
} | ||
|
||
public void setSecret(String secret) { | ||
this.secret = secret; | ||
} | ||
|
||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public int getDigits() { | ||
return this.digits; | ||
} | ||
|
||
public void setDigits(int digits) { | ||
this.digits = digits; | ||
} | ||
|
||
public int getPeriod() { | ||
return this.period; | ||
} | ||
|
||
public void setPeriod(int period) { | ||
this.period = period; | ||
} | ||
|
||
public String getAlgorithm() { | ||
return this.algorithm; | ||
} | ||
|
||
public void setAlgorithm(String algorith) { | ||
this.algorithm = algorith; | ||
} | ||
|
||
public String getEncoding() { | ||
return this.encoding; | ||
} | ||
|
||
public void setEncoding(String encoding) { | ||
this.encoding = encoding; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
LegacyTotp legacyTotp = (LegacyTotp) o; | ||
|
||
return Objects.equals(secret, legacyTotp.secret) && | ||
Objects.equals(name, legacyTotp.name) && | ||
Objects.equals(algorithm, legacyTotp.algorithm) && | ||
Objects.equals(encoding, legacyTotp.encoding) && | ||
digits == legacyTotp.digits && | ||
period == legacyTotp.period; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name, secret, digits, period, algorithm, encoding); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/test/java/com/danielfrak/code/keycloak/providers/rest/remote/LegacyTotpTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.danielfrak.code.keycloak.providers.rest.remote; | ||
|
||
import nl.jqno.equalsverifier.EqualsVerifier; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class LegacyTotpTest { | ||
|
||
@Test | ||
void shouldGetAndSetName() { | ||
var totp = new LegacyTotp(); | ||
var expectedValue = "value1"; | ||
totp.setName(expectedValue); | ||
assertEquals(expectedValue, totp.getName()); | ||
} | ||
|
||
@Test | ||
void shouldGetAndSetSecret() { | ||
var totp = new LegacyTotp(); | ||
var expectedValue = "value1"; | ||
totp.setSecret(expectedValue); | ||
assertEquals(expectedValue, totp.getSecret()); | ||
} | ||
|
||
@Test | ||
void shouldGetAndSetDigits() { | ||
var totp = new LegacyTotp(); | ||
var expectedValue = 6; | ||
totp.setDigits(expectedValue); | ||
assertEquals(expectedValue, totp.getDigits()); | ||
} | ||
|
||
@Test | ||
void shouldGetAndSetPeriod() { | ||
var totp = new LegacyTotp(); | ||
var expectedValue = 30; | ||
totp.setPeriod(expectedValue); | ||
assertEquals(expectedValue, totp.getPeriod()); | ||
} | ||
|
||
@Test | ||
void shouldGetAndSetAlgorithm() { | ||
var totp = new LegacyTotp(); | ||
var expectedValue = "value1"; | ||
totp.setAlgorithm(expectedValue); | ||
assertEquals(expectedValue, totp.getAlgorithm()); | ||
} | ||
|
||
@Test | ||
void shouldGetAndSetEncpding() { | ||
var totp = new LegacyTotp(); | ||
var expectedValue = "value1"; | ||
totp.setEncoding(expectedValue); | ||
assertEquals(expectedValue, totp.getEncoding()); | ||
} | ||
|
||
@Test | ||
void testEquals() { | ||
EqualsVerifier.simple().forClass(LegacyTotp.class) | ||
.verify(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/test/java/com/danielfrak/code/keycloak/providers/rest/remote/TestCredentialManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.danielfrak.code.keycloak.providers.rest.remote; | ||
|
||
import org.keycloak.credential.CredentialInput; | ||
import org.keycloak.credential.CredentialModel; | ||
import org.keycloak.models.SubjectCredentialManager; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
public class TestCredentialManager implements SubjectCredentialManager { | ||
|
||
private final Set<CredentialModel> storedCredentials = new HashSet<>(); | ||
|
||
@Override | ||
public boolean isValid(List<CredentialInput> inputs) { | ||
throw new RuntimeException("Not implemented"); | ||
} | ||
|
||
@Override | ||
public boolean updateCredential(CredentialInput input) { | ||
throw new RuntimeException("Not implemented"); | ||
} | ||
|
||
@Override | ||
public void updateStoredCredential(CredentialModel cred) { | ||
throw new RuntimeException("Not implemented"); | ||
} | ||
|
||
@Override | ||
public CredentialModel createStoredCredential(CredentialModel cred) { | ||
this.storedCredentials.add(cred); | ||
return cred; | ||
} | ||
|
||
@Override | ||
public boolean removeStoredCredentialById(String id) { | ||
throw new RuntimeException("Not implemented"); | ||
} | ||
|
||
@Override | ||
public CredentialModel getStoredCredentialById(String id) { | ||
throw new RuntimeException("Not implemented"); | ||
} | ||
|
||
@Override | ||
public Stream<CredentialModel> getStoredCredentialsStream() { | ||
throw new RuntimeException("Not implemented"); | ||
} | ||
|
||
@Override | ||
public Stream<CredentialModel> getStoredCredentialsByTypeStream(String type) { | ||
return this.storedCredentials.stream().filter(credentialModel -> Objects.equals(credentialModel.getType(), type)); | ||
} | ||
|
||
@Override | ||
public CredentialModel getStoredCredentialByNameAndType(String name, String type) { | ||
throw new RuntimeException("Not implemented"); | ||
} | ||
|
||
@Override | ||
public boolean moveStoredCredentialTo(String id, String newPreviousCredentialId) { | ||
throw new RuntimeException("Not implemented"); | ||
} | ||
|
||
@Override | ||
public void updateCredentialLabel(String credentialId, String credentialLabel) { | ||
throw new RuntimeException("Not implemented"); | ||
} | ||
|
||
@Override | ||
public void disableCredentialType(String credentialType) { | ||
throw new RuntimeException("Not implemented"); | ||
} | ||
|
||
@Override | ||
public Stream<String> getDisableableCredentialTypesStream() { | ||
throw new RuntimeException("Not implemented"); | ||
} | ||
|
||
@Override | ||
public boolean isConfiguredFor(String type) { | ||
throw new RuntimeException("Not implemented"); | ||
} | ||
|
||
@Override | ||
public boolean isConfiguredLocally(String type) { | ||
throw new RuntimeException("Not implemented"); | ||
} | ||
|
||
@Override | ||
public Stream<String> getConfiguredUserStorageCredentialTypesStream() { | ||
throw new RuntimeException("Not implemented"); | ||
} | ||
|
||
@Override | ||
public CredentialModel createCredentialThroughProvider(CredentialModel model) { | ||
throw new RuntimeException("Not implemented"); | ||
} | ||
} |
Oops, something went wrong.