-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add new password policy to validate passwords on login #1
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,26 @@ | ||||||
package org.keycloak.policy; | ||||||
|
||||||
import org.keycloak.models.RealmModel; | ||||||
import org.keycloak.models.UserModel; | ||||||
|
||||||
public class ValidateOnLoginPasswordPolicyProvider implements PasswordPolicyProvider { | ||||||
@Override | ||||||
public PolicyError validate(RealmModel realm, UserModel user, String password) { | ||||||
return null; | ||||||
} | ||||||
|
||||||
@Override | ||||||
public PolicyError validate(String user, String password) { | ||||||
return null; | ||||||
} | ||||||
|
||||||
@Override | ||||||
public Object parseConfig(String value) { | ||||||
return null; | ||||||
} | ||||||
|
||||||
@Override | ||||||
public void close() { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I personally like this style more, but I am not sure what the Keycloak style guidelines say. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked at similar implementations and mainly found the current variant. Sometimes, the empty line is removed, like this: public void close() {
} |
||||||
|
||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.keycloak.policy; | ||
|
||
import org.keycloak.Config; | ||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.models.KeycloakSessionFactory; | ||
import org.keycloak.models.PasswordPolicy; | ||
|
||
public class ValidateOnLoginPasswordPolicyProviderFactory implements PasswordPolicyProviderFactory { | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Validate Policy on Login"; | ||
} | ||
|
||
@Override | ||
public String getConfigType() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getDefaultConfigValue() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isMultiplSupported() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public PasswordPolicyProvider create(KeycloakSession session) { | ||
return new ValidateOnLoginPasswordPolicyProvider(); | ||
} | ||
|
||
@Override | ||
public void init(Config.Scope config) { | ||
|
||
} | ||
|
||
@Override | ||
public void postInit(KeycloakSessionFactory factory) { | ||
|
||
} | ||
|
||
@Override | ||
public void close() { | ||
|
||
} | ||
|
||
@Override | ||
public String getId() { | ||
return PasswordPolicy.VALIDATE_ON_LOGIN_ID; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<#import "template.ftl" as layout> | ||
<@layout.registrationLayout displayMessage=false; section> | ||
<#if section = "header"> | ||
${msg("passwordPolicyErrorTitle")} | ||
<#elseif section = "form"> | ||
<div id="kc-terms-text"> | ||
${kcSanitize(msg("passwordPolicyErrorMessage"))?no_esc} | ||
</div> | ||
<form class="form-actions" action="${url.loginAction}" method="POST"> | ||
<#if !userReadOnly> | ||
<input class="${properties.kcButtonClass!} ${properties.kcButtonPrimaryClass!} ${properties.kcButtonLargeClass!}" name="continueToUpdate" id="kc-accept" type="submit" value="${msg("doContinue")}"/> | ||
</#if> | ||
<input class="${properties.kcButtonClass!} ${properties.kcButtonDefaultClass!} ${properties.kcButtonLargeClass!}" name="cancelUpdate" id="kc-decline" type="submit" value="${msg("doCancel")}"/> | ||
</form> | ||
<div class="clearfix"></div> | ||
</#if> | ||
</@layout.registrationLayout> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would propose to enforce the policy and deny authentication in read only mode. If admins don't want that behavior they easily can disable the password policy but they cannot enforce them otherwise. However, there should be a error message to the user imho