人员权限控制涉及到得所有知识

来源:互联网 发布:骑行路线 知乎 编辑:程序博客网 时间:2024/06/04 17:48

public static String getValue(String key){
  File file =new java.io.File(GlobalNames.HOMEPATH     File路径
    + "/WEB-INF/SystemConfig.properties");
  if(file.lastModified()>modified){    modified 系统记录文件的最后配置时间
   reload();                                                      如果被修改了,系统会自动装载一次
   modified = file.lastModified();                     如果装载完后,把file.lastModified赋给modified
  }
  return pro.getProperty(key);
 }

 

点击查看File  空值就报出空指针。

有值就默认

public File(String pathname) {
 if (pathname == null) {
     throw new NullPointerException();
 }
 this.path = fs.normalize(pathname);
 this.prefixLength = fs.prefixLength(this.path);
    }

 

 

 

filenSystem.class 下

 Convert the given pathname string to normal form.  If the string is
     * already in normal form then it is simply returned.

 

》》public abstract String normalize(String path);

 

 

 

private  static void reload(){
  try {
   File file =new java.io.File(GlobalNames.HOMEPATH
   + "/WEB-INF/SystemConfig.properties");
   modified = file.lastModified();
   pro = null;
   FileInputStream fis = new FileInputStream(file);
   pro = new Properties();
   pro.load(fis);   
   fis.close();
  } catch (Exception ex) {
   ex.printStackTrace();
  }
 }

 

 

 

 

 

 

 public long lastModified() {
 SecurityManager security = System.getSecurityManager();          判断为空 。返回null
 if (security != null) {                         如果不为空。
     security.checkRead(path);
 }
 return fs.getLastModifiedTime(this);
    }

 

public static SecurityManager getSecurityManager() {
 return security;                                
    }

 

 

》》public class SecurityException extends RuntimeException       一个异常

 

 

 

》》public void checkRead(String file) {
 checkPermission(new FilePermission(file,
     SecurityConstants.FILE_READ_ACTION));
    }

 

 

SecurityManager.class       安全管理的类

 

public void checkPermission(Permission perm) {
 java.security.AccessController.checkPermission(perm);
    }                         

 

 

public class SecurityManagerextends Object安全管理器是一个允许应用程序实现安全策略的类。它允许应用程序在执行一个可能不安全或敏感的操作前确定该操作是什么,以及是否是在允许执行该操作的安全上下文中执行它。应用程序可以允许或不允许该操作。

SecurityManager 类包含了很多名称以单词 check 开头的方法。Java 库中的各种方法在执行某些潜在的敏感操作前可以调用这些方法。对 check 方法的典型调用如下:


     SecurityManager security = System.getSecurityManager();
     if (security != null) {
         security.checkXXX(argument,  . . . );
     }

 

 

 

 

 public FileInputStream(File file) throws FileNotFoundException {
 String name = (file != null ? file.getPath() : null);
 SecurityManager security = System.getSecurityManager();
 if (security != null) {
     security.checkRead(name);
 }
        if (name == null) {
            throw new NullPointerException();
        }
 fd = new FileDescriptor();
 open(name);
    }

 

Peroperties.class

返回一个  return pro.getProperty(key);

 

 

 

接下来需要返回一个key值。

 

 

 public String getProperty(String key) {
 Object oval = super.get(key);
 String sval = (oval instanceof String) ? (String)oval : null;
 return ((sval == null) && (defaults != null)) ? defaults.getProperty(key) : sval;
    }

 

super类

public class Hashtable<K,V>
    extends Dictionary<K,V>
    implements Map<K,V>, Cloneable, java.io.Serializable {}

 

 

 public synchronized V get(Object key) {               1. synchronized 方法:通过在方法声明中加入 synchronized关键字来声明 synchronized 方法。如:

  public synchronized void accessVal(int newVal); 
 Entry tab[] = table;
 int hash = key.hashCode();
 int index = (hash & 0x7FFFFFFF) % tab.length;
 for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) {
     if ((e.hash == hash) && e.key.equals(key)) {
  return e.value;
     }
 }
 return null;
    }

 

 

 

一个小小的权限涉及到得知识点。真多啊。还有很多没有抄出来。一大堆的class   跟蜘蛛网似的!!