Portálová navigace v aplikaci.
This commit is contained in:
@@ -33,7 +33,6 @@ public abstract class BaseDaoJPA<T> implements BaseDao<T> {
|
||||
@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();
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String> granted = getPrincipalAuthorities();
|
||||
boolean isAllGranted = granted.containsAll(parseAuthorities(authorities));
|
||||
return isAllGranted;
|
||||
}
|
||||
|
||||
private static Collection<String> parseAuthorities(String authorities) {
|
||||
String[] auth = authorities.split(",");
|
||||
return Arrays.asList(auth);
|
||||
}
|
||||
|
||||
private static Collection<String> getPrincipalAuthorities() {
|
||||
Authentication currentUser = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (null == currentUser) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if ((null == currentUser.getAuthorities()) || (currentUser.getAuthorities().isEmpty())) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Collection<String> granted = new ArrayList<String>();
|
||||
for (GrantedAuthority a : currentUser.getAuthorities()) {
|
||||
granted.add(a.getAuthority());
|
||||
}
|
||||
|
||||
return granted;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user