1 23 24 package com.sun.enterprise.security.jauth; 25 26 import java.util.ArrayList ; 27 28 import javax.xml.soap.SOAPMessage ; 29 import javax.xml.namespace.QName ; 30 31 import javax.security.auth.callback.CallbackHandler ; 32 33 import com.sun.enterprise.security.jauth.AuthConfig; 34 import com.sun.enterprise.security.jauth.AuthPolicy; 35 import com.sun.enterprise.security.jauth.ClientAuthContext; 36 import com.sun.enterprise.security.jauth.AuthException; 37 38 import com.sun.enterprise.deployment.runtime.common.MessageSecurityDescriptor; 39 import com.sun.enterprise.deployment.runtime.common.MessageSecurityBindingDescriptor; 40 41 import com.sun.xml.rpc.spi.runtime.StreamingHandler; 42 43 import java.util.logging.Logger ; 44 import java.util.logging.Level ; 45 import com.sun.logging.LogDomains; 46 47 53 public class ClientAuthConfig extends BaseAuthConfig { 54 55 private static Logger logger = LogDomains.getLogger(LogDomains.SECURITY_LOGGER); 56 57 private ClientAuthConfig(ClientAuthContext defaultContext) { 58 super(defaultContext); 59 } 60 61 private ClientAuthConfig (ArrayList descriptors, ArrayList authContexts) { 62 super(descriptors,authContexts); 63 } 64 65 public static ClientAuthConfig getConfig 66 (String authLayer, MessageSecurityBindingDescriptor binding, 67 CallbackHandler cbh) throws AuthException { 68 ClientAuthConfig rvalue = null; 69 String provider = null; 70 ArrayList descriptors = null; 71 ClientAuthContext defaultContext = null; 72 if (binding != null) { 73 String layer = binding.getAttributeValue 74 (MessageSecurityBindingDescriptor.AUTH_LAYER); 75 if (authLayer != null && layer.equals(authLayer)) { 76 provider = binding.getAttributeValue 77 (MessageSecurityBindingDescriptor.PROVIDER_ID); 78 descriptors = binding.getMessageSecurityDescriptors(); 79 } 80 } 81 if (descriptors == null || descriptors.size() == 0) { 82 defaultContext = getAuthContext(authLayer,provider,null,null,cbh); 83 if (defaultContext != null) { 84 rvalue = new ClientAuthConfig(defaultContext); 85 } 86 } else { 87 boolean hasPolicy = false; 88 ArrayList authContexts = new ArrayList (); 89 for (int i = 0; i < descriptors.size(); i++) { 90 MessageSecurityDescriptor msd = 91 (MessageSecurityDescriptor) descriptors.get(i); 92 AuthPolicy requestPolicy = 93 getAuthPolicy(msd.getRequestProtectionDescriptor()); 94 AuthPolicy responsePolicy = 95 getAuthPolicy(msd.getResponseProtectionDescriptor()); 96 if (requestPolicy.authRequired()||responsePolicy.authRequired()) { 97 authContexts.add 98 (getAuthContext 99 (authLayer,provider,requestPolicy,responsePolicy,cbh)); 100 hasPolicy = true; 101 } else { 102 authContexts.add(null); 103 } 104 } 105 if (hasPolicy) { 106 rvalue = new ClientAuthConfig(descriptors,authContexts); 107 } 108 } 109 return rvalue; 110 } 111 112 private static ClientAuthContext getAuthContext 113 (String layer, String provider, AuthPolicy requestPolicy, 114 AuthPolicy responsePolicy,CallbackHandler cbh) throws AuthException { 115 AuthConfig authConfig = AuthConfig.getAuthConfig(); 116 return authConfig.getClientAuthContext 117 (layer,provider,requestPolicy,responsePolicy,cbh); 118 } 119 120 public ClientAuthContext 121 getAuthContext(StreamingHandler handler, SOAPMessage message) { 122 return (ClientAuthContext) getContext(handler,message); 123 } 124 125 public ClientAuthContext getAuthContext 126 (javax.xml.ws.handler.soap.SOAPMessageContext context) { 127 return (ClientAuthContext) getContext(context); 128 } 129 130 public ClientAuthContext 131 getAuthContextForOpCode(StreamingHandler handler, int opcode) throws 132 ClassNotFoundException , NoSuchMethodException { 133 return (ClientAuthContext) getContextForOpCode(handler,opcode); 134 } 135 136 } 137 | Popular Tags |