?? myprivilegedaction.java
字號:
// ==================== Program Discription ==========================
// 程序名稱:示例20-4 : MyPrivilegedAction.java
// 程序目的:程序性授權
// ==============================================================
import java.io.*;
import java.security.*;
import javax.security.auth.*;
import javax.security.auth.login.*;
import java.util.*;
import com.sun.enterprise.security.*;
public class MyPrivilegedAction implements PrivilegedAction
{
public Object run() {
// Get the passed in subject from the DoAs
AccessControlContext context = AccessController.getContext();
Subject subject = Subject.getSubject( context );
if (subject == null ) {
throw new AccessControlException("Denied");
}
// Iterate through the principal set looking for sa
Set principals = subject.getPrincipals();
Iterator iterator = principals.iterator();
while (iterator.hasNext()) {
PrincipalImpl principal = (PrincipalImpl)iterator.next();
if (principal.getName().equals( "sa" )) {
System.out.println("sa has Payroll access\n");
return new Integer(0);
}
}
throw new AccessControlException("Denied");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -