Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * JBoss, Home of Professional Open Source
  * Copyright 2014, Red Hat, Inc., and individual contributors
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
package org.jboss.weld.bean.proxy;
Holds enhanced protection domains for proxy classes. This is only useful when running under security manager. The enhanced protection domain contains all the permissions of the original class plus the "accessDeclaredMembers" runtime permission. This is needed for the proxy class' static initializer block to be able to resolve methods using java.lang.Class.getDeclaredMethod(java.lang.String,java.lang.Class[]).

Jozef Hartinger
See also:
    private static final Permission ACCESS_DECLARED_MEMBERS_PERMISSION = new RuntimePermission("accessDeclaredMembers");
Gets an enhanced protection domain for a proxy based on the given protection domain.

domain the given protection domain
protection domain enhanced with "accessDeclaredMembers" runtime permission
        if (domain.getCodeSource() == null) {
            // no codesource to cache on
            return create(domain);
        ProtectionDomain proxyProtectionDomain = .get(domain.getCodeSource());
        if (proxyProtectionDomain == null) {
            // as this is not atomic create() may be called multiple times for the same domain
            // we ignore that
            proxyProtectionDomain = create(domain);
            ProtectionDomain existing = .putIfAbsent(domain.getCodeSource(), proxyProtectionDomain);
            if (existing != null) {
                proxyProtectionDomain = existing;
        return proxyProtectionDomain;
    private ProtectionDomain create(ProtectionDomain domain) {
        if (domain.implies()) {
            return domain;
        Enumeration<Permissionpermissions = domain.getPermissions().elements();
        PermissionCollection proxyPermissions = new Permissions();
        while (permissions.hasMoreElements()) {
        return new ProtectionDomain(domain.getCodeSource(), proxyPermissions);
    public void cleanupAfterBoot() {
New to GrepCode? Check out our FAQ X