Java Code Examples for java.security.AccessController

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project android-client_1, under directory /src/org/apache/harmony/javax/security/auth/login/.

Source file: LoginContext.java

  29 
vote

/** 
 * Warning: calling the method more than once may result in undefined behaviour if logout() method is not invoked before.
 */
public void login() throws LoginException {
  PrivilegedExceptionAction<Void> action=new PrivilegedExceptionAction<Void>(){
    public Void run() throws LoginException {
      loginImpl();
      return null;
    }
  }
;
  try {
    if (userProvidedConfig) {
      AccessController.doPrivileged(action,userContext);
    }
 else {
      AccessController.doPrivileged(action);
    }
  }
 catch (  PrivilegedActionException ex) {
    throw (LoginException)ex.getException();
  }
}
 

Example 2

From project Android_1, under directory /org.eclipse.ecf.android/src/org/eclipse/ecf/android/.

Source file: Client.java

  29 
vote

private void setupThreads(){
  debug("setupThreads()");
  sendThread=(Thread)AccessController.doPrivileged(new PrivilegedAction(){
    public Object run(){
      return getSendThread();
    }
  }
);
  rcvThread=(Thread)AccessController.doPrivileged(new PrivilegedAction(){
    public Object run(){
      return getRcvThread();
    }
  }
);
}
 

Example 3

From project api, under directory /weld-spi/src/main/java/org/jboss/weld/bootstrap/api/helpers/.

Source file: TCCLSingletonProvider.java

  29 
vote

private ClassLoader getClassLoader(){
  SecurityManager sm=System.getSecurityManager();
  if (sm != null) {
    return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>(){
      public ClassLoader run(){
        return Thread.currentThread().getContextClassLoader();
      }
    }
);
  }
 else {
    return Thread.currentThread().getContextClassLoader();
  }
}
 

Example 4

From project arquillian-container-gae, under directory /gae-common/src/main/java/org/jboss/arquillian/container/common/.

Source file: AppEngineCommonContainer.java

  29 
vote

public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
  prepareArchive(archive);
  FixedExplodedExporter exporter=new FixedExplodedExporter(archive,AccessController.doPrivileged(new PrivilegedAction<File>(){
    public File run(){
      return new File(System.getProperty("java.io.tmpdir"));
    }
  }
));
  appLocation=exporter.export();
  return doDeploy(archive);
}
 

Example 5

From project arquillian-container-openshift, under directory /openshift-express/src/main/java/org/jboss/arquillian/container/openshift/express/auth/.

Source file: SecurityActions.java

  29 
vote

static String getProperty(final String key){
  try {
    String value=AccessController.doPrivileged(new PrivilegedExceptionAction<String>(){
      public String run(){
        return System.getProperty(key);
      }
    }
);
    return value;
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof SecurityException) {
      throw (SecurityException)t;
    }
    if (t instanceof NullPointerException) {
      throw (NullPointerException)t;
    }
 else     if (t instanceof IllegalArgumentException) {
      throw (IllegalArgumentException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 6

From project arquillian-container-tomcat, under directory /tomcat-managed-5.5/src/main/java/org/jboss/arquillian/container/tomcat/managed_5_5/.

Source file: TomcatManagedConfiguration.java

  29 
vote

@Override public void validate() throws ConfigurationException {
  super.validate();
  Validate.configurationDirectoryExists(catalinaHome,"Either CATALINA_HOME environment variable or catalinaHome property in Arquillian configuration must be set and point to a valid directory! " + catalinaHome + " is not valid directory!");
  Validate.configurationDirectoryExists(javaHome,"Either JAVA_HOME environment variable or javaHome property in Arquillian configuration must be set and point to a valid directory! " + javaHome + " is not valid directory!");
  Validate.isValidFile(catalinaHome + "/conf/" + serverConfig,"The server configuration file denoted by serverConfig property has to exist! This file: " + catalinaHome + "/conf/"+ serverConfig+ " does not!");
  this.outputToConsole=AccessController.doPrivileged(new PrivilegedAction<Boolean>(){
    @Override public Boolean run(){
      String val=System.getProperty("org.apache.tomcat.writeconsole");
      return val == null || !"false".equals(val);
    }
  }
);
}
 

Example 7

From project arquillian-core, under directory /config/impl-base/src/main/java/org/jboss/arquillian/config/impl/extension/.

Source file: SysPropertyActions.java

  29 
vote

public String getProperty(final String name,final String defaultValue){
  final PrivilegedAction<String> action=new PrivilegedAction<String>(){
    public String run(){
      return System.getProperty(name,defaultValue);
    }
  }
;
  return (String)AccessController.doPrivileged(action);
}
 

Example 8

From project arquillian-extension-android, under directory /android-configuration/src/main/java/org/jboss/arquillian/android/configuration/.

Source file: SecurityActions.java

  29 
vote

/** 
 * Obtains the Constructor specified from the given Class and argument types
 * @param clazz
 * @param argumentTypes
 * @return
 * @throws NoSuchMethodException
 */
static Constructor<?> getConstructor(final Class<?> clazz,final Class<?>... argumentTypes) throws NoSuchMethodException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>(){
      public Constructor<?> run() throws NoSuchMethodException {
        return clazz.getConstructor(argumentTypes);
      }
    }
);
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof NoSuchMethodException) {
      throw (NoSuchMethodException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 9

From project arquillian-extension-drone, under directory /drone-configuration/src/main/java/org/jboss/arquillian/drone/configuration/.

Source file: SecurityActions.java

  29 
vote

static Map<String,Field> getAccessableFields(final Class<?> source){
  Map<String,Field> declaredAccessableFields=AccessController.doPrivileged(new PrivilegedAction<Map<String,Field>>(){
    public Map<String,Field> run(){
      Map<String,Field> foundFields=new LinkedHashMap<String,Field>();
      for (      Field field : source.getDeclaredFields()) {
        if (Modifier.isFinal(field.getModifiers())) {
          continue;
        }
        if (!field.isAccessible()) {
          field.setAccessible(true);
        }
        foundFields.put(field.getName(),field);
      }
      return foundFields;
    }
  }
);
  return declaredAccessableFields;
}
 

Example 10

From project arquillian-extension-persistence, under directory /impl/src/main/java/org/jboss/arquillian/persistence/core/configuration/.

Source file: SecurityActions.java

  29 
vote

static List<Field> getAccessibleFields(final Class<?> source){
  List<Field> declaredAccessableFields=AccessController.doPrivileged(new PrivilegedAction<List<Field>>(){
    public List<Field> run(){
      List<Field> foundFields=new ArrayList<Field>();
      for (      Field field : source.getDeclaredFields()) {
        if (Modifier.isFinal(field.getModifiers())) {
          continue;
        }
        if (!field.isAccessible()) {
          field.setAccessible(true);
        }
        foundFields.add(field);
      }
      return foundFields;
    }
  }
);
  return declaredAccessableFields;
}
 

Example 11

From project arquillian-extension-seam2, under directory /src/main/java/org/jboss/arquillian/seam2/configuration/.

Source file: SecurityActions.java

  29 
vote

static List<Field> getAccessibleFields(final Class<?> source){
  List<Field> declaredAccessableFields=AccessController.doPrivileged(new PrivilegedAction<List<Field>>(){
    public List<Field> run(){
      List<Field> foundFields=new ArrayList<Field>();
      for (      Field field : source.getDeclaredFields()) {
        if (Modifier.isFinal(field.getModifiers())) {
          continue;
        }
        if (!field.isAccessible()) {
          field.setAccessible(true);
        }
        foundFields.add(field);
      }
      return foundFields;
    }
  }
);
  return declaredAccessableFields;
}
 

Example 12

From project arquillian-extension-spring, under directory /arquillian-service-integration-spring/src/main/java/org/jboss/arquillian/spring/integration/container/.

Source file: SecurityActions.java

  29 
vote

/** 
 * <p>Retrieves current thread class loader.</p>
 * @return the class loader
 */
private static ClassLoader getThreadContextClassLoader(){
  return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>(){
    public ClassLoader run(){
      return Thread.currentThread().getContextClassLoader();
    }
  }
);
}
 

Example 13

From project arquillian-extension-warp, under directory /impl/src/main/java/org/jboss/arquillian/warp/impl/server/test/.

Source file: SecurityActions.java

  29 
vote

/** 
 * Obtains the Constructor specified from the given Class and argument types
 * @param clazz
 * @param argumentTypes
 * @return
 * @throws NoSuchMethodException
 */
static Constructor<?> getConstructor(final Class<?> clazz,final Class<?>... argumentTypes) throws NoSuchMethodException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>(){
      public Constructor<?> run() throws NoSuchMethodException {
        return clazz.getConstructor(argumentTypes);
      }
    }
);
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof NoSuchMethodException) {
      throw (NoSuchMethodException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 14

From project arquillian-graphene, under directory /graphene-webdriver/graphene-webdriver-impl/src/main/java/org/jboss/arquillian/graphene/configuration/.

Source file: SecurityActions.java

  29 
vote

static Map<String,Field> getAccessableFields(final Class<?> source){
  Map<String,Field> declaredAccessableFields=AccessController.doPrivileged(new PrivilegedAction<Map<String,Field>>(){
    public Map<String,Field> run(){
      Map<String,Field> foundFields=new LinkedHashMap<String,Field>();
      for (      Field field : source.getDeclaredFields()) {
        if (Modifier.isFinal(field.getModifiers())) {
          continue;
        }
        if (!field.isAccessible()) {
          field.setAccessible(true);
        }
        foundFields.put(field.getName(),field);
      }
      return foundFields;
    }
  }
);
  return declaredAccessableFields;
}
 

Example 15

From project arquillian-showcase, under directory /extensions/autodiscover/src/main/java/org/jboss/arquillian/showcase/extension/autodiscover/.

Source file: ReflectionHelper.java

  29 
vote

/** 
 * Obtains the Constructor specified from the given Class and argument types
 * @param clazz
 * @param argumentTypes
 * @return
 * @throws NoSuchMethodException
 */
public static Constructor<?> getConstructor(final Class<?> clazz,final Class<?>... argumentTypes) throws NoSuchMethodException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>(){
      public Constructor<?> run() throws NoSuchMethodException {
        return clazz.getConstructor(argumentTypes);
      }
    }
);
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof NoSuchMethodException) {
      throw (NoSuchMethodException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 16

From project arquillian_deprecated, under directory /containers/openejb-embedded-3.1/src/main/java/org/jboss/arquillian/container/openejb/embedded_3_1/.

Source file: OpenEJBTestEnricher.java

  29 
vote

/** 
 * {@inheritDoc}
 * @see org.jboss.arquillian.testenricher.ejb.EJBInjectionEnricher#enrich(org.jboss.arquillian.spi.Context,java.lang.Object)
 */
@Override public void enrich(Object testCase){
  super.enrich(testCase);
  final Class<? extends Annotation> inject=(Class<? extends Annotation>)Inject.class;
  List<Field> fieldsWithInject=this.getFieldsWithAnnotation(testCase.getClass(),inject);
  for (  final Field field : fieldsWithInject) {
    if (!field.isAccessible()) {
      AccessController.doPrivileged(new PrivilegedAction<Void>(){
        public Void run(){
          field.setAccessible(true);
          return null;
        }
      }
);
    }
    try {
      final Object resolvedVaue;
      final ArquillianContext arquillianContext=this.getArquillianContext();
      final Class<?> type=field.getType();
      if (field.isAnnotationPresent(Properties.class)) {
        final Properties properties=field.getAnnotation(Properties.class);
        resolvedVaue=arquillianContext.get(type,properties);
      }
 else       if (field.isAnnotationPresent(Property.class)) {
        final Property property=field.getAnnotation(Property.class);
        final Properties properties=new PropertiesImpl(new Property[]{property});
        resolvedVaue=arquillianContext.get(type,properties);
      }
 else {
        resolvedVaue=arquillianContext.get(type);
      }
      field.set(testCase,resolvedVaue);
    }
 catch (    final IllegalAccessException e) {
      throw new RuntimeException("Could not inject into " + field.getName() + " of test case: "+ testCase,e);
    }
  }
}
 

Example 17

From project AsmackService, under directory /src/org/apache/harmony/javax/security/auth/login/.

Source file: LoginContext.java

  29 
vote

/** 
 * Warning: calling the method more than once may result in undefined behaviour if logout() method is not invoked before.
 */
public void login() throws LoginException {
  PrivilegedExceptionAction<Void> action=new PrivilegedExceptionAction<Void>(){
    public Void run() throws LoginException {
      loginImpl();
      return null;
    }
  }
;
  try {
    if (userProvidedConfig) {
      AccessController.doPrivileged(action,userContext);
    }
 else {
      AccessController.doPrivileged(action);
    }
  }
 catch (  PrivilegedActionException ex) {
    throw (LoginException)ex.getException();
  }
}
 

Example 18

From project aviator, under directory /src/test/java/com/googlecode/aviator/code/asm/.

Source file: ASMCodeGeneratorUnitTest.java

  29 
vote

@Before public void setUp(){
  final AviatorClassLoader classloader=AccessController.doPrivileged(new PrivilegedAction<AviatorClassLoader>(){
    public AviatorClassLoader run(){
      return new AviatorClassLoader(Thread.currentThread().getContextClassLoader());
    }
  }
);
  this.codeGenerator=new ASMCodeGenerator(classloader,System.out,true);
  this.codeGenerator.start();
}
 

Example 19

From project beanvalidation-api, under directory /src/main/java/javax/validation/.

Source file: Validation.java

  29 
vote

public static List<ValidationProvider<?>> getValidationProviderList(){
  final GetValidationProviderList action=new GetValidationProviderList();
  if (System.getSecurityManager() != null) {
    return AccessController.doPrivileged(action);
  }
 else {
    return action.run();
  }
}
 

Example 20

From project blueprint-namespaces, under directory /blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/.

Source file: AggregateConverter.java

  29 
vote

public boolean canConvert(final Object fromValue,final ReifiedType toType){
  if (fromValue == null) {
    return true;
  }
  if (isAssignable(fromValue,toType)) {
    return true;
  }
  boolean canConvert=false;
  AccessControlContext acc=blueprintContainer.getAccessControlContext();
  if (acc == null) {
    canConvert=canConvertWithConverters(fromValue,toType);
  }
 else {
    canConvert=AccessController.doPrivileged(new PrivilegedAction<Boolean>(){
      public Boolean run(){
        return canConvertWithConverters(fromValue,toType);
      }
    }
,acc);
  }
  if (canConvert) {
    return true;
  }
  try {
    convert(fromValue,toType);
    return true;
  }
 catch (  Exception e) {
    return false;
  }
}
 

Example 21

From project bpm-console, under directory /server/integration/src/main/java/org/jboss/bpm/console/server/util/.

Source file: ServiceLoader.java

  29 
vote

/** 
 * Use the system property
 */
public static Object loadFromSystemProperty(String propertyName,String defaultFactory){
  Object factory=null;
  ClassLoader loader=Thread.currentThread().getContextClassLoader();
  PrivilegedAction action=new PropertyAccessAction(propertyName);
  String factoryName=(String)AccessController.doPrivileged(action);
  if (factoryName != null) {
    try {
      Class factoryClass=loader.loadClass(factoryName);
      factory=factoryClass.newInstance();
    }
 catch (    Throwable t) {
      throw new IllegalStateException("Failed to load " + propertyName + ": "+ factoryName,t);
    }
  }
  if (factory == null && defaultFactory != null) {
    factory=loadDefault(defaultFactory);
  }
  return factory;
}
 

Example 22

From project capedwarf-green, under directory /common/src/main/java/org/jboss/capedwarf/common/serialization/.

Source file: SerializatorFactory.java

  29 
vote

static ClassLoader getClassLoader(final Class<?> clazz){
  SecurityManager sm=System.getSecurityManager();
  if (sm == null)   return clazz.getClassLoader();
 else   return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>(){
    public ClassLoader run(){
      return clazz.getClassLoader();
    }
  }
);
}