From 26e733a537a8cf6bbee34c1df5baf26a213e3dc3 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Wed, 26 Nov 2014 15:24:42 +0100 Subject: [PATCH] =?UTF-8?q?Pokud=20je=20nastaveno=20p=C5=99ihla=C5=A1ov?= =?UTF-8?q?=C3=A1n=C3=AD=20proti=20AD=20nebo=20LDAP=20serveru,=20tak=20zmi?= =?UTF-8?q?z=C3=AD=20nab=C3=ADdka=20"Zm=C4=9Bnit=20heslo".=20closes=20#174?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../info/bukova/isspst/security/AuthMethod.java | 9 +++++++++ .../info/bukova/isspst/security/AuthPopulator.java | 1 + .../isspst/services/users/AdUserCtxMapper.java | 2 ++ .../bukova/isspst/services/users/UserService.java | 4 ++++ .../isspst/services/users/UserServiceImpl.java | 14 ++++++++++++++ src/main/java/info/bukova/isspst/ui/MainMenu.java | 10 ++++++++++ src/main/webapp/app/mainMenu.zul | 3 ++- 7 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/main/java/info/bukova/isspst/security/AuthMethod.java diff --git a/src/main/java/info/bukova/isspst/security/AuthMethod.java b/src/main/java/info/bukova/isspst/security/AuthMethod.java new file mode 100644 index 00000000..7714c8e2 --- /dev/null +++ b/src/main/java/info/bukova/isspst/security/AuthMethod.java @@ -0,0 +1,9 @@ +package info.bukova.isspst.security; + +public enum AuthMethod { + + DATABASE, + LDAP, + AD + +} diff --git a/src/main/java/info/bukova/isspst/security/AuthPopulator.java b/src/main/java/info/bukova/isspst/security/AuthPopulator.java index 2191077f..21055a64 100644 --- a/src/main/java/info/bukova/isspst/security/AuthPopulator.java +++ b/src/main/java/info/bukova/isspst/security/AuthPopulator.java @@ -23,6 +23,7 @@ public class AuthPopulator implements LdapAuthoritiesPopulator { public AuthPopulator(UserService userService, RoleService roleService) { this.userService = userService; this.roleService = roleService; + userService.setAuthMethod(AuthMethod.LDAP); } @Override diff --git a/src/main/java/info/bukova/isspst/services/users/AdUserCtxMapper.java b/src/main/java/info/bukova/isspst/services/users/AdUserCtxMapper.java index 96cd9b1f..fc95a943 100644 --- a/src/main/java/info/bukova/isspst/services/users/AdUserCtxMapper.java +++ b/src/main/java/info/bukova/isspst/services/users/AdUserCtxMapper.java @@ -2,6 +2,7 @@ package info.bukova.isspst.services.users; import info.bukova.isspst.Constants; import info.bukova.isspst.data.User; +import info.bukova.isspst.security.AuthMethod; import java.util.Collection; @@ -33,6 +34,7 @@ public class AdUserCtxMapper implements UserDetailsContextMapper { public AdUserCtxMapper(UserService userService, RoleService roleService) { this.userService = userService; this.roleService = roleService; + userService.setAuthMethod(AuthMethod.AD); } @Override diff --git a/src/main/java/info/bukova/isspst/services/users/UserService.java b/src/main/java/info/bukova/isspst/services/users/UserService.java index ccb3ec54..d5f729ce 100644 --- a/src/main/java/info/bukova/isspst/services/users/UserService.java +++ b/src/main/java/info/bukova/isspst/services/users/UserService.java @@ -5,6 +5,7 @@ import java.util.List; import info.bukova.isspst.data.Role; import info.bukova.isspst.data.User; import info.bukova.isspst.data.UserSettingsData; +import info.bukova.isspst.security.AuthMethod; import info.bukova.isspst.services.Service; import org.springframework.security.core.userdetails.UserDetailsService; @@ -24,4 +25,7 @@ public interface UserService extends UserDetailsService, Service { public UserSettingsData getUserSettings(User user); public UserSettingsData getUserSettings(); public void setUserSettings(UserSettingsData settings); + public void setAuthMethod(AuthMethod method); + public AuthMethod getAuthMethod(); + } diff --git a/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java b/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java index 925fe3cb..470abf14 100644 --- a/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java @@ -4,10 +4,12 @@ import info.bukova.isspst.Constants; import info.bukova.isspst.data.Role; import info.bukova.isspst.data.User; import info.bukova.isspst.data.UserSettingsData; +import info.bukova.isspst.security.AuthMethod; import info.bukova.isspst.services.AbstractService; import info.bukova.isspst.services.StringXmlMarshaller; //import info.bukova.isspst.services.LazyLoader; + import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -34,9 +36,11 @@ public class UserServiceImpl extends AbstractService implements UserServic @Autowired private RoleService roleService; private StringXmlMarshaller marshaller; + private AuthMethod authMethod; public UserServiceImpl(Marshaller marshaller, Unmarshaller unmarshaller) { this.marshaller = new StringXmlMarshaller(marshaller, unmarshaller, UserSettingsData.class); + authMethod = AuthMethod.DATABASE; } public void setEncoder(PasswordEncoder encoder) { @@ -202,4 +206,14 @@ public class UserServiceImpl extends AbstractService implements UserServic return Constants.PERM_EDIT_OWN; } + @Override + public void setAuthMethod(AuthMethod method) { + this.authMethod = method; + } + + @Override + public AuthMethod getAuthMethod() { + return authMethod; + } + } diff --git a/src/main/java/info/bukova/isspst/ui/MainMenu.java b/src/main/java/info/bukova/isspst/ui/MainMenu.java index e5454e35..df631dce 100644 --- a/src/main/java/info/bukova/isspst/ui/MainMenu.java +++ b/src/main/java/info/bukova/isspst/ui/MainMenu.java @@ -1,8 +1,12 @@ package info.bukova.isspst.ui; +import info.bukova.isspst.security.AuthMethod; +import info.bukova.isspst.services.users.UserService; + import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.Init; import org.zkoss.zk.ui.Executions; +import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zul.Window; public class MainMenu @@ -10,6 +14,8 @@ public class MainMenu private String contextPath; private String moduleUrl; + @WireVariable + private UserService userService; @Init public void init() @@ -55,4 +61,8 @@ public class MainMenu Window window = (Window) Executions.createComponents("/settings/userSettings.zul", null, null); window.doModal(); } + + public boolean isCanChangePassword() { + return userService.getAuthMethod() == AuthMethod.DATABASE; + } } diff --git a/src/main/webapp/app/mainMenu.zul b/src/main/webapp/app/mainMenu.zul index d78fb2fe..91bfcf0d 100644 --- a/src/main/webapp/app/mainMenu.zul +++ b/src/main/webapp/app/mainMenu.zul @@ -125,7 +125,8 @@ + onClick="@command('passwd')" + visible="@load(vm.canChangePassword)" />