Skip to content
Snippets Groups Projects
Commit 54375654 authored by srosse's avatar srosse
Browse files

OO-3554: reflect the list of user names in the WebDAV's change password

panel based on OpenOLAT configuration and the list of authentications
objects
parent 08d9f1a4
No related branches found
No related tags found
No related merge requests found
......@@ -185,12 +185,12 @@ public class WebDAVAuthManager implements AuthenticationSPI {
private void updateWebdavPassword(Identity doer, Identity identity, String password, List<Authentication> authentications) {
updateWebDAVPassword(doer, identity, identity.getName(), password, PROVIDER_WEBDAV, authentications);
if(StringHelper.containsNonWhitespace(identity.getUser().getEmail())) {
if(userModule.isEmailUnique() && StringHelper.containsNonWhitespace(identity.getUser().getEmail())) {
updateWebDAVPassword(doer, identity, identity.getUser().getEmail(), password, PROVIDER_WEBDAV_EMAIL, authentications);
} else {
removePassword(PROVIDER_WEBDAV_EMAIL, authentications);
}
if(StringHelper.containsNonWhitespace(identity.getUser().getInstitutionalEmail())) {
if(userModule.isEmailUnique() && StringHelper.containsNonWhitespace(identity.getUser().getInstitutionalEmail())) {
updateWebDAVPassword(doer, identity, identity.getUser().getInstitutionalEmail(), password, PROVIDER_WEBDAV_INSTITUTIONAL_EMAIL, authentications);
} else {
removePassword(PROVIDER_WEBDAV_INSTITUTIONAL_EMAIL, authentications);
......@@ -247,18 +247,16 @@ public class WebDAVAuthManager implements AuthenticationSPI {
private void updateDigestPasswords(Identity doer, Identity identity, String newPwd,
List<Authentication> authentications) {
updateDigestPassword(doer, identity, identity.getName(), newPwd, PROVIDER_HA1, authentications);
if (userModule.isEmailUnique()) {
if(StringHelper.containsNonWhitespace(identity.getUser().getEmail())) {
updateDigestPassword(doer, identity, identity.getUser().getEmail(), newPwd, PROVIDER_HA1_EMAIL, authentications);
} else {
removePassword(PROVIDER_HA1_EMAIL, authentications);
}
if(StringHelper.containsNonWhitespace(identity.getUser().getInstitutionalEmail())) {
updateDigestPassword(doer, identity, identity.getUser().getInstitutionalEmail(), newPwd, PROVIDER_HA1_INSTITUTIONAL_EMAIL, authentications);
} else {
removePassword(PROVIDER_HA1_INSTITUTIONAL_EMAIL, authentications);
}
if(userModule.isEmailUnique() && StringHelper.containsNonWhitespace(identity.getUser().getEmail())) {
updateDigestPassword(doer, identity, identity.getUser().getEmail(), newPwd, PROVIDER_HA1_EMAIL, authentications);
} else {
removePassword(PROVIDER_HA1_EMAIL, authentications);
}
if(userModule.isEmailUnique() && StringHelper.containsNonWhitespace(identity.getUser().getInstitutionalEmail())) {
updateDigestPassword(doer, identity, identity.getUser().getInstitutionalEmail(), newPwd, PROVIDER_HA1_INSTITUTIONAL_EMAIL, authentications);
} else {
removePassword(PROVIDER_HA1_INSTITUTIONAL_EMAIL, authentications);
}
for(Authentication authentication:authentications) {
......
......@@ -62,10 +62,13 @@ public class WebDAVPasswordController extends FormBasicController {
private FormLink newButton;
private TextElement passwordEl;
private TextElement confirmPasswordEl;
private StaticTextElement usernamesStaticEl;
private StaticTextElement passwordStaticEl;
private FormLayoutContainer accessDataFlc;
private FormLayoutContainer buttonGroupLayout;
@Autowired
private UserModule userModule;
@Autowired
private BaseSecurity securityManager;
@Autowired
......@@ -87,16 +90,6 @@ public class WebDAVPasswordController extends FormBasicController {
accessDataFlc = FormLayoutContainer.createDefaultFormLayout("flc_access_data", getTranslator());
layoutContainer.add(accessDataFlc);
StringBuilder sb = new StringBuilder();
sb.append(getIdentity().getName());
if(StringHelper.containsNonWhitespace(getIdentity().getUser().getEmail())) {
sb.append(", ").append(getIdentity().getUser().getEmail());
}
if(StringHelper.containsNonWhitespace(getIdentity().getUser().getInstitutionalEmail())) {
sb.append(", ").append(getIdentity().getUser().getInstitutionalEmail());
}
uifactory.addStaticTextElement("pwdav.username", "pwdav.username", sb.toString(), accessDataFlc);
boolean hasOlatToken = false;
boolean hasWebDAVToken = false;
......@@ -104,11 +97,19 @@ public class WebDAVPasswordController extends FormBasicController {
for(Authentication auth : authentications) {
if(BaseSecurityModule.getDefaultAuthProviderIdentifier().equals(auth.getProvider())) {
hasOlatToken = true;
} else if(WebDAVAuthManager.PROVIDER_WEBDAV.equals(auth.getProvider())) {
} else if(WebDAVAuthManager.PROVIDER_WEBDAV.equals(auth.getProvider())
|| WebDAVAuthManager.PROVIDER_WEBDAV_EMAIL.equals(auth.getProvider())
|| WebDAVAuthManager.PROVIDER_WEBDAV_INSTITUTIONAL_EMAIL.equals(auth.getProvider())
|| WebDAVAuthManager.PROVIDER_HA1.equals(auth.getProvider())
|| WebDAVAuthManager.PROVIDER_HA1_EMAIL.equals(auth.getProvider())
|| WebDAVAuthManager.PROVIDER_HA1_INSTITUTIONAL_EMAIL.equals(auth.getProvider())) {
hasWebDAVToken = true;
}
}
String usernames = getUsernames(authentications);
usernamesStaticEl = uifactory.addStaticTextElement("pwdav.username", "pwdav.username", usernames, accessDataFlc);
if(hasOlatToken) {
String passwordPlaceholder = getTranslator().translate("pwdav.password.placeholder");
uifactory.addStaticTextElement("pwdav.password", "pwdav.password", passwordPlaceholder, accessDataFlc);
......@@ -143,6 +144,35 @@ public class WebDAVPasswordController extends FormBasicController {
}
}
private String getUsernames(List<Authentication> authentications) {
StringBuilder sb = new StringBuilder();
sb.append(getIdentity().getName());
if(userModule.isEmailUnique()) {
if(StringHelper.containsNonWhitespace(getIdentity().getUser().getEmail())) {
sb.append(", ").append(getIdentity().getUser().getEmail());
}
if(StringHelper.containsNonWhitespace(getIdentity().getUser().getInstitutionalEmail())) {
sb.append(", ").append(getIdentity().getUser().getInstitutionalEmail());
}
}
for(Authentication auth : authentications) {
if(WebDAVAuthManager.PROVIDER_WEBDAV.equals(auth.getProvider())
|| WebDAVAuthManager.PROVIDER_WEBDAV_EMAIL.equals(auth.getProvider())
|| WebDAVAuthManager.PROVIDER_WEBDAV_INSTITUTIONAL_EMAIL.equals(auth.getProvider())
|| WebDAVAuthManager.PROVIDER_HA1.equals(auth.getProvider())
|| WebDAVAuthManager.PROVIDER_HA1_EMAIL.equals(auth.getProvider())
|| WebDAVAuthManager.PROVIDER_HA1_INSTITUTIONAL_EMAIL.equals(auth.getProvider())) {
String authUsername = auth.getAuthusername();
if(sb.indexOf(authUsername) < 0) {
sb.append(", ").append(authUsername);
}
}
}
return sb.toString();
}
@Override
protected void doDispose() {
//auto-disposed
......@@ -215,6 +245,10 @@ public class WebDAVPasswordController extends FormBasicController {
String buttonPlaceholderKey = auth == null ? "pwdav.password.new" : "pwdav.password.change";
newButton.setI18nKey(buttonPlaceholderKey);
List<Authentication> authentications = securityManager.getAuthentications(ureq.getIdentity());
String usernames = getUsernames(authentications);
usernamesStaticEl.setValue(usernames);
flc.setDirty(true);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment