ulrich
2016-12-24 87e382c61272e351b04715c960d485f863b7e594
Rollen in Arbeit
2 files modified
29 ■■■■ changed files
src/java/de/uhilger/um/api/UserMgr.java 26 ●●●● patch | view | raw | blame | history
web/WEB-INF/sql.properties 3 ●●●●● patch | view | raw | blame | history
src/java/de/uhilger/um/api/UserMgr.java
@@ -4,11 +4,13 @@
import de.uhilger.baselink.Record;
import de.uhilger.um.App;
import de.uhilger.um.daten.User;
import de.uhilger.um.daten.UserRole;
import java.util.List;
import org.apache.catalina.realm.RealmBase;
/**
 * Klasse zur Verwaltung von Benutzern in einer Datenbank
 * Klasse zur Verwaltung von Benutzern und Rollen
 * in einer Datenbank
 * 
 * @author Ulrich Hilger
 */
@@ -17,9 +19,11 @@
  private static final String MD5 = "MD5";
  
  private static final Record UserMapper = new GenericRecord(User.class);
  private static final Record UserRoleMapper = new GenericRecord(UserRole.class);
  
  public static final String SQL_GET_USER_LIST = "getUserList";
  public static final String SQL_GET_USER_NAME_LIST = "getUserNameList";
  public static final String SQL_GET_ROLE_LIST = "getRoleList";
  public static final String SQL_DELETE_USER = "deleteUser";
  
  /* ----------- Benutzer -------------- */
@@ -52,16 +56,26 @@
  
  /* ------------ Rollen ------------------ */
  
  public String grantRole(String userId, String roleName) {
    return "not implemented";
  public UserRole grantRole(String userId, String roleName) {
    UserRole ur = new UserRole();
    ur.setRole(roleName);
    ur.setUser(userId);
    App.getDatabase().insert(ur, UserRoleMapper);
    return ur;
  }
  
  public String revokeRole(String userId, String roleName) {
    return "not implemented";
  public UserRole revokeRole(String userId, String roleName) {
    UserRole ur = new UserRole();
    ur.setRole(roleName);
    ur.setUser(userId);
    App.getDatabase().delete(ur, UserRoleMapper);
    return ur;
  }
  
  public List getRoleNamesGranted() {
    return null;
    String sql = App.getSqlStatement(SQL_GET_ROLE_LIST);
    List roleNames = App.getDatabase().select(sql, App.WITHOUT_BLOBS);
    return roleNames;
  }
  
  /* ------------ sonstige Methoden -------------- */
web/WEB-INF/sql.properties
@@ -29,6 +29,9 @@
  <entry key="getUserList">
    select * from app.users
  </entry>
  <entry key="getRoleList">
    select distinct role_name from app.user_roles order by role_name
  </entry>
  <entry key="getDateList">
    select substr(or_zeit,1,8) as tag, count(*) as anz from app.orte as orte 
    where or_pers_id = ?