package com.foreverwin.mesnac.listener.listener;

import com.sap.security.api.PrincipalListener;
import com.sap.security.api.UMFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component;

@Component
public class StopListener implements ApplicationListener<ContextClosedEvent> {

    @Autowired
    NwaUserListener nwaUserListener;
    @Autowired
    PrincipalListener principalListener;

    @Override
    public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
        try {
            UMFactory.getUserFactory().unregisterListener(nwaUserListener);
            UMFactory.getPrincipalFactory().unregisterListener(principalListener);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
