Search in sources :

Example 16 with LogRecord

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

Example 17 with LogRecord

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

the class LogMessageProviderBase method createLogRecord.

/**
     * Returns Log Record. <code>null</code> is returned if there are no
     * corresponding entries in the XML definition file match with the
     * <code>messageIDName</code>.
     *
     * @param messageIDName Name of Message ID.
     * @param dataInfo Array of dataInfo.
     * @param ssoToken Single sign on token which will be used to fill in
     *        details like client IP address into the log record.
     * @return Log Record.
     */
public LogRecord createLogRecord(String messageIDName, String[] dataInfo, Object ssoToken) {
    LogRecord logRec = null;
    LogMessageID logMsgId = hashMessageIDs.get(messageIDName);
    if (logMsgId != null) {
        logRec = (ssoToken != null) ? new LogRecord(logMsgId.getLogLevel(), formatMessage(dataInfo, logMsgId), ssoToken) : new LogRecord(logMsgId.getLogLevel(), formatMessage(dataInfo, logMsgId));
        logRec.addLogInfo(LogConstants.MESSAGE_ID, logMsgId.getPrefix() + "-" + logMsgId.getID());
    } else {
        Debug.error("LogMessageProviderBase.createLogRecord: " + "unable to locate message ID object for " + messageIDName);
    }
    return logRec;
}
Also used : LogRecord(com.sun.identity.log.LogRecord)

Example 18 with LogRecord

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

the class LogMessageProviderBase method createLogRecord.

/**
     * Returns Log Record. <code>null</code> is returned if there are no
     * corresponding entries in the XML definition file match with the
     * <code>messageIDName</code>.
     *
     * @param messageIDName Name of Message ID.
     * @param dataInfo Array of dataInfo.
     * @param ssoProperties Hashtable which will be used to fill in
     *        details like client IP address into the log record.
     * @return Log Record.
     */
public LogRecord createLogRecord(String messageIDName, String[] dataInfo, Hashtable ssoProperties) {
    LogRecord logRec = null;
    LogMessageID logMsgId = (LogMessageID) hashMessageIDs.get(messageIDName);
    if (logMsgId != null) {
        logRec = new LogRecord(logMsgId.getLogLevel(), formatMessage(dataInfo, logMsgId), ssoProperties);
        logRec.addLogInfo(LogConstants.MESSAGE_ID, logMsgId.getPrefix() + "-" + logMsgId.getID());
    } else {
        Debug.error("LogMessageProviderBase.createLogRecord: " + "unable to locale message ID object for " + messageIDName);
    }
    return logRec;
}
Also used : LogRecord(com.sun.identity.log.LogRecord)

Example 19 with LogRecord

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

the class LogSample method logWriteProcessing.

private void logWriteProcessing() {
    /*
         *  get:
         *    1. subject userid (subject of the LogRecord)
	 *    2. subject userid's password
         *    3. Log filename to log to
         *    4. LogRecord's "data"
         *    5. LoggedBy userid (who's doing the logging)
         *    6. LoggedBy userid's password
         *    7. Realm (for both subject userid and LoggedBy userid
         *       in this sample)
         */
    String userSID = sampleUtils.getLine("Subject Userid", DEF_USERNAME);
    String userPWD = sampleUtils.getLine("Subject Userid " + userSID + "'s password", DEF_USERPSWD);
    String logName = sampleUtils.getLine("Log file", DEF_LOGNAME);
    String message = sampleUtils.getLine("Log message", DEF_LOGMSG);
    ;
    String loggedBySID = sampleUtils.getLine("LoggedBy Userid", DEF_LOGGEDBY);
    String loggedByPWD = sampleUtils.getLine("LoggedBy Userid's password", DEF_LOGGEDBYPSWD);
    String realmName = sampleUtils.getLine("Realm", DEF_REALM);
    // get AuthContexts for subject userid and loggedby userid
    try {
        userAC = new AuthContext(realmName);
        loggerAC = new AuthContext(realmName);
    } catch (AuthLoginException le) {
        System.err.println("LogSampleUtils: could not get AuthContext for realm " + realmName);
        System.exit(2);
    }
    // do user and loggedby login and get the SSOToken
    try {
        userSSOToken = sampleUtils.realmLogin(userSID, userPWD, userAC);
        loggerSSOToken = sampleUtils.realmLogin(loggedBySID, loggedByPWD, loggerAC);
    } catch (SSOException ssoe) {
        System.err.println("logWriteProcessing: could not get SSOToken: " + ssoe.getMessage());
        System.exit(3);
    } catch (AuthLoginException ale) {
        System.err.println("logWriteProcessing: could not authenticate: " + ale.getMessage());
        System.exit(4);
    } catch (Exception e) {
        System.err.println("logWriteProcessing: exception getting SSOToken: " + e.getMessage());
        System.exit(5);
    }
    try {
        LogRecord logRecord = new LogRecord(java.util.logging.Level.INFO, message, userSSOToken);
        logRecord.addLogInfo("ModuleName", DEF_MODULENAME);
        java.net.InetAddress ipAddr = java.net.InetAddress.getLocalHost();
        logRecord.addLogInfo("IPAddr", ipAddr.getHostAddress());
        Logger logger = (Logger) Logger.getLogger(logName);
        logger.log(logRecord, loggerSSOToken);
        System.out.println("LogSample: Logging Successful !!!");
        userAC.logout();
        loggerAC.logout();
    } catch (AMLogException amex) {
        System.err.println("LogSample: AMLogException: " + amex.getMessage());
        System.err.println("LogSample: Logging Failed; " + "Is user '" + loggedBySID + "' a member of a Role or Group with log writing privileges?");
    } catch (Exception ssoe) {
        System.err.println("LogSample: Exception: " + ssoe.getMessage());
        System.err.println("LogSample: Logging Failed !!!");
    }
}
Also used : LogRecord(com.sun.identity.log.LogRecord) AuthContext(com.sun.identity.authentication.AuthContext) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) AMLogException(com.sun.identity.log.AMLogException) SSOException(com.iplanet.sso.SSOException) Logger(com.sun.identity.log.Logger) LoginException(javax.security.auth.login.LoginException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SSOException(com.iplanet.sso.SSOException) AMLogException(com.sun.identity.log.AMLogException)

Example 20 with LogRecord

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

the class LogProvider method getLogRecord.

private LogRecord getLogRecord(String messageId, String[] data, Object session, Map properties, SSOToken authSSOToken) {
    SSOToken ssoToken = null;
    if (session != null) {
        try {
            String sid = SessionManager.getProvider().getSessionID(session);
            ssoToken = SSOTokenManager.getInstance().createSSOToken(sid);
        } catch (SessionException se) {
            debug.message("Error getting session provider: ", se);
        } catch (SSOException soe) {
            debug.message("Error creating SSOToken: ", soe);
        }
    }
    SSOToken realToken = (ssoToken != null) ? ssoToken : authSSOToken;
    LogRecord lr = msgProvider.createLogRecord(messageId, data, realToken);
    if ((properties != null) && (lr != null)) {
        String nameIDValue = (String) properties.get(LogConstants.NAME_ID);
        if ((nameIDValue != null) && (nameIDValue.length() > 0)) {
            lr.addLogInfo(LogConstants.NAME_ID, nameIDValue);
        }
        if (ssoToken == null) {
            String clientDomain = (String) properties.get(LogConstants.DOMAIN);
            if (clientDomain != null) {
                lr.addLogInfo(LogConstants.DOMAIN, clientDomain);
            }
            String clientID = (String) properties.get(LogConstants.LOGIN_ID);
            if (clientID != null) {
                lr.addLogInfo(LogConstants.LOGIN_ID, clientID);
            }
            String ipAddress = (String) properties.get(LogConstants.IP_ADDR);
            if (ipAddress != null) {
                String hostName = ipAddress;
                try {
                    if (Logger.resolveHostNameEnabled()) {
                        hostName = InetAddress.getByName(ipAddress).getHostName();
                    }
                } catch (Exception e) {
                    if (debug.messageEnabled()) {
                        debug.message("LogProvider:Unable to get Host for:" + ipAddress);
                    }
                    hostName = ipAddress;
                }
                lr.addLogInfo(LogConstants.IP_ADDR, hostName);
            }
            String loginIDSid = (String) properties.get(LogConstants.LOGIN_ID_SID);
            if (loginIDSid != null) {
                lr.addLogInfo(LogConstants.LOGIN_ID_SID, loginIDSid);
            }
            String moduleName = (String) properties.get(LogConstants.MODULE_NAME);
            if (moduleName != null) {
                lr.addLogInfo(LogConstants.MODULE_NAME, moduleName);
            }
            String contextID = (String) properties.get(LogConstants.CONTEXT_ID);
            if (contextID != null) {
                lr.addLogInfo(LogConstants.CONTEXT_ID, contextID);
            }
        }
    }
    return lr;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) LogRecord(com.sun.identity.log.LogRecord) SessionException(com.sun.identity.plugin.session.SessionException) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) SessionException(com.sun.identity.plugin.session.SessionException) SSOException(com.iplanet.sso.SSOException) LogException(com.sun.identity.plugin.log.LogException)

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