diff --git a/src/main/java/info/bukova/isspst/Constants.java b/src/main/java/info/bukova/isspst/Constants.java new file mode 100644 index 00000000..2d1b3923 --- /dev/null +++ b/src/main/java/info/bukova/isspst/Constants.java @@ -0,0 +1,10 @@ +package info.bukova.isspst; + +public class Constants { + + public final static String DEF_ADMIN = "admin"; + public final static String DEF_ADMIN_PASSWD = "admin"; + public final static String ROLE_USER = "ROLE_USER"; + public final static String ROLE_ADMIN = "ROLE_ADMIN"; + public final static String ROLES[] = {ROLE_USER, ROLE_ADMIN}; +} diff --git a/src/main/java/info/bukova/isspst/DbInitListener.java b/src/main/java/info/bukova/isspst/DbInitListener.java new file mode 100644 index 00000000..ada4fa8a --- /dev/null +++ b/src/main/java/info/bukova/isspst/DbInitListener.java @@ -0,0 +1,74 @@ +package info.bukova.isspst; + +import info.bukova.isspst.data.Role; +import info.bukova.isspst.data.User; +import info.bukova.isspst.services.RoleService; +import info.bukova.isspst.services.UserService; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +public class DbInitListener implements ServletContextListener { + + private RoleService roleService; + private UserService userService; + + @Override + public void contextDestroyed(ServletContextEvent arg0) { + + } + + @Override + public void contextInitialized(ServletContextEvent evt) { + Logger logger = LoggerFactory.getLogger(DbInitListener.class); + logger.info("Initializing database"); + + WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(evt.getServletContext()); + roleService = ctx.getBean(RoleService.class); + userService = ctx.getBean(UserService.class); + + checkRoles(); + checkUsers(); + } + + private void checkRoles() { + Role r = null; + + for (String auth : Constants.ROLES) + { + r = roleService.getRoleByAuthority(auth); + if (r == null) { + r = new Role(); + r.setAuthority(auth); + r.setDescription("---"); + roleService.add(r); + } + } + } + + private void checkUsers() { + boolean adminExists = false; + + for (User u : userService.getAll()) { + if (userService.hasRole(u, Constants.ROLE_ADMIN)) { + adminExists = true; + break; + } + } + + if (!adminExists) { + User u = new User(); + u.setUsername(Constants.DEF_ADMIN); + u.addAuthority(roleService.getRoleByAuthority(Constants.ROLE_ADMIN)); + u.setEnabled(true); + userService.setPassword(u, Constants.DEF_ADMIN_PASSWD); + userService.add(u); + } + } + +} diff --git a/src/main/java/info/bukova/isspst/LoginFailHandler.java b/src/main/java/info/bukova/isspst/LoginFailHandler.java new file mode 100644 index 00000000..8d2bb71e --- /dev/null +++ b/src/main/java/info/bukova/isspst/LoginFailHandler.java @@ -0,0 +1,25 @@ +package info.bukova.isspst; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.authentication.AuthenticationFailureHandler; + +public class LoginFailHandler implements AuthenticationFailureHandler { + + @Override + public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException ex) + throws IOException, ServletException { + + Logger logger = LoggerFactory.getLogger(LoginFailHandler.class); + logger.info("Login failed with message: " + ex.getMessage()); + + } + +} diff --git a/src/main/java/info/bukova/isspst/data/User.java b/src/main/java/info/bukova/isspst/data/User.java index 9f5f0c4b..5091b7e9 100644 --- a/src/main/java/info/bukova/isspst/data/User.java +++ b/src/main/java/info/bukova/isspst/data/User.java @@ -36,6 +36,7 @@ public class User implements UserDetails, DataModel { private String password; @Column(name="ENABLED") private boolean enabled; + private String fullName; @OneToMany(fetch=FetchType.EAGER) @JoinTable(name="USER_ROLE") @MapKeyColumn(name="ROLE_ID") private List authorities; @@ -137,4 +138,12 @@ public class User implements UserDetails, DataModel { this.valid = valid; } + public String getFullName() { + return fullName; + } + + public void setFullName(String fullName) { + this.fullName = fullName; + } + } diff --git a/src/main/java/info/bukova/isspst/ui/ListViewModel.java b/src/main/java/info/bukova/isspst/ui/ListViewModel.java index 1842cd89..bdc32a95 100644 --- a/src/main/java/info/bukova/isspst/ui/ListViewModel.java +++ b/src/main/java/info/bukova/isspst/ui/ListViewModel.java @@ -43,7 +43,7 @@ public class ListViewModel { public List getDataList() { if (dataList == null) { dataList = new ArrayList(); - loadFromDb(); + loadFromDbSync(); } return dataList; diff --git a/src/main/java/info/bukova/isspst/ui/UserForm.java b/src/main/java/info/bukova/isspst/ui/UserForm.java new file mode 100644 index 00000000..07116ed4 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/UserForm.java @@ -0,0 +1,14 @@ +package info.bukova.isspst.ui; + +import org.zkoss.bind.annotation.Init; + +import info.bukova.isspst.data.User; + +public class UserForm extends FormViewModel { + + @Init(superclass = true) + public void init() { + + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/UsersList.java b/src/main/java/info/bukova/isspst/ui/UsersList.java new file mode 100644 index 00000000..c5ca0c0f --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/UsersList.java @@ -0,0 +1,21 @@ +package info.bukova.isspst.ui; + +import org.zkoss.bind.annotation.Init; +import org.zkoss.zk.ui.select.annotation.WireVariable; + +import info.bukova.isspst.data.User; +import info.bukova.isspst.services.UserService; + +public class UsersList extends ListViewModel { + + @WireVariable + private UserService userService; + + @Init + public void init() { + service = userService; + dataClass = User.class; + formZul = "userForm.zul"; + } + +} diff --git a/src/main/webapp/WEB-INF/spring/root-context.xml b/src/main/webapp/WEB-INF/spring/root-context.xml index ca5f890c..39249fd2 100644 --- a/src/main/webapp/WEB-INF/spring/root-context.xml +++ b/src/main/webapp/WEB-INF/spring/root-context.xml @@ -53,7 +53,7 @@ - + diff --git a/src/main/webapp/admin/userForm.zul b/src/main/webapp/admin/userForm.zul new file mode 100644 index 00000000..635a212d --- /dev/null +++ b/src/main/webapp/admin/userForm.zul @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/webapp/admin/users.zul b/src/main/webapp/admin/users.zul new file mode 100644 index 00000000..b7f4f7e0 --- /dev/null +++ b/src/main/webapp/admin/users.zul @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/img/add.png b/src/main/webapp/img/add.png new file mode 100644 index 00000000..a074acc3 Binary files /dev/null and b/src/main/webapp/img/add.png differ diff --git a/src/main/webapp/img/delete.png b/src/main/webapp/img/delete.png new file mode 100644 index 00000000..b00936b7 Binary files /dev/null and b/src/main/webapp/img/delete.png differ diff --git a/src/main/webapp/img/edit.png b/src/main/webapp/img/edit.png new file mode 100644 index 00000000..3226ef3d Binary files /dev/null and b/src/main/webapp/img/edit.png differ diff --git a/src/main/webapp/img/funnel.png b/src/main/webapp/img/funnel.png new file mode 100644 index 00000000..35f1d259 Binary files /dev/null and b/src/main/webapp/img/funnel.png differ