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.audit; 25 26 import com.sun.enterprise.config.ConfigContext; 27 import com.sun.enterprise.config.ConfigException; 28 import com.sun.enterprise.config.serverbeans.SecurityService; 29 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 30 import com.sun.enterprise.admin.event.AdminEventListenerException; 31 import com.sun.enterprise.admin.event.SecurityServiceEvent; 32 import com.sun.enterprise.admin.event.SecurityServiceEventListener; 33 34 35 /** 36 * Listener interface to handle security service events. 37 * In this moment, only audit-enabled flag can be updated dynamically. 38 * @author Shing Wai Chan 39 */ 40 public class SecurityServiceEventListenerImpl implements SecurityServiceEventListener { 41 42 /** 43 * New security service element created. 44 * It is called whenever a SecurityServiceEvent with action of 45 * SecurityServiceEvent.ACTION_CREATE is received. 46 * @throws AdminEventListenerException when the listener is unable to 47 * process the event. 48 */ 49 public void securityServiceCreated(SecurityServiceEvent event) 50 throws AdminEventListenerException { 51 } 52 53 /** 54 * security service deleted. 55 * It is called whenever a SecurityServiceEvent with action of 56 * SecurityServiceEvent.ACTION_DELETE is received. 57 * @throws AdminEventListenerException when the listener is unable to 58 * process the event. 59 */ 60 public void securityServiceDeleted(SecurityServiceEvent event) 61 throws AdminEventListenerException { 62 } 63 64 /** 65 * security service element updated (attributes change). 66 * It is called whenever a SecurityServiceEvent with action of 67 * SecurityServiceEvent.ACTION_UPDATE is received. 68 * @throws AdminEventListenerException when the listener is unable to 69 * process the event. 70 */ 71 public void securityServiceUpdated(SecurityServiceEvent event) 72 throws AdminEventListenerException { 73 try { 74 SecurityService securityBean = 75 ServerBeansFactory.getSecurityServiceBean( 76 event.getConfigContext()); 77 boolean auditFlag = securityBean.isAuditEnabled(); 78 79 SecurityService oldSecurityBean = 80 ServerBeansFactory.getSecurityServiceBean( 81 event.getOldConfigContext()); 82 83 boolean oldAuditFlag = oldSecurityBean.isAuditEnabled(); 84 85 if (auditFlag != oldAuditFlag) { 86 AuditManagerFactory.getInstance().getAuditManagerInstance().setAuditOn(auditFlag); 87 } 88 } catch(Exception ex) { 89 throw new AdminEventListenerException(ex); 90 } 91 } 92 93 } 94