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.ServerAuthContext; 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 ServerAuthConfig extends BaseAuthConfig { 54 55 private static Logger logger = LogDomains.getLogger(LogDomains.SECURITY_LOGGER); 56 57 private ServerAuthConfig(ServerAuthContext defaultContext) { 58 super(defaultContext); 59 } 60 61 private ServerAuthConfig (ArrayList descriptors, ArrayList authContexts) { 62 super(descriptors,authContexts); 63 } 64 65 public static ServerAuthConfig getConfig 66 (String authLayer, MessageSecurityBindingDescriptor binding, 67 CallbackHandler cbh) throws AuthException { 68 ServerAuthConfig rvalue = null; 69 String provider = null; 70 ArrayList descriptors = null; 71 ServerAuthContext 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 ServerAuthConfig(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 ServerAuthConfig(descriptors,authContexts); 107 } 108 } 109 return rvalue; 110 } 111 112 private static ServerAuthContext getAuthContext 113 (String layer, String provider, AuthPolicy requestPolicy, 114 AuthPolicy responsePolicy,CallbackHandler cbh) throws AuthException { 115 AuthConfig authConfig = AuthConfig.getAuthConfig(); 116 return authConfig.getServerAuthContext 117 (layer,provider,requestPolicy,responsePolicy,cbh); 118 } 119 120 public ServerAuthContext 121 getAuthContext(StreamingHandler handler, SOAPMessage message) { 122 return (ServerAuthContext) getContext(handler,message); 123 } 124 125 public ServerAuthContext getAuthContext 126 (javax.xml.ws.handler.soap.SOAPMessageContext context) { 127 return (ServerAuthContext) getContext(context); 128 } 129 130 public ServerAuthContext 131 getAuthContextForOpCode(StreamingHandler handler, int opcode) throws 132 ClassNotFoundException , NoSuchMethodException { 133 return (ServerAuthContext) getContextForOpCode(handler,opcode); 134 } 135 136 } 137 | Popular Tags |