KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > wsmgmt > agent > AuthenticationListenerImpl


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  * AuthenticationListenerImpl.java
26  */

27
28 package com.sun.enterprise.admin.wsmgmt.agent;
29
30 import java.security.Principal JavaDoc;
31 import com.sun.enterprise.webservice.monitoring.AuthenticationListener;
32 import com.sun.enterprise.webservice.monitoring.WebServiceEngine;
33 import com.sun.enterprise.webservice.monitoring.WebServiceEngineFactory;
34 import com.sun.enterprise.webservice.monitoring.Endpoint;
35 import com.sun.enterprise.deployment.BundleDescriptor;
36 import com.sun.enterprise.admin.wsmgmt.WebServiceMgrBackEnd;
37 import com.sun.enterprise.admin.wsmgmt.stats.spi.StatsProviderManager;
38 import com.sun.enterprise.admin.wsmgmt.config.spi.ConfigProvider;
39 import com.sun.enterprise.admin.wsmgmt.config.spi.ConfigFactory;
40 import com.sun.enterprise.admin.wsmgmt.config.spi.WebServiceConfig;
41 import com.sun.enterprise.admin.wsmgmt.stats.impl.WebServiceEndpointStatsProviderImpl;
42
43 import java.util.logging.Logger JavaDoc;
44 import java.util.logging.Level JavaDoc;
45 import com.sun.logging.LogDomains;
46 import com.sun.enterprise.util.i18n.StringManager;
47
48 /**
49  * This interface allows to register interest in authentication events
50  * in the web service container.
51  *
52  * @author Satish Viswanatham
53  */

54 public class AuthenticationListenerImpl implements AuthenticationListener {
55     
56     public AuthenticationListenerImpl() {
57         try {
58             cfgProv = ConfigFactory.getConfigFactory().getConfigProvider();
59         } catch (Exception JavaDoc e) {
60             _logger.fine("Config provider could not be initialized " +
61                 e.getMessage());
62         }
63      }
64
65     /**
66      * notification that a user properly authenticated while making
67      * a web service invocation.
68      */

69     public void authSucess(BundleDescriptor desc, Endpoint ep, Principal JavaDoc principal) {
70         // all the data is collected by Message listener for the success case
71
}
72     
73     /**
74      * notification that a user authentication attempt has failed.
75      * @param endpointSelector the endpoint selector
76      * @param principal Optional principal that failed
77      */

78     public void authFailure(BundleDescriptor desc, Endpoint ep, Principal JavaDoc principal) {
79         if (ep == null) {
80             _logger.fine("Endpoint is null for " + desc.getModuleID());
81             return;
82         }
83         // get the endpoint's fully qualified name
84
String JavaDoc fqn =WebServiceMgrBackEnd.getManager().getFullyQualifiedName(ep);
85         if (fqn == null) {
86             _logger.fine("Fully Qualified could not be computed for the selector " +
87             ep.getEndpointSelector());
88             return;
89         }
90         WebServiceConfig wsc = cfgProv.getWebServiceConfig(fqn);
91         if ((wsc == null) || (wsc.getMonitoringLevel() == null)
92                 || (wsc.getMonitoringLevel().equals("OFF"))) {
93             // in this case, there wont be any stats
94
_logger.fine("Monitoring is OFF for webservice endpoint " +
95                 fqn);
96             return;
97         }
98         // get its corresponding stats provider
99
WebServiceEndpointStatsProviderImpl impl = (
100              WebServiceEndpointStatsProviderImpl) StatsProviderManager.
101              getInstance().getEndpointStatsProvider(fqn);
102         if (impl == null) {
103             if (cfgProv != null) {
104                 String JavaDoc msg = _stringMgr.getString("Auth.StatsNotReg", fqn);
105                 throw new RuntimeException JavaDoc(msg);
106             }
107          return;
108         }
109         // set auth failure time stamp
110
impl.setAuthFailure(System.currentTimeMillis());
111     }
112
113     /** PRIVATE VARIABLES */
114     private static final Logger JavaDoc _logger =
115           Logger.getLogger(LogDomains.ADMIN_LOGGER);
116     private ConfigProvider cfgProv = null;
117     private static final StringManager _stringMgr =
118             StringManager.getManager(AuthenticationListenerImpl.class);
119 }
120
Popular Tags