diff --git a/src/main/java/info/bukova/isspst/dao/jpa/BaseDaoJPA.java b/src/main/java/info/bukova/isspst/dao/jpa/BaseDaoJPA.java index 8352f0f0..6a3ef5ba 100644 --- a/src/main/java/info/bukova/isspst/dao/jpa/BaseDaoJPA.java +++ b/src/main/java/info/bukova/isspst/dao/jpa/BaseDaoJPA.java @@ -33,7 +33,6 @@ public abstract class BaseDaoJPA implements BaseDao { @SuppressWarnings("unchecked") @Override public T getById(int id) { - sessionFactory.getCurrentSession().enableFetchProfile("fetch-all"); Query q = sessionFactory.getCurrentSession().createQuery("from " + getEntityName() + " e where ID = :id"); q.setInteger("id", id); return (T) q.uniqueResult(); diff --git a/src/main/java/info/bukova/isspst/ui/NavigationVM.java b/src/main/java/info/bukova/isspst/ui/NavigationVM.java new file mode 100644 index 00000000..3a4d927e --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/NavigationVM.java @@ -0,0 +1,41 @@ +package info.bukova.isspst.ui; + +import org.zkoss.bind.annotation.Init; +import org.zkoss.zk.ui.Executions; + +public class NavigationVM { + + private String contextPath; + private String moduleUrl; + + @Init + public void init() { + contextPath = Executions.getCurrent().getContextPath(); + moduleUrl = Executions.getCurrent().getDesktop().getRequestPath(); + } + + public String getContextPath() { + return contextPath; + } + + public String getModuleUrl() { + return moduleUrl; + } + + public boolean isOrders() { + return moduleUrl.contains("orders"); + } + + public boolean isSettings() { + return moduleUrl.contains("settings"); + } + + public boolean isAdmin() { + return moduleUrl.contains("admin"); + } + + public boolean isUser() { + return moduleUrl.contains("passwd"); + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/SecurityHelper.java b/src/main/java/info/bukova/isspst/ui/SecurityHelper.java new file mode 100644 index 00000000..731cb10a --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/SecurityHelper.java @@ -0,0 +1,45 @@ +package info.bukova.isspst.ui; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.context.SecurityContextHolder; + +public class SecurityHelper { + + public static boolean isAllGranted(String authorities) { + if (null == authorities || "".equals(authorities)) { + return false; + } + final Collection granted = getPrincipalAuthorities(); + boolean isAllGranted = granted.containsAll(parseAuthorities(authorities)); + return isAllGranted; + } + + private static Collection parseAuthorities(String authorities) { + String[] auth = authorities.split(","); + return Arrays.asList(auth); + } + + private static Collection getPrincipalAuthorities() { + Authentication currentUser = SecurityContextHolder.getContext().getAuthentication(); + if (null == currentUser) { + return Collections.emptyList(); + } + if ((null == currentUser.getAuthorities()) || (currentUser.getAuthorities().isEmpty())) { + return Collections.emptyList(); + } + + Collection granted = new ArrayList(); + for (GrantedAuthority a : currentUser.getAuthorities()) { + granted.add(a.getAuthority()); + } + + return granted; + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/TestVM.java b/src/main/java/info/bukova/isspst/ui/TestVM.java deleted file mode 100644 index b516c080..00000000 --- a/src/main/java/info/bukova/isspst/ui/TestVM.java +++ /dev/null @@ -1,18 +0,0 @@ -package info.bukova.isspst.ui; - -import org.zkoss.bind.annotation.Command; -import org.zkoss.zk.ui.select.annotation.WireVariable; - -import info.bukova.isspst.services.UserService; - -public class TestVM { - - @WireVariable - private UserService userService; - - @Command - public void test() { - userService.test(); - } - -} diff --git a/src/main/webapp/WEB-INF/security.tld b/src/main/webapp/WEB-INF/security.tld new file mode 100644 index 00000000..2ac85b0e --- /dev/null +++ b/src/main/webapp/WEB-INF/security.tld @@ -0,0 +1,16 @@ + + http://www.zkoss.org/demo/integration/security + + Methods and actions for ZK + Spring Security + + + + isAllGranted + info.bukova.isspst.ui.SecurityHelper + boolean isAllGranted(java.lang.String authorities) + + + Return true if the authenticated principal is granted authorities of ALL the specified roles. + + + \ No newline at end of file diff --git a/src/main/webapp/admin/test.zul b/src/main/webapp/admin/test.zul deleted file mode 100644 index 3c408ca0..00000000 --- a/src/main/webapp/admin/test.zul +++ /dev/null @@ -1,10 +0,0 @@ - - - - -