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