Search in sources :

Example 1 with Logger

use of com.sun.identity.log.Logger in project OpenAM by OpenRock.

the class LogRecWrite method execute.

/**
     * Return result of the request processing in <code>Response</code>
     * @return result of the request processing in <code>Response</code>
     */
public Response execute(AuditEventPublisher auditEventPublisher, AuditEventFactory auditEventFactory) {
    Response res = new Response("OK");
    SsoServerLoggingSvcImpl slsi = null;
    SsoServerLoggingHdlrEntryImpl slei = null;
    if (MonitoringUtil.isRunning()) {
        slsi = Agent.getLoggingSvcMBean();
        slei = slsi.getHandler(SsoServerLoggingSvcImpl.REMOTE_HANDLER_NAME);
    }
    Logger logger = (Logger) Logger.getLogger(_logname);
    if (Debug.messageEnabled()) {
        Debug.message("LogRecWrite: exec: logname = " + _logname);
    }
    Level level = Level.parse(((com.sun.identity.log.service.LogRecord) _records.elementAt(0)).level);
    String msg = ((com.sun.identity.log.service.LogRecord) _records.elementAt(0)).msg;
    Map logInfoMap = ((com.sun.identity.log.service.LogRecord) _records.elementAt(0)).logInfoMap;
    Object[] parameters = ((com.sun.identity.log.service.LogRecord) _records.elementAt(0)).parameters;
    try {
        msg = new String(com.sun.identity.shared.encode.Base64.decode(msg));
    } catch (RuntimeException ex) {
        // write msg as it is.
        if (Debug.messageEnabled()) {
            Debug.message("LogRecWrite: message is not base64 encoded");
        }
    }
    LogRecord rec = new LogRecord(level, msg);
    if (logInfoMap != null) {
        String loginIDSid = (String) logInfoMap.get(LogConstants.LOGIN_ID_SID);
        if (loginIDSid != null && loginIDSid.length() > 0) {
            SSOToken loginIDToken = null;
            try {
                SSOTokenManager ssom = SSOTokenManager.getInstance();
                loginIDToken = ssom.createSSOToken(loginIDSid);
            } catch (SSOException e) {
                if (Debug.warningEnabled()) {
                    Debug.warning("LogService::process(): SSOException", e);
                }
                rec.setLogInfoMap(logInfoMap);
            }
            if (loginIDToken != null) {
                // here fill up logInfo into the newlr
                rec = LogSSOTokenDetails.logSSOTokenInfo(rec, loginIDToken);
                // now take one be one values from logInfoMap and overwrite
                // any populated value from sso token.
                Set keySet = logInfoMap.keySet();
                Iterator i = keySet.iterator();
                String key = null;
                String value = null;
                while (i.hasNext()) {
                    key = (String) i.next();
                    value = (String) logInfoMap.get(key);
                    if (value != null && value.length() > 0) {
                        if (key.equalsIgnoreCase(LogConstants.DATA)) {
                            try {
                                value = new String(com.sun.identity.shared.encode.Base64.decode(value));
                            } catch (RuntimeException ex) {
                                // ignore & write msg as it is.
                                if (Debug.messageEnabled()) {
                                    Debug.message("LogRecWrite: data is not " + "base64 encoded");
                                }
                            }
                        }
                        rec.addLogInfo(key, value);
                    }
                }
            }
        } else {
            rec.setLogInfoMap(logInfoMap);
        }
    }
    rec.addLogInfo(LogConstants.LOG_LEVEL, rec.getLevel().toString());
    rec.setParameters(parameters);
    SSOToken loggedByToken = null;
    String realm = NO_REALM;
    try {
        SSOTokenManager ssom = SSOTokenManager.getInstance();
        loggedByToken = ssom.createSSOToken(_loggedBySid);
        Map<String, Set<String>> appAttributes = IdUtils.getIdentity(loggedByToken).getAttributes();
        realm = getFirstItem(appAttributes.get(EVALUATION_REALM), NO_REALM);
    } catch (IdRepoException | SSOException ssoe) {
        Debug.error("LogRecWrite: exec:SSOException: ", ssoe);
    }
    if (MonitoringUtil.isRunning()) {
        slei.incHandlerRequestCount(1);
    }
    auditAccessMessage(auditEventPublisher, auditEventFactory, rec, realm);
    logger.log(rec, loggedByToken);
    // Log file record write okay and return OK
    if (MonitoringUtil.isRunning()) {
        slei.incHandlerSuccessCount(1);
    }
    return res;
}
Also used : SSOTokenManager(com.iplanet.sso.SSOTokenManager) SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) Logger(com.sun.identity.log.Logger) Response(com.iplanet.services.comm.share.Response) LogRecord(com.sun.identity.log.LogRecord) Iterator(java.util.Iterator) Level(java.util.logging.Level) Map(java.util.Map) SsoServerLoggingSvcImpl(com.sun.identity.monitoring.SsoServerLoggingSvcImpl) SsoServerLoggingHdlrEntryImpl(com.sun.identity.monitoring.SsoServerLoggingHdlrEntryImpl)

Example 2 with Logger

use of com.sun.identity.log.Logger in project OpenAM by OpenRock.

the class Archiver method archive.

/**
     * This method generates a Date object, formatting according to
     * the "DDMMyyyyHHmmss" format and saves the files in the same directory.
     * <p>
     * also does some book keeping operations.
     *
     * @param fileName name of the archive file.
     * @param location location of the archive file.
     */
public void archive(String fileName, String location) {
    if ((fileName == null) || (fileName.length() == 0)) {
        Debug.error("Archiver:archive:FileName is null");
        return;
    } else if ((location == null) || (location.length() == 0)) {
        Debug.error("Archiver:archive:Location is null");
        return;
    }
    Logger logger = (com.sun.identity.log.Logger) Logger.getLogger(fileName);
    filesPerKeystoreCounter++;
    Date d = new Date();
    String timestampedFileName = location + PREFIX + fileName + "." + sdf.format(d).toString();
    String completePath = location + PREFIX + fileName;
    File f = new File(completePath);
    f.renameTo(new File(timestampedFileName));
    SecureFileHandler.addToCurrentFileList(fileName, fileName + "." + sdf.format(d).toString(), fileName);
    return;
}
Also used : Logger(com.sun.identity.log.Logger) File(java.io.File) Date(java.util.Date)

Example 3 with Logger

use of com.sun.identity.log.Logger in project OpenAM by OpenRock.

the class AuthD method logIt.

////////////////////////////////////////////////////////////////
//  Other utilities
////////////////////////////////////////////////////////////////
/**
      * Writes a log record.
      *
      * @param s Array of data information for the log record.
      * @param type Type of log either <code>LOG_ERROR</code> or
      *        <code>LOG_ACCESS</code>.
      * @param messageName Message ID for the log record.
      * @param ssoProperties Single Sign On Properties to be written to the
      *        log record. If this is <code>null</code>, properties will be
      *        retrieved from administrator Single Sign On Token.
      */
public void logIt(String[] s, int type, String messageName, Hashtable ssoProperties) {
    if (logStatus && (s != null)) {
        try {
            LogMessageProviderBase provider = (LogMessageProviderBase) MessageProviderFactory.getProvider("Authentication");
            com.sun.identity.log.LogRecord lr = null;
            SSOToken ssot = AccessController.doPrivileged(AdminTokenAction.getInstance());
            if (ssoProperties == null) {
                lr = provider.createLogRecord(messageName, s, ssot);
            } else {
                lr = provider.createLogRecord(messageName, s, ssoProperties);
            }
            com.sun.identity.log.Logger logger;
            switch(type) {
                case LOG_ACCESS:
                    logger = (com.sun.identity.log.Logger) Logger.getLogger("amAuthentication.access");
                    logger.log(lr, ssot);
                    break;
                case LOG_ERROR:
                    logger = (com.sun.identity.log.Logger) Logger.getLogger("amAuthentication.error");
                    logger.log(lr, ssot);
                    break;
                default:
                    logger = (com.sun.identity.log.Logger) Logger.getLogger("amAuthentication.access");
                    logger.log(lr, ssot);
                    break;
            }
        } catch (IOException ex) {
            ex.printStackTrace();
            debug.error("Logging exception : " + ex.getMessage());
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Logger(com.sun.identity.log.Logger) LogMessageProviderBase(com.sun.identity.log.messageid.LogMessageProviderBase) IOException(java.io.IOException)

Example 4 with Logger

use of com.sun.identity.log.Logger in project OpenAM by OpenRock.

the class LogWriter method log.

/**
     * Writes to log.
     *
     * @param mgr Command Manager Object.
     * @param type Type of log message.
     * @param level Logging level of the message.
     * @param msgid ID for message.
     * @param msgdata array of log message "data".
     * @param ssoToken Single Sign On Token of the user who committed the
     *        operation.
     * @throws CLIException if log cannot be written.
     */
public static void log(CommandManager mgr, int type, Level level, String msgid, String[] msgdata, SSOToken ssoToken) throws CLIException {
    if (!mgr.isLogOff()) {
        Logger logger;
        String logName = mgr.getLogName();
        switch(type) {
            case LOG_ERROR:
                logger = (com.sun.identity.log.Logger) Logger.getLogger(logName + ".error");
                break;
            default:
                logger = (com.sun.identity.log.Logger) Logger.getLogger(logName + ".access");
        }
        try {
            LogMessageProvider msgProvider = MessageProviderFactory.getProvider(LOG_MSG_XML);
            SSOToken adminSSOToken = AccessController.doPrivileged(AdminTokenAction.getInstance());
            if (ssoToken == null) {
                ssoToken = adminSSOToken;
            }
            if (logger.isLoggable(level)) {
                LogRecord logRec = msgProvider.createLogRecord(msgid, msgdata, ssoToken);
                if (logRec != null) {
                    logger.log(logRec, adminSSOToken);
                }
            }
            logToAuditService(type, msgid, msgdata, ssoToken, msgProvider, adminSSOToken);
        } catch (Exception e) {
            throw new CLIException(e, ExitCodes.CANNOT_WRITE_LOG);
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) LogMessageProvider(com.sun.identity.log.messageid.LogMessageProvider) LogRecord(com.sun.identity.log.LogRecord) Logger(com.sun.identity.log.Logger) URISyntaxException(java.net.URISyntaxException) HttpApplicationException(org.forgerock.http.HttpApplicationException) NeverThrowsException(org.forgerock.util.promise.NeverThrowsException) IOException(java.io.IOException)

Example 5 with Logger

use of com.sun.identity.log.Logger in project OpenAM by OpenRock.

the class IdentityServicesImpl method log.

@Override
public LogResponse log(Token app, Token subject, String logName, String message) throws AccessDenied, TokenExpired, GeneralFailure {
    if (app == null) {
        throw new AccessDenied("No logging application token specified");
    }
    SSOToken appToken;
    SSOToken subjectToken;
    appToken = getSSOToken(app);
    subjectToken = subject == null ? appToken : getSSOToken(subject);
    try {
        LogRecord logRecord = new LogRecord(java.util.logging.Level.INFO, message, subjectToken);
        //TODO Support internationalization via a resource bundle specification
        Logger logger = (Logger) Logger.getLogger(logName);
        logger.log(logRecord, appToken);
        logger.flush();
    } catch (AMLogException e) {
        debug.error("IdentityServicesImpl:log", e);
        throw new GeneralFailure(e.getMessage());
    }
    return new LogResponse();
}
Also used : LogResponse(com.sun.identity.idsvcs.LogResponse) SSOToken(com.iplanet.sso.SSOToken) LogRecord(com.sun.identity.log.LogRecord) GeneralFailure(com.sun.identity.idsvcs.GeneralFailure) AMLogException(com.sun.identity.log.AMLogException) Logger(com.sun.identity.log.Logger) AccessDenied(com.sun.identity.idsvcs.AccessDenied)

Aggregations

Logger (com.sun.identity.log.Logger)10 SSOToken (com.iplanet.sso.SSOToken)4 LogRecord (com.sun.identity.log.LogRecord)4 IOException (java.io.IOException)4 NullLocationException (com.iplanet.log.NullLocationException)2 SSOException (com.iplanet.sso.SSOException)2 AMLogException (com.sun.identity.log.AMLogException)2 File (java.io.File)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 Response (com.iplanet.services.comm.share.Response)1 SSOTokenManager (com.iplanet.sso.SSOTokenManager)1 AuthContext (com.sun.identity.authentication.AuthContext)1 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)1 IdRepoException (com.sun.identity.idm.IdRepoException)1 AccessDenied (com.sun.identity.idsvcs.AccessDenied)1 GeneralFailure (com.sun.identity.idsvcs.GeneralFailure)1 LogResponse (com.sun.identity.idsvcs.LogResponse)1 LogMessageProvider (com.sun.identity.log.messageid.LogMessageProvider)1 LogMessageProviderBase (com.sun.identity.log.messageid.LogMessageProviderBase)1