FileDocCategorySizeDatePackage
ConfigInterceptor.javaAPI DocGlassfish v2 API15153Fri May 04 22:33:46 BST 2007com.sun.enterprise.admin.server.core

ConfigInterceptor

public class ConfigInterceptor extends com.sun.enterprise.admin.util.proxy.InterceptorImpl
Config interceptor for MBeans

Fields Summary
private com.sun.enterprise.admin.AdminContext
adminContext
private Logger
_logger
private static com.sun.enterprise.security.audit.AuditManager
auditManager
Constructors Summary
public ConfigInterceptor()


      
    
public ConfigInterceptor(com.sun.enterprise.admin.AdminContext ctx)

        adminContext = ctx;
        if (adminContext != null) {
            _logger = adminContext.getAdminLogger();
        } else {
            _logger = Logger.getLogger("global");
        }
    
Methods Summary
private voidauditInvocation(com.sun.enterprise.admin.util.proxy.Call call)

        if(auditManager.isAuditOn())
        {
            if (/*auditManager.isAuditOn() &&*/ isAuditable(call)){
                SecurityContext sc = SecurityContext.getCurrent();
//XXX remove audit API
/*
                auditManager.adminInvocation(
                    sc.getCallerPrincipal().getName(), //caller
                    sc.getSubject(), //subject
                    auditManager.getRemoteHost(), // host
                    getObjectNameForCall(call),//ObjectName
                    getOperationName(call), //operation name
                    "JMXLocal",  //mode JMXLocal,JMXRemote-http,JMXRemote-rmi,JMXRemote-jmxmp
                    getAuditedParamsString(call),
                    call.getState().isSuccess());
*/
/*
System.out.println(
"\nCaller: "+sc.getCallerPrincipal().getName() +
"\nSubject: "+ sc.getSubject() +
"\nHost: "+ auditManager.getRemoteHost() +
"\nObjectName: "+  getObjectNameForCall(call)+
"\nOperation: "+  getOperationName(call)+
"\nParams: "+  getAuditedParamsString(call)+
"\nSuccess: "+  call.getState().isSuccess() );
*/            
            }
        }
    
private java.lang.StringgetAuditedParamsString(com.sun.enterprise.admin.util.proxy.Call call)
represents parameters of call in printable form fro audit module

        if(call==null)
            return null;
        Object[] params = call.getArguments();
        if(params==null)
            return null;
        int i=0;
        String methodName = call.getMethod().getName();
        if(methodName.equals("invoke"))
        {
            if(params.length>2)
                return paramToString(params[2]);
        }
        else
            if(methodName.equals("setAttribute") ||
                methodName.equals("setAttributes") )
            {
                if(params.length>1)
                    return paramToString(params[1]);
            }
        return null;
    
private java.lang.StringgetObjectNameForCall(com.sun.enterprise.admin.util.proxy.Call call)
returns ObjectName of invoking MBean

        if(call==null)
            return null;
        Object[] params = call.getArguments();
        if( params==null || 
            params.length<1 ||
            !(params[0] instanceof ObjectName))
            return null;
        return params[0].toString();
    
private java.lang.StringgetOperationName(com.sun.enterprise.admin.util.proxy.Call call)
returns OperationName invoking in MBean

        if(call==null)
            return null;
        String methodName = call.getMethod().getName();
        if(methodName.equals("invoke"))
        {
            Object[] params = call.getArguments();
            if(params!=null && params.length>1 && (params[1] instanceof String))
                methodName = (String)params[1];
        }
        return methodName;
    
private booleanisAuditable(com.sun.enterprise.admin.util.proxy.Call call)
check call using method name/params/objectname - whether it auditable or not

        if(call==null)
            return false;
        String methodName = call.getMethod().getName();
        if( !methodName.equals("setAttribute")  &&
            !methodName.equals("setAttributes") &&
            !methodName.equals("invoke")) 
                return false;
        if(methodName.equals("invoke"))
        {
            String opName = getOperationName(call);
            if(opName==null ||
               opName.startsWith("get") ||
               opName.startsWith("list") ||
               opName.startsWith("is") )
                return false;
        }
        String objectName = getObjectNameForCall(call);
        if(objectName==null || objectName.indexOf("category=config")<0)
            return false;
        return true;
    
private booleanisFlushNeeded(com.sun.enterprise.admin.util.proxy.Call call)
Flush is needed only for those methods that change configcontext. These are setAttribute(s) and invoke

        String methodName = call.getMethod().getName();
        if( methodName.equals("setAttribute") ||
            methodName.equals("setAttributes") ||
            (methodName.equals("invoke") && !isReadonlyInvokeOperation(call))) {
                return true;
        }
        return false;
    
private booleanisReadonlyInvokeOperation(com.sun.enterprise.admin.util.proxy.Call call)


        try {
            Object[] args = call.getArguments();
            if(args!=null && args.length>1)
            {
                String operationName = (String) (args[1]);

                // skips notification if this is a ping for deployment status
                if("takeNotifications".equals(operationName)) {
                    return true;
                }
            }
        } catch(Throwable t){ }

        return false;
    
private java.lang.StringparamToString(java.lang.Object obj)
represents parameter of call in printable form fro audit module

        if(obj==null)
            return null;
        String res = null;
        if(obj instanceof Object[])
        {
            res = "{";
            for(int i=0; i<((Object[])obj).length; i++)
                res += paramToString(((Object[])obj)[i]) + ";";
            res += "}";
        }
        else if(obj instanceof ArrayList)
        {
            res = "{";
            for(int i=0; i<((ArrayList)obj).size(); i++)
                res += paramToString(((ArrayList)obj).get(i)) + ";";
            res += "}";
        }
        else if(obj instanceof Properties)
        {
            res = "{";
            Enumeration keys = ((Properties)obj).keys();
            while (keys.hasMoreElements())
            {
                final String key = (String)keys.nextElement();
                res += key + "=" + ((Properties)obj).get(key) + ";";
            }
            res += "}";
        }
        else if(obj instanceof Attribute)
        {
            res = ""+((Attribute)obj).getName()+"="+((Attribute)obj).getValue();
        }
        else if(obj instanceof String ||
                obj instanceof Number ||
                obj instanceof ObjectName )
        {
            res = obj.toString();
        }
        else
            res = "<?>";
        return res;
    
public voidpostInvoke(com.sun.enterprise.admin.util.proxy.CallStack callStack)
We flush configcontext only in the last return of setAttribute, setAttributes or invoke. Send notification if flush is successfull Failure cases will be handled later


        
        if (callStack.getStackSize() == 1) {
            Call call = callStack.getActiveCall();
            if (call.getState().isSuccess() && isFlushNeeded(call)) {
                try {
                    ConfigContext ctx = adminContext.getAdminConfigContext();
                    if (ctx.isChanged()) {
                        ctx.flush();
                    }
                } catch (ConfigException ce) {
                    _logger.log(Level.WARNING,
                        "core.config_exception_occurred", ce);
                }
            }
            if (isFlushNeeded(call)) {
                new AdminNotificationHelper(adminContext).sendNotification();
            }
        } 
        auditInvocation(callStack.getActiveCall());

        
    
public voidpreInvoke(com.sun.enterprise.admin.util.proxy.CallStack callstack)


        if (callstack.getStackSize() == 1) {
            EventStack stack = new EventStack();
            stack.setConfigContext(adminContext.getAdminConfigContext());
            EventContext.setEventStackToThreadLocal(stack);
        }