From 8c98a8feb6a9a217240efaba9f032005a758621a Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Mon, 16 Aug 2021 18:38:31 +0200 Subject: [PATCH] introduce storagelimits --- .../de/hsadmin/mods/pac/PacModuleImpl.java | 4 +++- .../src/de/hsadmin/mods/user/UnixUser.java | 24 +++++++++++++++++++ .../hsadmin/mods/user/UnixUserModuleImpl.java | 16 +++++++++++++ .../src/de/hsadmin/remote/UnixUserRemote.java | 20 +++++++++++----- 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java b/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java index a2e54f4..98fecc4 100644 --- a/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java @@ -103,8 +103,10 @@ public class PacModuleImpl extends AbstractModuleImpl { admin.setHomedir("/home/pacs/" + pac.getName()); admin.setName(pac.getName()); admin.setShell("/bin/bash"); - admin.setQuotaSoftlimit(0); admin.setQuotaHardlimit(0); + admin.setQuotaSoftlimit(0); + admin.setStorageHardlimit(0); + admin.setStorageSoftlimit(0); admin.setPac(pac); long nUID = 20000; Long maxUid = (Long) em.createQuery("SELECT MAX(u.userId) FROM UnixUsers u").getSingleResult(); diff --git a/hsarback/src/de/hsadmin/mods/user/UnixUser.java b/hsarback/src/de/hsadmin/mods/user/UnixUser.java index 03fa198..0ad0f2f 100644 --- a/hsarback/src/de/hsadmin/mods/user/UnixUser.java +++ b/hsarback/src/de/hsadmin/mods/user/UnixUser.java @@ -77,6 +77,14 @@ public class UnixUser extends AbstractEntity implements Serializable { @Column(name = "quota_hardlimit", columnDefinition = "integer") private Integer quotaHardlimit; + @AnnFieldIO(validation="[0-9]*", rw=ReadWriteAccess.READWRITE, overwriteName="storage_softlimit") + @Column(name = "storage_softlimit", columnDefinition = "integer") + private Integer storageSoftlimit; + + @AnnFieldIO(validation="[0-9]*", rw=ReadWriteAccess.READWRITE, overwriteName="storage_hardlimit") + @Column(name = "storage_hardlimit", columnDefinition = "integer") + private Integer storageHardlimit; + public UnixUser() { } @@ -228,6 +236,22 @@ public class UnixUser extends AbstractEntity implements Serializable { return quotaHardlimit; } + public Integer getStorageSoftlimit() { + return storageSoftlimit; + } + + public void setStorageSoftlimit(Integer storage) { + this.storageSoftlimit = storage; + } + + public void setStorageHardlimit(Integer storageLimit) { + this.storageHardlimit = storageLimit; + } + + public Integer getStorageHardlimit() { + return storageHardlimit; + } + @Override public boolean isNew() { return id == 0; diff --git a/hsarback/src/de/hsadmin/mods/user/UnixUserModuleImpl.java b/hsarback/src/de/hsadmin/mods/user/UnixUserModuleImpl.java index 45a1efe..0db1866 100644 --- a/hsarback/src/de/hsadmin/mods/user/UnixUserModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/user/UnixUserModuleImpl.java @@ -208,6 +208,22 @@ public class UnixUserModuleImpl extends AbstractModuleImpl { } } } + if (detachedUnixUser.getStorageSoftlimit() != null) { + if (hasFullAccessOnPacOf(attachedUnixUser)) { + attachedUnixUser.setStorageSoftlimit(detachedUnixUser.getStorageSoftlimit()); + if (detachedUnixUser.getStorageHardlimit() != null) { + attachedUnixUser.setStorageHardlimit(detachedUnixUser.getStorageHardlimit()); + } + } + else { + Integer oldQuota = attachedUnixUser.getStorageSoftlimit(); + Integer newQuota = detachedUnixUser.getStorageSoftlimit(); + if (oldQuota != newQuota && !oldQuota.equals(newQuota)) { + throw new AuthorisationException(loginUser, "update", detachedUnixUser, "storage"); + } + } + } + return super.update(attachedUnixUser); } diff --git a/hsarback/src/de/hsadmin/remote/UnixUserRemote.java b/hsarback/src/de/hsadmin/remote/UnixUserRemote.java index 4e36022..01576d1 100644 --- a/hsarback/src/de/hsadmin/remote/UnixUserRemote.java +++ b/hsarback/src/de/hsadmin/remote/UnixUserRemote.java @@ -65,13 +65,21 @@ public class UnixUserRemote extends AbstractRemote { if (assertNotNull(homedir)) { user.setHomedir(homedir); } - String quota = (String) map.get("quota_softlimit"); - if (assertNotNull(quota)) { - user.setQuotaSoftlimit(Integer.parseInt(quota)); + String quotaSoftlimit = (String) map.get("quota_softlimit"); + if (assertNotNull(quotaSoftlimit)) { + user.setQuotaSoftlimit(Integer.parseInt(quotaSoftlimit)); } - String quotaLimit = (String) map.get("quota_hardlimit"); - if (assertNotNull(quotaLimit)) { - user.setQuotaHardlimit(Integer.parseInt(quotaLimit)); + String quotaHardlimit = (String) map.get("quota_hardlimit"); + if (assertNotNull(quotaHardlimit)) { + user.setQuotaHardlimit(Integer.parseInt(quotaHardlimit)); + } + String storageSoftlimit = (String) map.get("storage_softlimit"); + if (assertNotNull(storageSoftlimit)) { + user.setStorageSoftlimit(Integer.parseInt(storageSoftlimit)); + } + String storageHardlimit = (String) map.get("storage_hardlimit"); + if (assertNotNull(storageHardlimit)) { + user.setStorageHardlimit(Integer.parseInt(storageHardlimit)); } Boolean locked = (Boolean) map.get("locked"); if (assertNotNull(locked)) {