Search in sources :

Example 1 with LogRecord

use of com.sun.identity.log.LogRecord 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 2 with LogRecord

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

the class TokenLogUtils method access.

/**
     * Logs message to core token access logs.
     *
     * @param level the log level , these are based on those
     *          defined in java.util.logging.Level, the values for
     *          level can be any one of the following : <br>
     *          <ul>
     *          <li>SEVERE (highest value) <br>
     *          <li>WARNING <br>
     *          <li>INFO <br>
     *          <li>CONFIG <br>
     *          <li>FINE <br>
     *          <li>FINER <br>
     *          <li>FINEST (lowest value) <br>
     *          </ul>
     * @param msgid the message or a message identifier.
     * @param data string array of dynamic data to be replaced in the message.
     * @param session the User's session object
     * @param nameId value for NameID logging field
     */
public static void access(Level level, String msgid, String[] data, SSOToken session, String nameId) {
    if (logActive) {
        try {
            if (isAccessLoggable(level)) {
                SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
                LogMessageProvider msgProvider = MessageProviderFactory.getProvider(LOG_MSG_XML);
                LogRecord logRec = msgProvider.createLogRecord(msgid, data, session);
                logRec.addLogInfo(TokenLogUtils.TOKEN_NAME_ID, nameId);
                if (logRec != null) {
                    accessLogger.log(logRec, adminToken);
                }
            }
        } catch (IOException le) {
            CoreTokenUtils.debug.error("TokenLogUtils.error:Couldn't write error log:", le);
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) LogMessageProvider(com.sun.identity.log.messageid.LogMessageProvider) LogRecord(com.sun.identity.log.LogRecord) IOException(java.io.IOException)

Example 3 with LogRecord

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

the class TokenLogUtils method error.

/** 
     * Logs error messages to core token error log.
     *
     * @param level the log level , these are based on those
     *          defined in java.util.logging.Level, the values for
     *          level can be any one of the following : <br>
     *          <ul>
     *          <li>SEVERE (highest value) <br>
     *          <li>WARNING <br>
     *          <li>INFO <br>
     *          <li>CONFIG <br>
     *          <li>FINE <br>
     *          <li>FINER <br>
     *          <li>FINEST (lowest value) <br>
     *          </ul>
     * @param msgid the message or a message identifier.
     * @param data string array of dynamic data to be replaced in the message.
     * @param session the User's Session object.
     * @param nameId value for NameID logging field
      */
public static void error(Level level, String msgid, String[] data, SSOToken session, String nameId) {
    if (logActive) {
        try {
            if (isErrorLoggable(level)) {
                SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
                LogMessageProvider msgProvider = MessageProviderFactory.getProvider(LOG_MSG_XML);
                LogRecord logRec = msgProvider.createLogRecord(msgid, data, session);
                logRec.addLogInfo(TokenLogUtils.TOKEN_NAME_ID, nameId);
                if (logRec != null) {
                    errorLogger.log(logRec, adminToken);
                }
            }
        } catch (IOException le) {
            CoreTokenUtils.debug.error("TokenLogUtils.error:Couldn't write error log:", le);
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) LogMessageProvider(com.sun.identity.log.messageid.LogMessageProvider) LogRecord(com.sun.identity.log.LogRecord) IOException(java.io.IOException)

Example 4 with LogRecord

use of com.sun.identity.log.LogRecord 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 5 with LogRecord

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

the class PolicyUtils method logErrorMessage.

/**
     * Logs an error message
     * @param msgIdName name of message id
     * @param data array of data to be logged
     * @param token session token of the user who did the operation
     * that triggered this logging
     */
public static void logErrorMessage(String msgIdName, String[] data, SSOToken token) throws SSOException {
    try {
        if (msgProvider == null) {
            msgProvider = MessageProviderFactory.getProvider("Policy");
        }
    } catch (IOException e) {
        debug.error("PolicyUtils.logErrorMessage()", e);
        debug.error("PolicyUtils.logAccessMessage():" + "disabling logging");
        logStatus = false;
    }
    if ((errorLogger != null) && (msgProvider != null)) {
        LogRecord lr = msgProvider.createLogRecord(msgIdName, data, token);
        if (lr != null) {
            SSOToken ssoToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
            errorLogger.log(lr, ssoToken);
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) LogRecord(com.sun.identity.log.LogRecord) IOException(java.io.IOException)

Aggregations

LogRecord (com.sun.identity.log.LogRecord)21 SSOToken (com.iplanet.sso.SSOToken)14 IOException (java.io.IOException)9 LogMessageProvider (com.sun.identity.log.messageid.LogMessageProvider)5 Logger (com.sun.identity.log.Logger)4 SSOException (com.iplanet.sso.SSOException)3 AMLogException (com.sun.identity.log.AMLogException)3 Level (java.util.logging.Level)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 ELogRecord (com.sun.identity.entitlement.log.ELogRecord)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 SsoServerLoggingHdlrEntryImpl (com.sun.identity.monitoring.SsoServerLoggingHdlrEntryImpl)1 SsoServerLoggingSvcImpl (com.sun.identity.monitoring.SsoServerLoggingSvcImpl)1 LogException (com.sun.identity.plugin.log.LogException)1