Agenda na správu uživatelů
parent
202825322a
commit
6462fb3806
@ -1,10 +1,29 @@
|
||||
package info.bukova.isspst;
|
||||
|
||||
import info.bukova.isspst.data.Role;
|
||||
|
||||
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};
|
||||
public final static String ROLE_DIRECTOR = "ROLE_DIRECTOR";
|
||||
public final static String ROLE_MANAGER = "ROLE_MANAGER";
|
||||
public final static String ROLE_PRINCIPAL = "ROLE_PRINCIPAL";
|
||||
public final static String ROLE_ACCOUNTANT = "ROLE_ACCOUNTANT";
|
||||
public final static String ROLE_SUPPLIER = "ROLE_SUPPLIER";
|
||||
public final static String ROLE_TECHNICIAN = "ROLE_TECHNICIAN";
|
||||
public final static String ROLE_LEADER = "ROLE_LEADER";
|
||||
public final static Role ROLES[] = {
|
||||
new Role(ROLE_ADMIN, "Administrátor"),
|
||||
new Role(ROLE_DIRECTOR, "Ředitel"),
|
||||
new Role(ROLE_MANAGER, "Správce"),
|
||||
new Role(ROLE_PRINCIPAL, "Příkazce"),
|
||||
new Role(ROLE_ACCOUNTANT, "Účetní"),
|
||||
new Role(ROLE_SUPPLIER, "Zásobovač"),
|
||||
new Role(ROLE_TECHNICIAN, "Technik"),
|
||||
new Role(ROLE_LEADER, "Vedoucí"),
|
||||
new Role(ROLE_USER, "Uživatel")
|
||||
};
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package info.bukova.isspst;
|
||||
|
||||
public class StringUtils {
|
||||
|
||||
public static String nullStr(String str) {
|
||||
return str == null ? "" : str;
|
||||
}
|
||||
|
||||
public static String not0ToStr(long i) {
|
||||
return i == 0 ? "" : String.valueOf(i);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package info.bukova.isspst.filters;
|
||||
|
||||
import info.bukova.isspst.data.User;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Factory;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
|
||||
import static info.bukova.isspst.StringUtils.nullStr;
|
||||
|
||||
public class UserFilter implements Filter<User> {
|
||||
|
||||
private User condUser;
|
||||
|
||||
public UserFilter(User condition) {
|
||||
this.condUser = condition;
|
||||
}
|
||||
|
||||
private static class UserMatcher extends TypeSafeMatcher<User> {
|
||||
|
||||
private User condUser;
|
||||
|
||||
public UserMatcher(User condition) {
|
||||
this.condUser = condition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("user matcher");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesSafely(User item) {
|
||||
return nullStr(item.getUsername()).toLowerCase().contains(nullStr(condUser.getUsername()).toLowerCase())
|
||||
&& nullStr(item.getFirstName()).toLowerCase().contains(nullStr(condUser.getFirstName()).toLowerCase())
|
||||
&& nullStr(item.getLastName()).toLowerCase().contains(nullStr(condUser.getLastName()).toLowerCase())
|
||||
&& nullStr(item.getPersonalNumber()).toLowerCase().contains(nullStr(condUser.getPersonalNumber()).toLowerCase());
|
||||
}
|
||||
|
||||
@Factory
|
||||
public UserMatcher matchUser(User cond) {
|
||||
return new UserMatcher(cond);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeSafeMatcher<User> matcher() {
|
||||
return new UserMatcher(condUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String queryString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package info.bukova.isspst.services;
|
||||
|
||||
import info.bukova.isspst.data.User;
|
||||
|
||||
public interface UserService extends Service<User> {
|
||||
|
||||
public void setPassword(User user, String password);
|
||||
public boolean hasRole(User user, String authority);
|
||||
public void test();
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package info.bukova.isspst.services;
|
||||
package info.bukova.isspst.services.users;
|
||||
|
||||
import info.bukova.isspst.data.Role;
|
||||
import info.bukova.isspst.services.Service;
|
||||
|
||||
public interface RoleService extends Service<Role> {
|
||||
|
@ -1,8 +1,9 @@
|
||||
package info.bukova.isspst.services;
|
||||
package info.bukova.isspst.services.users;
|
||||
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import info.bukova.isspst.data.Role;
|
||||
import info.bukova.isspst.services.AbstractService;
|
||||
|
||||
public class RoleServiceImpl extends AbstractService<Role> implements RoleService {
|
||||
|
@ -0,0 +1,14 @@
|
||||
package info.bukova.isspst.services.users;
|
||||
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
|
||||
import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.services.Service;
|
||||
|
||||
public interface UserService extends UserDetailsService, Service<User> {
|
||||
|
||||
public void setPassword(User user, String password);
|
||||
public boolean hasRole(User user, String authority);
|
||||
public void saveWithPwd(User user, String password);
|
||||
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
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,43 @@
|
||||
package info.bukova.isspst.ui.users;
|
||||
|
||||
import info.bukova.isspst.data.Role;
|
||||
import info.bukova.isspst.data.User;
|
||||
|
||||
public class RoleCheck {
|
||||
|
||||
private Role role;
|
||||
private User user;
|
||||
private boolean checked;
|
||||
|
||||
public RoleCheck(User user, Role role) {
|
||||
this.user = user;
|
||||
this.role = role;
|
||||
if (user.getAuthorities().contains(role)) {
|
||||
checked = true;
|
||||
} else {
|
||||
checked = false;
|
||||
}
|
||||
}
|
||||
|
||||
public Role getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(Role role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public boolean isChecked() {
|
||||
return checked;
|
||||
}
|
||||
|
||||
public void setChecked(boolean checked) {
|
||||
this.checked = checked;
|
||||
if (checked && !user.getAuthorities().contains(role)) {
|
||||
user.addAuthority(role);
|
||||
} else {
|
||||
user.getAuthorities().remove(role);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package info.bukova.isspst.ui.users;
|
||||
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.zkoss.bind.annotation.Command;
|
||||
import org.zkoss.bind.annotation.Init;
|
||||
import org.zkoss.bind.annotation.NotifyChange;
|
||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||
|
||||
import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.services.users.RoleService;
|
||||
import info.bukova.isspst.services.users.UserService;
|
||||
import info.bukova.isspst.ui.FormViewModel;
|
||||
|
||||
public class UserForm extends FormViewModel<User> {
|
||||
|
||||
@WireVariable
|
||||
private RoleService roleService;
|
||||
@WireVariable
|
||||
private UserService userService;
|
||||
private String retPasswd = "";
|
||||
private String password = "";
|
||||
private UserRoles userRoles;
|
||||
private boolean loginFree;
|
||||
|
||||
@Init(superclass = true)
|
||||
public void init() {
|
||||
userRoles = new UserRoles(getDataBean(), roleService.getAll());
|
||||
loginFree = true;
|
||||
}
|
||||
|
||||
public UserRoles getUserRoles() {
|
||||
return userRoles;
|
||||
}
|
||||
|
||||
public String getRetPasswd() {
|
||||
return retPasswd;
|
||||
}
|
||||
|
||||
@NotifyChange({"canSave", "pwMatches"})
|
||||
public void setRetPasswd(String retPasswd) {
|
||||
this.retPasswd = retPasswd;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
@NotifyChange({"canSave", "pwMatches"})
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange({"loginFree", "canSave"})
|
||||
public void checkLogin() {
|
||||
try {
|
||||
userService.loadUserByUsername(getDataBean().getUsername());
|
||||
loginFree = false;
|
||||
} catch(UsernameNotFoundException e) {
|
||||
loginFree = true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPwMatches() {
|
||||
return password.equals(retPasswd);
|
||||
}
|
||||
|
||||
public boolean isLoginFree() {
|
||||
return loginFree || isEdit();
|
||||
}
|
||||
|
||||
public boolean isEdit() {
|
||||
return getDataBean().getCreated() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doSave() {
|
||||
if (!password.isEmpty()) {
|
||||
userService.saveWithPwd(getDataBean(), this.password);
|
||||
} else {
|
||||
super.doSave();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCanSave() {
|
||||
return password.equals(retPasswd) && isLoginFree() && getDataBean().getUsername() != null && !getDataBean().getUsername().isEmpty();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package info.bukova.isspst.ui.users;
|
||||
|
||||
import info.bukova.isspst.data.Role;
|
||||
import info.bukova.isspst.data.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class UserRoles {
|
||||
|
||||
private List<RoleCheck> roleChecks;
|
||||
|
||||
public UserRoles(User user, List<Role> roles) {
|
||||
roleChecks = new ArrayList<RoleCheck>();
|
||||
for (Role r : roles) {
|
||||
roleChecks.add(new RoleCheck(user, r));
|
||||
}
|
||||
}
|
||||
|
||||
public List<RoleCheck> getRoleChecks() {
|
||||
return roleChecks;
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,34 @@
|
||||
<?page title="Uživatel" contentType="text/html;charset=UTF-8"?>
|
||||
<zk>
|
||||
<window title="Uživatel" border="normal">
|
||||
|
||||
<window id="editWin" title="Uživatel" border="normal" closable="true" width="450px" apply="org.zkoss.bind.BindComposer"
|
||||
viewModel="@id('vm') @init('info.bukova.isspst.ui.users.UserForm')">
|
||||
<style src="/app/form.css"/>
|
||||
<grid width="440px">
|
||||
<columns>
|
||||
<column hflex="min"></column>
|
||||
<column></column>
|
||||
<column></column>
|
||||
</columns>
|
||||
<rows>
|
||||
<row><label value="Login"/><textbox value="@bind(vm.dataBean.username)" instant="true" disabled="@load(vm.edit)" onChange="@command('checkLogin')"/><label value="Login je obsazený" sclass="error" visible="@load(not vm.loginFree)"/></row>
|
||||
<row><label value="Jméno"/><textbox value="@bind(vm.dataBean.firstName)"/></row>
|
||||
<row><label value="Příjmení"/><textbox value="@bind(vm.dataBean.lastName)"/></row>
|
||||
<row><label value="Osobní číslo"/><textbox value="@bind(vm.dataBean.personalNumber)" width="90px"/></row>
|
||||
<row><label value="E-mail"/><textbox value="@bind(vm.dataBean.email)"/></row>
|
||||
<row><label value=""/><checkbox label="Zasílat upozornění" checked="@bind(vm.dataBean.notify)"/></row>
|
||||
<row><label value="Heslo"/><textbox value="@bind(vm.password)" type="password" instant="true"/></row>
|
||||
<row><label value="Znova heslo"/><textbox value="@bind(vm.retPasswd)" type="password" instant="true"/><label value="Hesla nesouhlasí" sclass="error" visible="@load(not vm.pwMatches)"/></row>
|
||||
<row><label value=""/><checkbox label="Aktivní" checked="@bind(vm.dataBean.enabled)"/></row>
|
||||
</rows>
|
||||
</grid>
|
||||
<groupbox mold="3d">
|
||||
<caption label="Role"/>
|
||||
<vbox children="@load(vm.userRoles.roleChecks)">
|
||||
<template name="children">
|
||||
<checkbox label="@load(each.role.description)" checked="@bind(each.checked)"/>
|
||||
</template>
|
||||
</vbox>
|
||||
</groupbox>
|
||||
<button image="/img/save.png" label="Uložit" onClick="@command('save', window=editWin) @global-command('refresh')" disabled="@load(not vm.canSave)" sclass="nicebutton" /><button image="~./zul/img/misc/drag-disallow.png" label="Zavřít" onClick="editWin.detach()" sclass="nicebutton"/>
|
||||
</window>
|
||||
</zk>
|
Loading…
Reference in New Issue