Search in sources :

Example 1 with MessageSecurityDescriptor

use of com.sun.enterprise.deployment.runtime.common.MessageSecurityDescriptor in project Payara by payara.

the class AuthMessagePolicy method oneSOAPPolicy.

public static boolean oneSOAPPolicy(MessageSecurityBindingDescriptor binding) {
    boolean onePolicy = true;
    ArrayList msgSecDescs = null;
    if (binding != null) {
        String layer = binding.getAttributeValue(MessageSecurityBindingDescriptor.AUTH_LAYER);
        if (SOAP.equals(layer)) {
            msgSecDescs = binding.getMessageSecurityDescriptors();
        }
    }
    if (msgSecDescs == null) {
        return true;
    }
    for (int i = 0; i < msgSecDescs.size(); i++) {
        MessageSecurityDescriptor msd = (MessageSecurityDescriptor) msgSecDescs.get(i);
        for (int j = 0; j < msgSecDescs.size(); j++) {
            if (j != i && !policiesAreEqual(msd, ((MessageSecurityDescriptor) msgSecDescs.get(j)))) {
                onePolicy = false;
            }
        }
    }
    return onePolicy;
}
Also used : ArrayList(java.util.ArrayList) MessageSecurityDescriptor(com.sun.enterprise.deployment.runtime.common.MessageSecurityDescriptor) WebServiceEndpoint(com.sun.enterprise.deployment.WebServiceEndpoint)

Example 2 with MessageSecurityDescriptor

use of com.sun.enterprise.deployment.runtime.common.MessageSecurityDescriptor in project Payara by payara.

the class ServerAuthConfig method getConfig.

public static ServerAuthConfig getConfig(String authLayer, MessageSecurityBindingDescriptor binding, CallbackHandler cbh) throws AuthException {
    ServerAuthConfig rvalue = null;
    String provider = null;
    ArrayList descriptors = null;
    ServerAuthContext defaultContext = null;
    if (binding != null) {
        String layer = binding.getAttributeValue(MessageSecurityBindingDescriptor.AUTH_LAYER);
        if (authLayer != null && layer.equals(authLayer)) {
            provider = binding.getAttributeValue(MessageSecurityBindingDescriptor.PROVIDER_ID);
            descriptors = binding.getMessageSecurityDescriptors();
        }
    }
    if (descriptors == null || descriptors.size() == 0) {
        defaultContext = getAuthContext(authLayer, provider, null, null, cbh);
        if (defaultContext != null) {
            rvalue = new ServerAuthConfig(defaultContext);
        }
    } else {
        boolean hasPolicy = false;
        ArrayList authContexts = new ArrayList();
        for (int i = 0; i < descriptors.size(); i++) {
            MessageSecurityDescriptor msd = (MessageSecurityDescriptor) descriptors.get(i);
            AuthPolicy requestPolicy = getAuthPolicy(msd.getRequestProtectionDescriptor());
            AuthPolicy responsePolicy = getAuthPolicy(msd.getResponseProtectionDescriptor());
            if (requestPolicy.authRequired() || responsePolicy.authRequired()) {
                authContexts.add(getAuthContext(authLayer, provider, requestPolicy, responsePolicy, cbh));
                hasPolicy = true;
            } else {
                authContexts.add(null);
            }
        }
        if (hasPolicy) {
            rvalue = new ServerAuthConfig(descriptors, authContexts);
        }
    }
    return rvalue;
}
Also used : ArrayList(java.util.ArrayList) MessageSecurityDescriptor(com.sun.enterprise.deployment.runtime.common.MessageSecurityDescriptor)

Example 3 with MessageSecurityDescriptor

use of com.sun.enterprise.deployment.runtime.common.MessageSecurityDescriptor in project Payara by payara.

the class AuthMessagePolicy method getSOAPPolicies.

public static MessagePolicy[] getSOAPPolicies(MessageSecurityBindingDescriptor binding, String operation, boolean onePolicy) {
    MessagePolicy requestPolicy = null;
    MessagePolicy responsePolicy = null;
    if (binding != null) {
        ArrayList<MessageSecurityDescriptor> msgSecDescs = null;
        String layer = binding.getAttributeValue(MessageSecurityBindingDescriptor.AUTH_LAYER);
        if (SOAP.equals(layer)) {
            msgSecDescs = binding.getMessageSecurityDescriptors();
        }
        if (msgSecDescs != null) {
            if (onePolicy) {
                if (msgSecDescs.size() > 0) {
                    MessageSecurityDescriptor msd = msgSecDescs.get(0);
                    requestPolicy = getMessagePolicy(msd.getRequestProtectionDescriptor());
                    responsePolicy = getMessagePolicy(msd.getResponseProtectionDescriptor());
                }
            } else {
                // try to match
                MessageSecurityDescriptor matchMsd = null;
                for (int i = 0; i < msgSecDescs.size(); i++) {
                    MessageSecurityDescriptor msd = msgSecDescs.get(i);
                    ArrayList msgDescs = msd.getMessageDescriptors();
                    for (int j = i + 1; j < msgDescs.size(); j++) {
                        // XXX don't know how to get JavaMethod from operation
                        MessageDescriptor msgDesc = (MessageDescriptor) msgDescs.get(j);
                        String opName = msgDesc.getOperationName();
                        if ((opName == null && matchMsd == null)) {
                            matchMsd = msd;
                        } else if (opName != null && opName.equals(operation)) {
                            matchMsd = msd;
                            break;
                        }
                    }
                    if (matchMsd != null) {
                        requestPolicy = getMessagePolicy(matchMsd.getRequestProtectionDescriptor());
                        responsePolicy = getMessagePolicy(matchMsd.getResponseProtectionDescriptor());
                    }
                }
            }
        }
    }
    return new MessagePolicy[] { requestPolicy, responsePolicy };
}
Also used : MessageDescriptor(com.sun.enterprise.deployment.runtime.common.MessageDescriptor) MessagePolicy(javax.security.auth.message.MessagePolicy) ArrayList(java.util.ArrayList) MessageSecurityDescriptor(com.sun.enterprise.deployment.runtime.common.MessageSecurityDescriptor) WebServiceEndpoint(com.sun.enterprise.deployment.WebServiceEndpoint)

Example 4 with MessageSecurityDescriptor

use of com.sun.enterprise.deployment.runtime.common.MessageSecurityDescriptor in project Payara by payara.

the class BaseAuthConfig method getContextForOpName.

private Object getContextForOpName(String operation) {
    synchronized (contextLock) {
        if (contextsForOpNames_ == null) {
            // one time initialization of the opName to authContext array.
            contextsForOpNames_ = new HashMap();
            for (int i = 0; messageSecurityDescriptors_ != null && i < messageSecurityDescriptors_.size(); i++) {
                MessageSecurityDescriptor mSD = (MessageSecurityDescriptor) messageSecurityDescriptors_.get(i);
                ArrayList mDs = mSD.getMessageDescriptors();
                for (int j = 0; mDs != null && j < mDs.size(); j++) {
                    MessageDescriptor mD = (MessageDescriptor) mDs.get(j);
                    String opName = mD.getOperationName();
                    if (opName != null) {
                        if (contextsForOpNames_.containsKey(opName)) {
                            Integer k = (Integer) contextsForOpNames_.get(opName);
                            if (k != null) {
                                MessageSecurityDescriptor other = (MessageSecurityDescriptor) messageSecurityDescriptors_.get(k.intValue());
                                if (!policiesAreEqual(mSD, other)) {
                                    contextsForOpNames_.put(opName, null);
                                }
                            }
                        } else if (superMSD_ != null && !policiesAreEqual(mSD, superMSD_)) {
                            // set to null if operation policy differs from superPolicy
                            contextsForOpNames_.put(opName, null);
                        } else {
                            contextsForOpNames_.put(opName, Integer.valueOf(i));
                        }
                    }
                }
            }
        }
    }
    Object rvalue = null;
    if (operation != null) {
        if (contextsForOpNames_.containsKey(operation)) {
            Integer k = (Integer) contextsForOpNames_.get(operation);
            if (k != null) {
                rvalue = contexts_.get(k.intValue());
            }
        } else if (superIndex_ >= 0) {
            // if there is a msb that matches all methods, use the
            // associatedContext
            rvalue = contexts_.get(superIndex_);
        }
        if (rvalue == null) {
            // else return explicitNull under the assumption
            // that methodName was known, and no match was found
            rvalue = explicitNull;
        }
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, "WSS: ForOpName={0} context: {1}", new Object[] { operation, rvalue });
        }
    }
    return rvalue;
}
Also used : MessageDescriptor(com.sun.enterprise.deployment.runtime.common.MessageDescriptor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MessageSecurityDescriptor(com.sun.enterprise.deployment.runtime.common.MessageSecurityDescriptor)

Example 5 with MessageSecurityDescriptor

use of com.sun.enterprise.deployment.runtime.common.MessageSecurityDescriptor in project Payara by payara.

the class ClientAuthConfig method getConfig.

public static ClientAuthConfig getConfig(String authLayer, MessageSecurityBindingDescriptor binding, CallbackHandler cbh) throws AuthException {
    ClientAuthConfig rvalue = null;
    String provider = null;
    ArrayList descriptors = null;
    ClientAuthContext defaultContext = null;
    if (binding != null) {
        String layer = binding.getAttributeValue(MessageSecurityBindingDescriptor.AUTH_LAYER);
        if (authLayer != null && layer.equals(authLayer)) {
            provider = binding.getAttributeValue(MessageSecurityBindingDescriptor.PROVIDER_ID);
            descriptors = binding.getMessageSecurityDescriptors();
        }
    }
    if (descriptors == null || descriptors.size() == 0) {
        defaultContext = getAuthContext(authLayer, provider, null, null, cbh);
        if (defaultContext != null) {
            rvalue = new ClientAuthConfig(defaultContext);
        }
    } else {
        boolean hasPolicy = false;
        ArrayList authContexts = new ArrayList();
        for (int i = 0; i < descriptors.size(); i++) {
            MessageSecurityDescriptor msd = (MessageSecurityDescriptor) descriptors.get(i);
            AuthPolicy requestPolicy = getAuthPolicy(msd.getRequestProtectionDescriptor());
            AuthPolicy responsePolicy = getAuthPolicy(msd.getResponseProtectionDescriptor());
            if (requestPolicy.authRequired() || responsePolicy.authRequired()) {
                authContexts.add(getAuthContext(authLayer, provider, requestPolicy, responsePolicy, cbh));
                hasPolicy = true;
            } else {
                authContexts.add(null);
            }
        }
        if (hasPolicy) {
            rvalue = new ClientAuthConfig(descriptors, authContexts);
        }
    }
    return rvalue;
}
Also used : ArrayList(java.util.ArrayList) MessageSecurityDescriptor(com.sun.enterprise.deployment.runtime.common.MessageSecurityDescriptor)

Aggregations

MessageSecurityDescriptor (com.sun.enterprise.deployment.runtime.common.MessageSecurityDescriptor)6 ArrayList (java.util.ArrayList)6 WebServiceEndpoint (com.sun.enterprise.deployment.WebServiceEndpoint)2 MessageDescriptor (com.sun.enterprise.deployment.runtime.common.MessageDescriptor)2 XMLElement (com.sun.enterprise.deployment.node.XMLElement)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 MessagePolicy (javax.security.auth.message.MessagePolicy)1 Element (org.w3c.dom.Element)1