SecurityManager USE

Posted rojas

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SecurityManager USE相关的知识,希望对你有一定的参考价值。

 

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class BaseT {

    public static void main(String[] args) throws IOException {
        
        System.setSecurityManager(new mySecurityM("ABC","123"));
        File f=new File("E:\\Test.java"); 
        DataInputStream fis=new DataInputStream(new FileInputStream(f));
        String x="";
        
        while((x=fis.readLine())!=null){
            System.out.println(x);
        }
        fis.close();
    }
}

//----------------------
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class mySecurityM extends SecurityManager {
    private String upwd;
    private String unam;
    public mySecurityM(String unam,String upwd){
        this.upwd=upwd;
        this.unam=unam;
    }
    public boolean okacess(){
        System.out.println("请输入用户名和密码,用逗号隔开");
        BufferedReader dis = new BufferedReader(new InputStreamReader(System.in));
        try {
        String[] value=dis.readLine().split(",");
        if (value[0].equals(this.unam)&&value[1].equals(this.upwd))
        return true;
        else
        return false;
        } catch (IOException e) {
        return false;
        }
    }
 
    public void checkRead(String file){
        if(!okacess()){
            throw new SecurityException("No Premission.");
        }
    }
    
}

 

以上是关于SecurityManager USE的主要内容,如果未能解决你的问题,请参考以下文章

JAVA SecurityManager - 具有多个操作的自定义 BasicPermission

ngx-translate实现国际化:this.translate.use()this.translate.get()this.translate.instant()onLangChange(代码片段

[React Testing] Use Generated Data in Tests with tests-data-bot to Improve Test Maintainability(代码片段

[Grid Layout] Use auto-fill and auto-fit if the number of repeated grid tracks is not to be def(代码片段

Java SecurityManager 多线程

Shiro No SecurityManager 可供调用代码访问