Zapomenuté soubory
parent
c5c8aacd31
commit
33309a109b
@ -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};
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<User> {
|
||||||
|
|
||||||
|
@Init(superclass = true)
|
||||||
|
public void init() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<User> {
|
||||||
|
|
||||||
|
@WireVariable
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@Init
|
||||||
|
public void init() {
|
||||||
|
service = userService;
|
||||||
|
dataClass = User.class;
|
||||||
|
formZul = "userForm.zul";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
<?page title="Uživatel" contentType="text/html;charset=UTF-8"?>
|
||||||
|
<zk>
|
||||||
|
<window title="Uživatel" border="normal">
|
||||||
|
|
||||||
|
</window>
|
||||||
|
</zk>
|
@ -0,0 +1,29 @@
|
|||||||
|
<?page title="Uživatelé" contentType="text/html;charset=UTF-8"?>
|
||||||
|
<zk>
|
||||||
|
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
|
||||||
|
<window title="Uživatelé" border="normal" apply="org.zkoss.bind.BindComposer"
|
||||||
|
viewModel="@id('vm') @init('info.bukova.isspst.ui.UsersList')">
|
||||||
|
|
||||||
|
<toolbar>
|
||||||
|
<toolbarbutton image="/img/add.png" tooltiptext="${labels.New}" id="btnNew" onClick="@command('addNew')" disabled="@load(vm.filter)" />
|
||||||
|
<toolbarbutton image="/img/edit.png" tooltiptext="${labels.Edit}" id="btnEdit" onClick="@command('edit')" disabled="@load(empty vm.dataBean ? 'true' : 'false')"/>
|
||||||
|
<toolbarbutton image="/img/delete.png" tooltiptext="${labels.Delete}" id="btnDelete" onClick="@command('delObject')" disabled="@load(empty vm.dataBean ? 'true' : 'false')"/>
|
||||||
|
<toolbarbutton image="/img/funnel.png" tooltiptext="${labels.Filter}" id="btnFilter" onClick="@command('filter')" />
|
||||||
|
</toolbar>
|
||||||
|
|
||||||
|
|
||||||
|
<listbox model="@load(vm.dataList)" selectedItem="@bind(vm.dataBean)">
|
||||||
|
<listhead>
|
||||||
|
<listheader label="Login"/>
|
||||||
|
<listheader label="Celé jméno"/>
|
||||||
|
</listhead>
|
||||||
|
<template name="model">
|
||||||
|
<listitem>
|
||||||
|
<listcell label="@load(each.username)"/>
|
||||||
|
<listcell label="@load(each.fullName)"/>
|
||||||
|
</listitem>
|
||||||
|
</template>
|
||||||
|
</listbox>
|
||||||
|
|
||||||
|
</window>
|
||||||
|
</zk>
|
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
Binary file not shown.
After Width: | Height: | Size: 543 B |
Loading…
Reference in New Issue