001package jmri; 002 003 004import org.openide.util.lookup.ServiceProvider; 005 006/** 007 * Standard permissions. 008 * 009 * @author Daniel Bergqvist (C) 2024 010 */ 011public class PermissionsSystemAdmin { 012 013 public static final PermissionOwner PERMISSION_OWNER_SYSTEM_ADMIN = 014 new PermissionOwnerSystemAdmin(); 015 016 public static final Permission PERMISSION_EDIT_PREFERENCES = 017 new PermissionEditPreferences(); 018 019 public static final Permission PERMISSION_EDIT_PERMISSIONS = 020 new PermissionEditPermissions(); 021 022 public static final Permission PERMISSION_EDIT_OWN_PASSWORD = 023 new PermissionEditOwnPassword(); 024 025 026 @ServiceProvider(service = PermissionFactory.class) 027 public static class Factory implements PermissionFactory { 028 029 @Override 030 public void register(PermissionManager manager) { 031 manager.registerOwner(PERMISSION_OWNER_SYSTEM_ADMIN); 032 manager.registerPermission(PERMISSION_EDIT_PREFERENCES); 033 manager.registerPermission(PERMISSION_EDIT_PERMISSIONS); 034 manager.registerPermission(PERMISSION_EDIT_OWN_PASSWORD); 035 } 036 037 } 038 039 040 public static class PermissionOwnerSystemAdmin implements PermissionOwner { 041 042 @Override 043 public String getName() { 044 return Bundle.getMessage("PermissionsSystemAdmin_PermissionOwnerSystemAdmin"); 045 } 046 047 } 048 049 public static class PermissionEditPermissions implements BooleanPermission { 050 051 @Override 052 public PermissionOwner getOwner() { 053 return PERMISSION_OWNER_SYSTEM_ADMIN; 054 } 055 056 @Override 057 public String getName() { 058 return Bundle.getMessage("PermissionsSystemAdmin_PermissionEditPermissions"); 059 } 060 061 @Override 062 public BooleanValue getDefaultPermission(Role role) { 063 return BooleanValue.get(role.isAdminRole()); 064 } 065 066 } 067 068 public static class PermissionEditPreferences implements BooleanPermission { 069 070 @Override 071 public PermissionOwner getOwner() { 072 return PERMISSION_OWNER_SYSTEM_ADMIN; 073 } 074 075 @Override 076 public String getName() { 077 return Bundle.getMessage("PermissionsSystemAdmin_PermissionEditPreferences"); 078 } 079 080 @Override 081 public BooleanValue getDefaultPermission(Role role) { 082 return BooleanValue.get(role.isAdminRole()); 083 } 084 085 } 086 087 public static class PermissionEditOwnPassword implements BooleanPermission { 088 089 @Override 090 public PermissionOwner getOwner() { 091 return PERMISSION_OWNER_SYSTEM_ADMIN; 092 } 093 094 @Override 095 public String getName() { 096 return Bundle.getMessage("PermissionsSystemAdmin_PermissionChangeOwnPassword"); 097 } 098 099 @Override 100 public BooleanValue getDefaultPermission(Role role) { 101 return BooleanValue.get(role.isAdminRole() || role.isStandardUserRole()); 102 } 103 104 } 105 106 // This class should never be instantiated. 107 private PermissionsSystemAdmin() {} 108 109 110}