Exemple #1
0
 public Session getSession()
 {
     session = Session.getSession(this, session);
     if (session == null || !session.isValid())
     {
         lock (this)
         {
             session = Session.getSession(this, session);
             if (session == null || !session.isValid())                     //need re-auth ?
             {
                 session = Auth.login(
                     Bootstrap.getAppRealm(),
                     auth.indexType.moduleInstance, "Application",
                     new Callback[] {
                     new NameCallback(Bootstrap.getAppUser()),
                     new PasswordCallback(Bootstrap.getAppPassword())
                 }
                     );
                 naming        = Naming.Get(new naming.Request(session));
                 reread_config = true;                        //clear config
                 config        = GetConfig();
             }
         }
     }
     return(session);
 }
Exemple #2
0
        public Session getSession()
        {
            Session session = Session.getSession(this, sessionId);

            if (session == null || !session.isValid())
            {
                lock (this)
                {
                    session = Session.getSession(this, sessionId);
                    if (session == null || !session.isValid())                     //need re-auth ?
                    {
                        session = Auth.login(
                            Bootstrap.getAppRealm(),
                            auth.indexType.moduleInstance, "Application",
                            new Callback[] {
                            new NameCallback(Bootstrap.getAppUser()),
                            new PasswordCallback(Bootstrap.getAppPassword())
                        }
                            );
                        sessionId = session.sessionId;
                        naming    = null;                     //clear naming
                        config    = null;                     //clear config
                    }
                }
            }
            return(session);
        }
Exemple #3
0
        public static void Init()
        {
            var config = LogManager.Configuration ?? new LoggingConfiguration();

            var debugRule = config.LoggingRules.FirstOrDefault(l => l.LoggerNamePattern == DEBUG_LOGGER);
            var auditRule = config.LoggingRules.FirstOrDefault(l => l.LoggerNamePattern == AUDIT_LOGGER);

            if (debugRule != null && auditRule != null && !_noConfig)
            {
                _debugLogger = LogManager.GetLogger(DEBUG_LOGGER);
                _auditLogger = LogManager.GetLogger(AUDIT_LOGGER);
                return;
            }

            _noConfig = true;

            EventLogTarget syslog = new EventLogTarget();

            syslog.Source = Bootstrap.getAppUser();
            syslog.Name   = "EventLog";
            //syslog.Category = 0;
            //syslog.EntryType = "";
            //syslog.EventId = "";
            syslog.Layout = "${message}${newline}${exception:format=ToString}";

            FileTarget            fileTarget         = new FileTarget();
            RetryingTargetWrapper retryTargetWrapper = new RetryingTargetWrapper(fileTarget, 3, 100);
            AsyncTargetWrapper    asyncTargetWrapper = new AsyncTargetWrapper(retryTargetWrapper);

            config.AddTarget("async", asyncTargetWrapper);

            fileTarget.Layout = @"${longdate} ${level} ${message}";
            var    agentConfig = Agent.Instance.HasConfig() ? Agent.Instance.GetSingle("com.sun.identity.agents.config.local.log.path") : null;
            String prefix      = ConfigurationManager.AppSettings["com.sun.identity.agents.config.local.log.path"] != null ? ConfigurationManager.AppSettings["com.sun.identity.agents.config.local.log.path"] : agentConfig;

            fileTarget.FileName = (String.IsNullOrWhiteSpace(prefix)?"${basedir}/App_Data/Logs":prefix) + "/${logger}/${date:format=yyyy-MM-dd}.log";
            fileTarget.Encoding = Encoding.UTF8;

            LogLevel nlogLevel = LogLevel.Info;             //default level

            // todo проверить
            //TODO failover FATAL log to WINDOWS SYSTEM LOG
            if (Agent.Instance.HasConfig())
            {
                //logAudit = Agent.Instance.GetSingle("com.sun.identity.agents.config.audit.accesstype") == "LOG_ALLOW";
                auditLevel = Agent.Instance.GetSingle("com.sun.identity.agents.config.audit.accesstype");

                if (Agent.Instance.GetSingle("com.sun.identity.agents.config.local.log.rotate") == "true")
                {
                    long temp;
                    fileTarget.ArchiveAboveSize = 104857600;
                    fileTarget.MaxArchiveFiles  = 9999;
                    fileTarget.ArchiveFileName  = (String.IsNullOrWhiteSpace(prefix) ? "${basedir}/App_Data/Logs" : prefix) + "/${logger}/${date:format=yyyy-MM-dd}_{#}.log";
                    fileTarget.ArchiveNumbering = ArchiveNumberingMode.Sequence;
                    fileTarget.ArchiveEvery     = FileArchivePeriod.Hour;
                    if (long.TryParse(Agent.Instance.GetSingle("com.sun.identity.agents.config.local.log.size"), out temp))
                    {
                        fileTarget.ArchiveAboveSize = temp;
                    }
                }

                var configLevel = Agent.Instance.GetSingle("com.sun.identity.agents.config.debug.level");
                switch (configLevel)
                {
                case "Error":
                    nlogLevel = LogLevel.Error;
                    break;

                case "Warning":
                    nlogLevel = LogLevel.Warn;
                    break;

                case "Info":
                    nlogLevel = LogLevel.Info;
                    break;

                default:
                    nlogLevel = LogLevel.Trace;
                    break;
                }
            }

            lock (_sync){
                var oldRule = config.LoggingRules.FirstOrDefault(l => l.LoggerNamePattern == DEBUG_LOGGER);
                if (oldRule != null)
                {
                    config.LoggingRules.Remove(oldRule);
                }
                var rule = new LoggingRule(DEBUG_LOGGER, nlogLevel, fileTarget);
                config.LoggingRules.Add(rule);

                oldRule = config.LoggingRules.FirstOrDefault(l => l.LoggerNamePattern == AUDIT_LOGGER);
                if (oldRule != null)
                {
                    config.LoggingRules.Remove(oldRule);
                }
                var rule2 = new LoggingRule(AUDIT_LOGGER, LogLevel.Info, fileTarget);
                config.LoggingRules.Add(rule2);

                oldRule = config.LoggingRules.FirstOrDefault(l => l.LoggerNamePattern == "*");
                if (oldRule != null)
                {
                    config.LoggingRules.Remove(oldRule);
                }
                config.LoggingRules.Add(new LoggingRule("*", LogLevel.Fatal, syslog));

                LogManager.Configuration = config;

                _debugLogger = LogManager.GetLogger(DEBUG_LOGGER);
                _auditLogger = LogManager.GetLogger(AUDIT_LOGGER);
            }
        }