KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > webservice > monitoring > LogAuthenticationListener


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 package com.sun.enterprise.webservice.monitoring;
26
27 import java.security.Principal JavaDoc;
28 import java.util.logging.Logger JavaDoc;
29 import java.util.logging.Level JavaDoc;
30 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
31
32 import com.sun.logging.LogDomains;
33 import com.sun.enterprise.deployment.BundleDescriptor;
34
35 /**
36  * Log all authentication successes and failures.
37  *
38  * @author Jerome Dochez
39  */

40 public class LogAuthenticationListener implements AuthenticationListener {
41     
42     private static Logger JavaDoc ejbLogger
43         = LogDomains.getLogger(LogDomains.EJB_LOGGER);
44     private static Logger JavaDoc webLogger
45         = LogDomains.getLogger(LogDomains.WEB_LOGGER);
46     
47     
48     /** Creates a new instance of LogAuthenticationListener */
49     public LogAuthenticationListener() {
50     }
51     
52     /**
53      * notification that a user properly authenticated while making
54      * a web service invocation.
55      */

56     public void authSucess(BundleDescriptor bundleDesc, Endpoint endpoint, Principal JavaDoc principal) {
57         if (ModuleType.EJB.equals(bundleDesc.getModuleType())) {
58             if (ejbLogger.isLoggable(Level.FINER)) {
59                 ejbLogger.finer("LOG LISTENER : authentication succeeded for "
60                         + endpoint.getEndpointSelector());
61             }
62         } else {
63             if (webLogger.isLoggable(Level.FINER)) {
64                 webLogger.finer("authentication succeeded for endpoint in " +
65                         bundleDesc.getModuleID() + " web app");
66             }
67         }
68     }
69     
70     /**
71      * notification that a user authentication attempt has failed.
72      * @param endpointSelector the endpoint selector
73      * @param principal Optional principal that failed
74      */

75     public void authFailure(BundleDescriptor bundleDesc, Endpoint endpoint, Principal JavaDoc principal) {
76         if (ModuleType.EJB.equals(bundleDesc.getModuleType())) {
77             if (ejbLogger.isLoggable(Level.FINE)) {
78                 ejbLogger.fine("authentication failure for "
79                         + endpoint.getEndpointSelector());
80             }
81         } else {
82             if (webLogger.isLoggable(Level.FINE)) {
83                 webLogger.fine("authentication failure for endpoint in " +
84                         bundleDesc.getModuleID() + " web app");
85             }
86         }
87     }
88 }
89
Popular Tags