KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > webservice > EjbServletWSSCallbackHandler


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 /*
25  * EjbServletWSSCallbackHandler.java
26  *
27  * Created on September 14, 2004, 12:56 PM
28  */

29
30 package com.sun.enterprise.webservice;
31 import com.sun.enterprise.security.jauth.callback.*;
32 import javax.security.auth.callback.Callback JavaDoc;
33 import javax.security.auth.callback.*;
34 import javax.security.auth.callback.UnsupportedCallbackException JavaDoc;
35 import java.io.IOException JavaDoc;
36 import java.util.logging.*;
37 import com.sun.enterprise.security.wss.*;
38
39 /**
40  * Callback Handler for Servlets/EJB
41  * @author Harpreet Singh
42  */

43 public final class EjbServletWSSCallbackHandler extends WSSCallbackHandler{
44     private static WSSCallbackHandler INSTANCE = null;
45     
46     /** Creates a new instance of EjbServletWSSCallbackHandler */
47     private EjbServletWSSCallbackHandler() {
48     }
49     /**
50      * returns a singleton instance of this class.
51      */

52     static WSSCallbackHandler newInstance() {
53         if(INSTANCE == null){
54             INSTANCE = new EjbServletWSSCallbackHandler();
55         }
56         return INSTANCE;
57     }
58
59     
60     public void handle(Callback JavaDoc[] callbacks)
61         throws IOException JavaDoc, UnsupportedCallbackException JavaDoc
62     {
63         if(callbacks == null){
64             return;
65         }
66         for (int i=0; i<callbacks.length; i++){
67             if(!isSupportedCallback(callbacks[i])){
68                 _logger.log(Level.FINE, "wss-container-auth: UnsupportedCallback : "+
69                     callbacks[i].getClass().getName());
70                 throw new UnsupportedCallbackException JavaDoc(callbacks[i]);
71             }
72             processCallback(callbacks[i]);
73         }
74     }
75     boolean isSupportedCallback(Callback JavaDoc callback) {
76         boolean isSupported = false;
77         if (callback instanceof CertStoreCallback){
78             isSupported = true;
79         } else if(callback instanceof PasswordValidationCallback){
80             isSupported = true;
81         } else if (callback instanceof SecretKeyCallback){
82             isSupported = true;
83         } else if (callback instanceof PrivateKeyCallback){
84             isSupported = true;
85         } else if (callback instanceof TrustStoreCallback){
86             isSupported = true;
87         } else{
88             isSupported = false;
89         }
90         return isSupported;
91     }
92
93 }
94
Popular Tags