8131350: policytool can directly reference permission classes
Reviewed-by: xuelei, mullan
This commit is contained in:
parent
d9cbd23d50
commit
9866d4239d
@ -633,17 +633,16 @@ public class PolicyTool {
|
||||
type.equals(PolicyParser.PrincipalEntry.REPLACE_NAME)) {
|
||||
return;
|
||||
}
|
||||
Class<?> PRIN = Class.forName("java.security.Principal");
|
||||
Class<?> pc = Class.forName(type, true,
|
||||
Thread.currentThread().getContextClassLoader());
|
||||
if (!PRIN.isAssignableFrom(pc)) {
|
||||
if (!Principal.class.isAssignableFrom(pc)) {
|
||||
MessageFormat form = new MessageFormat(getMessage
|
||||
("Illegal.Principal.Type.type"));
|
||||
Object[] source = {type};
|
||||
throw new InstantiationException(form.format(source));
|
||||
}
|
||||
|
||||
if (ToolDialog.X500_PRIN_CLASS.equals(pc.getName())) {
|
||||
if (X500Principal.class.getName().equals(pc.getName())) {
|
||||
// PolicyParser checks validity of X500Principal name
|
||||
// - PolicyTool needs to as well so that it doesn't store
|
||||
// an invalid name that can't be read in later
|
||||
@ -1563,14 +1562,6 @@ class ToolDialog extends JDialog {
|
||||
public static final int NEW = 2;
|
||||
public static final int OPEN = 3;
|
||||
|
||||
public static final String ALL_PERM_CLASS =
|
||||
"java.security.AllPermission";
|
||||
public static final String FILE_PERM_CLASS =
|
||||
"java.io.FilePermission";
|
||||
|
||||
public static final String X500_PRIN_CLASS =
|
||||
"javax.security.auth.x500.X500Principal";
|
||||
|
||||
/* popup menus */
|
||||
public static final String PERM =
|
||||
PolicyTool.getMessage
|
||||
@ -1752,11 +1743,11 @@ class ToolDialog extends JDialog {
|
||||
for (int i = 0; i < PERM_ARRAY.size(); i++) {
|
||||
Perm next = PERM_ARRAY.get(i);
|
||||
if (fullClassName) {
|
||||
if (next.FULL_CLASS.equals(clazz)) {
|
||||
if (next.getName().equals(clazz)) {
|
||||
return next;
|
||||
}
|
||||
} else {
|
||||
if (next.CLASS.equals(clazz)) {
|
||||
if (next.getSimpleName().equals(clazz)) {
|
||||
return next;
|
||||
}
|
||||
}
|
||||
@ -1772,11 +1763,11 @@ class ToolDialog extends JDialog {
|
||||
for (int i = 0; i < PRIN_ARRAY.size(); i++) {
|
||||
Prin next = PRIN_ARRAY.get(i);
|
||||
if (fullClassName) {
|
||||
if (next.FULL_CLASS.equals(clazz)) {
|
||||
if (next.getName().equals(clazz)) {
|
||||
return next;
|
||||
}
|
||||
} else {
|
||||
if (next.CLASS.equals(clazz)) {
|
||||
if (next.getSimpleName().equals(clazz)) {
|
||||
return next;
|
||||
}
|
||||
}
|
||||
@ -2170,7 +2161,7 @@ class ToolDialog extends JDialog {
|
||||
choice.getAccessibleContext().setAccessibleName(PRIN_TYPE);
|
||||
for (int i = 0; i < PRIN_ARRAY.size(); i++) {
|
||||
Prin next = PRIN_ARRAY.get(i);
|
||||
choice.addItem(next.CLASS);
|
||||
choice.addItem(next.getSimpleName());
|
||||
}
|
||||
|
||||
if (edit) {
|
||||
@ -2180,7 +2171,7 @@ class ToolDialog extends JDialog {
|
||||
} else {
|
||||
Prin inputPrin = getPrin(editMe.getPrincipalClass(), true);
|
||||
if (inputPrin != null) {
|
||||
choice.setSelectedItem(inputPrin.CLASS);
|
||||
choice.setSelectedItem(inputPrin.getSimpleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2286,7 +2277,7 @@ class ToolDialog extends JDialog {
|
||||
choice.getAccessibleContext().setAccessibleName(PERM);
|
||||
for (int i = 0; i < PERM_ARRAY.size(); i++) {
|
||||
Perm next = PERM_ARRAY.get(i);
|
||||
choice.addItem(next.CLASS);
|
||||
choice.addItem(next.getSimpleName());
|
||||
}
|
||||
tw.addNewComponent(newTD, choice, PD_PERM_CHOICE,
|
||||
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
|
||||
@ -2300,7 +2291,7 @@ class ToolDialog extends JDialog {
|
||||
if (edit) {
|
||||
Perm inputPerm = getPerm(editMe.permission, true);
|
||||
if (inputPerm != null) {
|
||||
choice.setSelectedItem(inputPerm.CLASS);
|
||||
choice.setSelectedItem(inputPerm.getSimpleName());
|
||||
}
|
||||
}
|
||||
tw.addNewComponent(newTD, tf, PD_PERM_TEXTFIELD,
|
||||
@ -2417,7 +2408,7 @@ class ToolDialog extends JDialog {
|
||||
"\t'" + pname + "' will be interpreted " +
|
||||
"as a key store alias.\n" +
|
||||
"\tThe final principal class will be " +
|
||||
ToolDialog.X500_PRIN_CLASS + ".\n" +
|
||||
X500Principal.class.getName() + ".\n" +
|
||||
"\tThe final principal name will be " +
|
||||
"determined by the following:\n" +
|
||||
"\n" +
|
||||
@ -2452,7 +2443,7 @@ class ToolDialog extends JDialog {
|
||||
if (tf.getText().trim().equals("") == false)
|
||||
name = new String(tf.getText().trim());
|
||||
if (permission.equals("") ||
|
||||
(!permission.equals(ALL_PERM_CLASS) && name == null)) {
|
||||
(!permission.equals(AllPermission.class.getName()) && name == null)) {
|
||||
throw new InvalidParameterException(PolicyTool.getMessage
|
||||
("Permission.and.Target.Name.must.have.a.value"));
|
||||
}
|
||||
@ -2467,7 +2458,8 @@ class ToolDialog extends JDialog {
|
||||
// \\server\share 0, legal
|
||||
// \\\\server\share 2, illegal
|
||||
|
||||
if (permission.equals(FILE_PERM_CLASS) && name.lastIndexOf("\\\\") > 0) {
|
||||
if (permission.equals(FilePermission.class.getName())
|
||||
&& name.lastIndexOf("\\\\") > 0) {
|
||||
char result = tw.displayYesNoDialog(this,
|
||||
PolicyTool.getMessage("Warning"),
|
||||
PolicyTool.getMessage(
|
||||
@ -3645,7 +3637,7 @@ class PrincipalTypeMenuListener implements ItemListener {
|
||||
if (prinField.getText() != null &&
|
||||
prinField.getText().length() > 0) {
|
||||
Prin inputPrin = ToolDialog.getPrin(prinField.getText(), true);
|
||||
prin.setSelectedItem(inputPrin.CLASS);
|
||||
prin.setSelectedItem(inputPrin.getSimpleName());
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -3660,7 +3652,7 @@ class PrincipalTypeMenuListener implements ItemListener {
|
||||
// set of names and actions
|
||||
Prin inputPrin = ToolDialog.getPrin((String)e.getItem(), false);
|
||||
if (inputPrin != null) {
|
||||
prinField.setText(inputPrin.FULL_CLASS);
|
||||
prinField.setText(inputPrin.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3711,7 +3703,7 @@ class PermissionMenuListener implements ItemListener {
|
||||
|
||||
Perm inputPerm = ToolDialog.getPerm(permField.getText(), true);
|
||||
if (inputPerm != null) {
|
||||
perms.setSelectedItem(inputPerm.CLASS);
|
||||
perms.setSelectedItem(inputPerm.getSimpleName());
|
||||
}
|
||||
}
|
||||
return;
|
||||
@ -3732,7 +3724,7 @@ class PermissionMenuListener implements ItemListener {
|
||||
if (inputPerm == null) {
|
||||
permField.setText("");
|
||||
} else {
|
||||
permField.setText(inputPerm.FULL_CLASS);
|
||||
permField.setText(inputPerm.getName());
|
||||
}
|
||||
td.setPermissionNames(inputPerm, names, nameField);
|
||||
td.setPermissionActions(inputPerm, actions, actionsField);
|
||||
@ -4082,26 +4074,30 @@ class TaggedList extends JList<String> {
|
||||
*/
|
||||
|
||||
class Prin {
|
||||
public final String CLASS;
|
||||
public final String FULL_CLASS;
|
||||
final Class<? extends Principal> CLASS;
|
||||
|
||||
public Prin(String clazz, String fullClass) {
|
||||
Prin(Class<? extends Principal> clazz) {
|
||||
this.CLASS = clazz;
|
||||
this.FULL_CLASS = fullClass;
|
||||
}
|
||||
|
||||
String getName() {
|
||||
return CLASS.getName();
|
||||
}
|
||||
|
||||
String getSimpleName() {
|
||||
return CLASS.getSimpleName();
|
||||
}
|
||||
}
|
||||
|
||||
class KrbPrin extends Prin {
|
||||
public KrbPrin() {
|
||||
super("KerberosPrincipal",
|
||||
"javax.security.auth.kerberos.KerberosPrincipal");
|
||||
KrbPrin() {
|
||||
super(javax.security.auth.kerberos.KerberosPrincipal.class);
|
||||
}
|
||||
}
|
||||
|
||||
class X500Prin extends Prin {
|
||||
public X500Prin() {
|
||||
super("X500Principal",
|
||||
"javax.security.auth.x500.X500Principal");
|
||||
X500Prin() {
|
||||
super(javax.security.auth.x500.X500Principal.class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4110,31 +4106,36 @@ class X500Prin extends Prin {
|
||||
*/
|
||||
|
||||
class Perm {
|
||||
public final String CLASS;
|
||||
public final String FULL_CLASS;
|
||||
public final String[] TARGETS;
|
||||
public final String[] ACTIONS;
|
||||
final Class<? extends Permission> CLASS;
|
||||
final String[] TARGETS;
|
||||
final String[] ACTIONS;
|
||||
|
||||
public Perm(String clazz, String fullClass,
|
||||
Perm(Class<? extends Permission> clazz,
|
||||
String[] targets, String[] actions) {
|
||||
|
||||
this.CLASS = clazz;
|
||||
this.FULL_CLASS = fullClass;
|
||||
this.TARGETS = targets;
|
||||
this.ACTIONS = actions;
|
||||
}
|
||||
|
||||
String getName() {
|
||||
return CLASS.getName();
|
||||
}
|
||||
|
||||
String getSimpleName() {
|
||||
return CLASS.getSimpleName();
|
||||
}
|
||||
}
|
||||
|
||||
class AllPerm extends Perm {
|
||||
public AllPerm() {
|
||||
super("AllPermission", "java.security.AllPermission", null, null);
|
||||
AllPerm() {
|
||||
super(java.security.AllPermission.class, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
class AudioPerm extends Perm {
|
||||
public AudioPerm() {
|
||||
super("AudioPermission",
|
||||
"javax.sound.sampled.AudioPermission",
|
||||
AudioPerm() {
|
||||
super(javax.sound.sampled.AudioPermission.class,
|
||||
new String[] {
|
||||
"play",
|
||||
"record"
|
||||
@ -4144,9 +4145,8 @@ class AudioPerm extends Perm {
|
||||
}
|
||||
|
||||
class AuthPerm extends Perm {
|
||||
public AuthPerm() {
|
||||
super("AuthPermission",
|
||||
"javax.security.auth.AuthPermission",
|
||||
AuthPerm() {
|
||||
super(javax.security.auth.AuthPermission.class,
|
||||
new String[] {
|
||||
"doAs",
|
||||
"doAsPrivileged",
|
||||
@ -4170,9 +4170,8 @@ class AuthPerm extends Perm {
|
||||
}
|
||||
|
||||
class AWTPerm extends Perm {
|
||||
public AWTPerm() {
|
||||
super("AWTPermission",
|
||||
"java.awt.AWTPermission",
|
||||
AWTPerm() {
|
||||
super(java.awt.AWTPermission.class,
|
||||
new String[] {
|
||||
"accessClipboard",
|
||||
"accessEventQueue",
|
||||
@ -4193,9 +4192,8 @@ class AWTPerm extends Perm {
|
||||
}
|
||||
|
||||
class DelegationPerm extends Perm {
|
||||
public DelegationPerm() {
|
||||
super("DelegationPermission",
|
||||
"javax.security.auth.kerberos.DelegationPermission",
|
||||
DelegationPerm() {
|
||||
super(javax.security.auth.kerberos.DelegationPermission.class,
|
||||
new String[] {
|
||||
// allow user input
|
||||
},
|
||||
@ -4204,9 +4202,8 @@ class DelegationPerm extends Perm {
|
||||
}
|
||||
|
||||
class FilePerm extends Perm {
|
||||
public FilePerm() {
|
||||
super("FilePermission",
|
||||
"java.io.FilePermission",
|
||||
FilePerm() {
|
||||
super(java.io.FilePermission.class,
|
||||
new String[] {
|
||||
"<<ALL FILES>>"
|
||||
},
|
||||
@ -4220,9 +4217,8 @@ class FilePerm extends Perm {
|
||||
}
|
||||
|
||||
class URLPerm extends Perm {
|
||||
public URLPerm() {
|
||||
super("URLPermission",
|
||||
"java.net.URLPermission",
|
||||
URLPerm() {
|
||||
super(java.net.URLPermission.class,
|
||||
new String[] {
|
||||
"<"+ PolicyTool.getMessage("url") + ">",
|
||||
},
|
||||
@ -4234,9 +4230,8 @@ class URLPerm extends Perm {
|
||||
}
|
||||
|
||||
class InqSecContextPerm extends Perm {
|
||||
public InqSecContextPerm() {
|
||||
super("InquireSecContextPermission",
|
||||
"com.sun.security.jgss.InquireSecContextPermission",
|
||||
InqSecContextPerm() {
|
||||
super(com.sun.security.jgss.InquireSecContextPermission.class,
|
||||
new String[] {
|
||||
"KRB5_GET_SESSION_KEY",
|
||||
"KRB5_GET_TKT_FLAGS",
|
||||
@ -4248,9 +4243,8 @@ class InqSecContextPerm extends Perm {
|
||||
}
|
||||
|
||||
class LogPerm extends Perm {
|
||||
public LogPerm() {
|
||||
super("LoggingPermission",
|
||||
"java.util.logging.LoggingPermission",
|
||||
LogPerm() {
|
||||
super(java.util.logging.LoggingPermission.class,
|
||||
new String[] {
|
||||
"control"
|
||||
},
|
||||
@ -4259,9 +4253,8 @@ class LogPerm extends Perm {
|
||||
}
|
||||
|
||||
class MgmtPerm extends Perm {
|
||||
public MgmtPerm() {
|
||||
super("ManagementPermission",
|
||||
"java.lang.management.ManagementPermission",
|
||||
MgmtPerm() {
|
||||
super(java.lang.management.ManagementPermission.class,
|
||||
new String[] {
|
||||
"control",
|
||||
"monitor"
|
||||
@ -4271,9 +4264,8 @@ class MgmtPerm extends Perm {
|
||||
}
|
||||
|
||||
class MBeanPerm extends Perm {
|
||||
public MBeanPerm() {
|
||||
super("MBeanPermission",
|
||||
"javax.management.MBeanPermission",
|
||||
MBeanPerm() {
|
||||
super(javax.management.MBeanPermission.class,
|
||||
new String[] {
|
||||
// allow user input
|
||||
},
|
||||
@ -4300,9 +4292,8 @@ class MBeanPerm extends Perm {
|
||||
}
|
||||
|
||||
class MBeanSvrPerm extends Perm {
|
||||
public MBeanSvrPerm() {
|
||||
super("MBeanServerPermission",
|
||||
"javax.management.MBeanServerPermission",
|
||||
MBeanSvrPerm() {
|
||||
super(javax.management.MBeanServerPermission.class,
|
||||
new String[] {
|
||||
"createMBeanServer",
|
||||
"findMBeanServer",
|
||||
@ -4314,9 +4305,8 @@ class MBeanSvrPerm extends Perm {
|
||||
}
|
||||
|
||||
class MBeanTrustPerm extends Perm {
|
||||
public MBeanTrustPerm() {
|
||||
super("MBeanTrustPermission",
|
||||
"javax.management.MBeanTrustPermission",
|
||||
MBeanTrustPerm() {
|
||||
super(javax.management.MBeanTrustPermission.class,
|
||||
new String[] {
|
||||
"register"
|
||||
},
|
||||
@ -4325,9 +4315,8 @@ class MBeanTrustPerm extends Perm {
|
||||
}
|
||||
|
||||
class NetPerm extends Perm {
|
||||
public NetPerm() {
|
||||
super("NetPermission",
|
||||
"java.net.NetPermission",
|
||||
NetPerm() {
|
||||
super(java.net.NetPermission.class,
|
||||
new String[] {
|
||||
"allowHttpTrace",
|
||||
"setDefaultAuthenticator",
|
||||
@ -4346,9 +4335,8 @@ class NetPerm extends Perm {
|
||||
}
|
||||
|
||||
class NetworkPerm extends Perm {
|
||||
public NetworkPerm() {
|
||||
super("NetworkPermission",
|
||||
"jdk.net.NetworkPermission",
|
||||
NetworkPerm() {
|
||||
super(jdk.net.NetworkPermission.class,
|
||||
new String[] {
|
||||
"setOption.SO_FLOW_SLA",
|
||||
"getOption.SO_FLOW_SLA"
|
||||
@ -4358,9 +4346,8 @@ class NetworkPerm extends Perm {
|
||||
}
|
||||
|
||||
class PrivCredPerm extends Perm {
|
||||
public PrivCredPerm() {
|
||||
super("PrivateCredentialPermission",
|
||||
"javax.security.auth.PrivateCredentialPermission",
|
||||
PrivCredPerm() {
|
||||
super(javax.security.auth.PrivateCredentialPermission.class,
|
||||
new String[] {
|
||||
// allow user input
|
||||
},
|
||||
@ -4371,9 +4358,8 @@ class PrivCredPerm extends Perm {
|
||||
}
|
||||
|
||||
class PropPerm extends Perm {
|
||||
public PropPerm() {
|
||||
super("PropertyPermission",
|
||||
"java.util.PropertyPermission",
|
||||
PropPerm() {
|
||||
super(java.util.PropertyPermission.class,
|
||||
new String[] {
|
||||
// allow user input
|
||||
},
|
||||
@ -4385,9 +4371,8 @@ class PropPerm extends Perm {
|
||||
}
|
||||
|
||||
class ReflectPerm extends Perm {
|
||||
public ReflectPerm() {
|
||||
super("ReflectPermission",
|
||||
"java.lang.reflect.ReflectPermission",
|
||||
ReflectPerm() {
|
||||
super(java.lang.reflect.ReflectPermission.class,
|
||||
new String[] {
|
||||
"suppressAccessChecks"
|
||||
},
|
||||
@ -4396,9 +4381,8 @@ class ReflectPerm extends Perm {
|
||||
}
|
||||
|
||||
class RuntimePerm extends Perm {
|
||||
public RuntimePerm() {
|
||||
super("RuntimePermission",
|
||||
"java.lang.RuntimePermission",
|
||||
RuntimePerm() {
|
||||
super(java.lang.RuntimePermission.class,
|
||||
new String[] {
|
||||
"createClassLoader",
|
||||
"getClassLoader",
|
||||
@ -4437,9 +4421,8 @@ class RuntimePerm extends Perm {
|
||||
}
|
||||
|
||||
class SecurityPerm extends Perm {
|
||||
public SecurityPerm() {
|
||||
super("SecurityPermission",
|
||||
"java.security.SecurityPermission",
|
||||
SecurityPerm() {
|
||||
super(java.security.SecurityPermission.class,
|
||||
new String[] {
|
||||
"createAccessControlContext",
|
||||
"getDomainCombiner",
|
||||
@ -4475,9 +4458,8 @@ class SecurityPerm extends Perm {
|
||||
}
|
||||
|
||||
class SerialPerm extends Perm {
|
||||
public SerialPerm() {
|
||||
super("SerializablePermission",
|
||||
"java.io.SerializablePermission",
|
||||
SerialPerm() {
|
||||
super(java.io.SerializablePermission.class,
|
||||
new String[] {
|
||||
"enableSubclassImplementation",
|
||||
"enableSubstitution"
|
||||
@ -4487,9 +4469,8 @@ class SerialPerm extends Perm {
|
||||
}
|
||||
|
||||
class ServicePerm extends Perm {
|
||||
public ServicePerm() {
|
||||
super("ServicePermission",
|
||||
"javax.security.auth.kerberos.ServicePermission",
|
||||
ServicePerm() {
|
||||
super(javax.security.auth.kerberos.ServicePermission.class,
|
||||
new String[] {
|
||||
// allow user input
|
||||
},
|
||||
@ -4501,9 +4482,8 @@ class ServicePerm extends Perm {
|
||||
}
|
||||
|
||||
class SocketPerm extends Perm {
|
||||
public SocketPerm() {
|
||||
super("SocketPermission",
|
||||
"java.net.SocketPermission",
|
||||
SocketPerm() {
|
||||
super(java.net.SocketPermission.class,
|
||||
new String[] {
|
||||
// allow user input
|
||||
},
|
||||
@ -4517,9 +4497,8 @@ class SocketPerm extends Perm {
|
||||
}
|
||||
|
||||
class SQLPerm extends Perm {
|
||||
public SQLPerm() {
|
||||
super("SQLPermission",
|
||||
"java.sql.SQLPermission",
|
||||
SQLPerm() {
|
||||
super(java.sql.SQLPermission.class,
|
||||
new String[] {
|
||||
"setLog",
|
||||
"callAbort",
|
||||
@ -4531,9 +4510,8 @@ class SQLPerm extends Perm {
|
||||
}
|
||||
|
||||
class SSLPerm extends Perm {
|
||||
public SSLPerm() {
|
||||
super("SSLPermission",
|
||||
"javax.net.ssl.SSLPermission",
|
||||
SSLPerm() {
|
||||
super(javax.net.ssl.SSLPermission.class,
|
||||
new String[] {
|
||||
"setHostnameVerifier",
|
||||
"getSSLSessionContext"
|
||||
@ -4543,9 +4521,8 @@ class SSLPerm extends Perm {
|
||||
}
|
||||
|
||||
class SubjDelegPerm extends Perm {
|
||||
public SubjDelegPerm() {
|
||||
super("SubjectDelegationPermission",
|
||||
"javax.management.remote.SubjectDelegationPermission",
|
||||
SubjDelegPerm() {
|
||||
super(javax.management.remote.SubjectDelegationPermission.class,
|
||||
new String[] {
|
||||
// allow user input
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user