KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > security > jauth > ClientAuthConfig


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.security.jauth;
25
26 import java.util.ArrayList JavaDoc;
27
28 import javax.xml.soap.SOAPMessage JavaDoc;
29 import javax.xml.namespace.QName JavaDoc;
30
31 import javax.security.auth.callback.CallbackHandler JavaDoc;
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 JavaDoc;
44 import java.util.logging.Level JavaDoc;
45 import com.sun.logging.LogDomains;
46
47 /**
48  * This class is the client container's interface to the AuthConfig subsystem
49  * to get AuthContext objects on which to invoke message layer authentication
50  * providers. It is not intended to be layer or web services specific (see
51  * getMechanisms method at end).
52  */

53 public class ClientAuthConfig extends BaseAuthConfig {
54
55     private static Logger JavaDoc logger = LogDomains.getLogger(LogDomains.SECURITY_LOGGER);
56
57     private ClientAuthConfig(ClientAuthContext defaultContext) {
58     super(defaultContext);
59     }
60
61     private ClientAuthConfig (ArrayList JavaDoc descriptors, ArrayList JavaDoc authContexts) {
62     super(descriptors,authContexts);
63     }
64
65     public static ClientAuthConfig getConfig
66     (String JavaDoc authLayer, MessageSecurityBindingDescriptor binding,
67      CallbackHandler JavaDoc cbh) throws AuthException {
68     ClientAuthConfig rvalue = null;
69     String JavaDoc provider = null;
70     ArrayList JavaDoc descriptors = null;
71     ClientAuthContext defaultContext = null;
72     if (binding != null) {
73         String JavaDoc 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 JavaDoc authContexts = new ArrayList JavaDoc();
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 JavaDoc layer, String JavaDoc provider, AuthPolicy requestPolicy,
114      AuthPolicy responsePolicy,CallbackHandler JavaDoc 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 JavaDoc 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 JavaDoc, NoSuchMethodException JavaDoc {
133     return (ClientAuthContext) getContextForOpCode(handler,opcode);
134     }
135
136 }
137
Popular Tags