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();
}
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;
}
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;
}
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 !!!");
}
}
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;
}
Aggregations