@@ -0,0 +1,2345 @@
+/*%0A * Copyright 2020 Red Hat, Inc.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *   http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage org.wildfly.security.authz.jacc;%0A%0Aimport static org.wildfly.security.authz.jacc.SecurityActions.doPrivileged;%0Aimport static org.wildfly.security.authz.jacc.SubjectUtil.fromSecurityIdentity;%0A%0Aimport java.security.PrivilegedAction;%0A%0Aimport javax.security.jacc.PolicyContextException;%0Aimport javax.security.jacc.PolicyContextHandler;%0A%0Aimport org.wildfly.security.auth.server.SecurityDomain;%0Aimport org.wildfly.security.auth.server.SecurityIdentity;%0A%0A/**%0A * A %7B@code PolicyContextHandler%7D to return a %7B@code Subject%7D from the current %7B@code SecurityIdentity%7D.%0A *%0A * @author %3Ca href=%22mailto:darran.lofthouse@jboss.com%22%3EDarran Lofthouse%3C/a%3E%0A */%0Apublic class SubjectPolicyContextHandler implements PolicyContextHandler %7B%0A%0A    private static final String KEY = %22javax.security.auth.Subject.container%22;%0A%0A    @Override%0A    public boolean supports(String key) throws PolicyContextException %7B%0A        return KEY.equalsIgnoreCase(key);%0A    %7D%0A%0A    @Override%0A    public String%5B%5D getKeys() throws PolicyContextException %7B%0A        return new String%5B%5D %7B KEY %7D;%0A    %7D%0A%0A    @Override%0A    public Object getContext(String key, Object data) throws PolicyContextException %7B%0A        if (!supports(key)) %7B%0A            return null;%0A        %7D%0A%0A        SecurityIdentity securityIdentity = getSecurityIdentity();%0A        if (securityIdentity != null) %7B%0A            return fromSecurityIdentity(securityIdentity);%0A        %7D%0A%0A        return null;%0A    %7D%0A%0A    private static SecurityIdentity getSecurityIdentity() %7B%0A        SecurityDomain securityDomain = doPrivileged((PrivilegedAction%3CSecurityDomain%3E) SecurityDomain::getCurrent);%0A%0A        if (securityDomain != null) %7B%0A            return securityDomain.getCurrentSecurityIdentity();%0A        %7D%0A%0A        return null;%0A    %7D%0A%7D%0A

Add a new SubjectPolicyContextHandler to return a Subject based on the current SecurityIdentity.