1 22 package org.jboss.aop.advice; 23 24 import java.beans.PropertyEditorManager ; 25 import java.security.AccessController ; 26 import java.security.PrivilegedActionException ; 27 import java.security.PrivilegedExceptionAction ; 28 29 import org.jboss.util.propertyeditor.ClassArrayEditor; 30 import org.jboss.util.propertyeditor.IntArrayEditor; 31 import org.jboss.util.propertyeditor.StringArrayEditor; 32 33 import javassist.CtClass; 34 35 40 public class SecurityActions 41 { 42 private interface InitPropertyEditorsAction 43 { 44 void initEditors(); 45 46 InitPropertyEditorsAction PRIVILEGED = new InitPropertyEditorsAction() 47 { 48 public void initEditors() 49 { 50 try 51 { 52 AccessController.doPrivileged(new PrivilegedExceptionAction () 53 { 54 public Object run() throws Exception 55 { 56 doInitEditors(); 57 return null; 58 } 59 }); 60 } 61 catch (PrivilegedActionException e) 62 { 63 throw new RuntimeException (e.getException()); 64 } 65 } 66 }; 67 68 InitPropertyEditorsAction NON_PRIVILEGED = new InitPropertyEditorsAction() 69 { 70 public void initEditors() 71 { 72 doInitEditors(); 73 } 74 }; 75 } 76 77 private static void doInitEditors() 78 { 79 String [] currentPath = PropertyEditorManager.getEditorSearchPath(); 80 int length = currentPath != null ? currentPath.length : 0; 81 String [] newPath = new String [length+2]; 82 System.arraycopy(currentPath, 0, newPath, 2, length); 83 newPath[0] = "org.jboss.util.propertyeditor"; 86 newPath[1] = "org.jboss.mx.util.propertyeditor"; 87 PropertyEditorManager.setEditorSearchPath(newPath); 88 89 93 Class strArrayType = String [].class; 94 PropertyEditorManager.registerEditor(strArrayType, StringArrayEditor.class); 95 Class clsArrayType = Class [].class; 96 PropertyEditorManager.registerEditor(clsArrayType, ClassArrayEditor.class); 97 Class intArrayType = int[].class; 98 PropertyEditorManager.registerEditor(intArrayType, IntArrayEditor.class); 99 } 100 101 102 static void initEditors() 103 { 104 if (System.getSecurityManager() == null) 105 { 106 InitPropertyEditorsAction.NON_PRIVILEGED.initEditors(); 107 } 108 else 109 { 110 InitPropertyEditorsAction.PRIVILEGED.initEditors(); 111 } 112 } 113 114 } 115 | Popular Tags |