List of usage examples for org.apache.commons.logging Log isErrorEnabled
boolean isErrorEnabled();
From source file:org.alfresco.repo.webdav.auth.BaseNTLMAuthenticationFilter.java
/** * Process a type 3 NTLM message/*from ww w .j a va 2s . c o m*/ * * @param type3Msg Type3NTLMMessage * @param req HttpServletRequest * @param res HttpServletResponse * * @exception IOException * @exception ServletException */ protected boolean processType3(Type3NTLMMessage type3Msg, ServletContext context, HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { Log logger = getLogger(); if (logger.isDebugEnabled()) logger.debug("Received type3 " + type3Msg); // Get the existing NTLM details NTLMLogonDetails ntlmDetails = null; SessionUser user = null; user = getSessionUser(context, req, res, true); HttpSession session = req.getSession(); ntlmDetails = (NTLMLogonDetails) session.getAttribute(NTLM_AUTH_DETAILS); // Get the NTLM logon details String userName = type3Msg.getUserName(); String workstation = type3Msg.getWorkstation(); String domain = type3Msg.getDomain(); // ALF-10997 fix, normalize the userName //the system runAs is acceptable because we are resolving a username i.e. it's a system-wide operation that does not need permission checks final String userName_f = userName; String normalized = transactionService.getRetryingTransactionHelper() .doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<String>() { public String execute() throws Throwable { return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<String>() { public String doWork() throws Exception { String normalized = personService.getUserIdentifier(userName_f); return normalized; } }, AuthenticationUtil.SYSTEM_USER_NAME); } }, true); if (normalized != null) { userName = normalized; } boolean authenticated = false; // Check if we are using cached details for the authentication if (user != null && ntlmDetails != null && ntlmDetails.hasNTLMHashedPassword()) { // Check if the received NTLM hashed password matches the cached password byte[] ntlmPwd = type3Msg.getNTLMHash(); byte[] cachedPwd = ntlmDetails.getNTLMHashedPassword(); if (ntlmPwd != null) { authenticated = Arrays.equals(cachedPwd, ntlmPwd); } if (logger.isDebugEnabled()) logger.debug("Using cached NTLM hash, authenticated = " + authenticated); onValidate(context, req, res, new NTLMCredentials(userName, ntlmPwd)); // Allow the user to access the requested page return true; } else { WebCredentials credentials; // Check if we are using local MD4 password hashes or passthru authentication if (nltmAuthenticator.getNTLMMode() == NTLMMode.MD4_PROVIDER) { // Check if guest logons are allowed and this is a guest logon if (m_allowGuest && userName.equalsIgnoreCase(authenticationComponent.getGuestUserName())) { credentials = new GuestCredentials(); // Indicate that the user has been authenticated authenticated = true; if (getLogger().isDebugEnabled()) getLogger().debug("Guest logon"); } else { // Get the stored MD4 hashed password for the user, or null if the user does not exist String md4hash = getMD4Hash(userName); if (md4hash != null) { authenticated = validateLocalHashedPassword(type3Msg, ntlmDetails, authenticated, md4hash); credentials = new NTLMCredentials(ntlmDetails.getUserName(), ntlmDetails.getNTLMHashedPassword()); } else { // Check if unknown users should be logged on as guest if (m_mapUnknownUserToGuest) { // Reset the user name to be the guest user userName = authenticationComponent.getGuestUserName(); authenticated = true; credentials = new GuestCredentials(); if (logger.isDebugEnabled()) logger.debug("User " + userName + " logged on as guest, no Alfresco account"); } else { if (logger.isDebugEnabled()) logger.debug("User " + userName + " does not have Alfresco account"); // Bypass NTLM authentication and display the logon screen, // as user account does not exist in Alfresco credentials = new UnknownCredentials(); authenticated = false; } } } } else { credentials = new NTLMCredentials(type3Msg.getUserName(), type3Msg.getNTLMHash()); // Determine if the client sent us NTLMv1 or NTLMv2 if (type3Msg.hasFlag(NTLM.Flag128Bit) && type3Msg.hasFlag(NTLM.FlagNTLM2Key) || (type3Msg.getNTLMHash() != null && type3Msg.getNTLMHash().length > 24)) { // Cannot accept NTLMv2 if we are using passthru auth if (logger.isErrorEnabled()) logger.error("Client " + workstation + " using NTLMv2 logon, not valid with passthru authentication"); } else { if (ntlmDetails == null) { if (logger.isWarnEnabled()) logger.warn( "Authentication failed: NTLM details can not be retrieved from session. Client must support cookies."); restartLoginChallenge(context, req, res); return false; } // Passthru mode, send the hashed password details to the passthru authentication server NTLMPassthruToken authToken = (NTLMPassthruToken) ntlmDetails.getAuthenticationToken(); authToken.setUserAndPassword(type3Msg.getUserName(), type3Msg.getNTLMHash(), PasswordEncryptor.NTLM1); try { // Run the second stage of the passthru authentication nltmAuthenticator.authenticate(authToken); authenticated = true; // Check if the user has been logged on as guest if (authToken.isGuestLogon()) { userName = authenticationComponent.getGuestUserName(); } // Set the authentication context authenticationComponent.setCurrentUser(userName); } catch (BadCredentialsException ex) { if (logger.isDebugEnabled()) logger.debug("Authentication failed, " + ex.getMessage()); } catch (AuthenticationException ex) { if (logger.isDebugEnabled()) logger.debug("Authentication failed, " + ex.getMessage()); } finally { // Clear the authentication token from the NTLM details ntlmDetails.setAuthenticationToken(null); } } } // Check if the user has been authenticated, if so then setup the user environment if (authenticated == true) { boolean userInit = false; if (user == null) { try { user = createUserEnvironment(session, userName); userInit = true; } catch (AuthenticationException ex) { if (logger.isDebugEnabled()) logger.debug("Failed to validate user " + userName, ex); onValidateFailed(context, req, res, session, credentials); return false; } } onValidate(context, req, res, credentials); // Update the NTLM logon details in the session String srvName = getServerName(); if (ntlmDetails == null) { // No cached NTLM details ntlmDetails = new NTLMLogonDetails(userName, workstation, domain, false, srvName); ntlmDetails.setNTLMHashedPassword(type3Msg.getNTLMHash()); session.setAttribute(NTLM_AUTH_DETAILS, ntlmDetails); if (logger.isDebugEnabled()) logger.debug("No cached NTLM details, created"); } else { // Update the cached NTLM details ntlmDetails.setDetails(userName, workstation, domain, false, srvName); ntlmDetails.setNTLMHashedPassword(type3Msg.getNTLMHash()); if (logger.isDebugEnabled()) logger.debug("Updated cached NTLM details"); } if (logger.isDebugEnabled()) logger.debug("User logged on via NTLM, " + ntlmDetails); if (onLoginComplete(context, req, res, userInit)) { // Allow the user to access the requested page return true; } } else { restartLoginChallenge(context, req, res); } } return false; }
From source file:org.apache.ojb.broker.util.logging.CommonsLoggerImpl.java
/** * @see org.apache.ojb.broker.util.logging.Logger#isEnabledFor(int) *///from www. j a va2s.c o m public boolean isEnabledFor(int priority) { Log commonsLog = getLog(); switch (priority) { case Logger.DEBUG: return commonsLog.isDebugEnabled(); case Logger.INFO: return commonsLog.isInfoEnabled(); case Logger.WARN: return commonsLog.isWarnEnabled(); case Logger.ERROR: return commonsLog.isErrorEnabled(); case Logger.FATAL: return commonsLog.isFatalEnabled(); } return false; }
From source file:org.easyrec.utils.spring.log.LoggerUtils.java
/** * @param logger// ww w . jav a2s . co m * @param logLevel * */ public static boolean isLogLevelEnabled(Log logger, String logLevel) { if (logLevel.equalsIgnoreCase("info")) { if (logger.isInfoEnabled()) { return true; } } else if (logLevel.equalsIgnoreCase("debug")) { if (logger.isDebugEnabled()) { return true; } } else if (logLevel.equalsIgnoreCase("error")) { if (logger.isErrorEnabled()) { return true; } } else if (logLevel.equalsIgnoreCase("trace")) { if (logger.isTraceEnabled()) { return true; } } else if (logLevel.equalsIgnoreCase("warn")) { if (logger.isWarnEnabled()) { return true; } } else if (logLevel.equalsIgnoreCase("fatal")) { if (logger.isFatalEnabled()) { return true; } } else { logger.warn("Passed unknown log level '" + logLevel + "' to Aspect - returning false!"); return false; } logger.warn("log level '" + logLevel + "' not enabled - returning false!"); return false; }
From source file:org.easyrec.utils.spring.log.LoggerUtils.java
/** * Writes the given 'message' to the Log 'logger' with level 'logLevel'. * * @param logger the Log to which the message is written * @param logLevel the level to which the message is written * @param message the message to be written *///from ww w . j a v a2 s. c o m public static void log(Log logger, String logLevel, String message) { if (logLevel.equalsIgnoreCase("info")) { if (logger.isInfoEnabled()) { logger.info(message); } } else if (logLevel.equalsIgnoreCase("debug")) { if (logger.isDebugEnabled()) { logger.debug(message); } } else if (logLevel.equalsIgnoreCase("error")) { if (logger.isErrorEnabled()) { logger.error(message); } } else if (logLevel.equalsIgnoreCase("trace")) { if (logger.isTraceEnabled()) { logger.trace(message); } } else if (logLevel.equalsIgnoreCase("warn")) { if (logger.isWarnEnabled()) { logger.warn(message); } } else if (logLevel.equalsIgnoreCase("fatal")) { if (logger.isFatalEnabled()) { logger.fatal(message); } } else { logger.error("Passed unknown log level " + logLevel + " to Aspect - logging to error instead!"); logger.error(message); } }
From source file:org.easyrec.utils.spring.log.LoggerUtils.java
/** * Writes the given 'message' to the Log 'logger' with level 'logLevel'. * * @param logger the Log to which the message is written * @param logLevel the level to which the message is written * @param message the message to be written * @param ta a Throwable passed on to the Log *//*from w w w . j ava 2 s .c o m*/ public static void log(Log logger, String logLevel, String message, Throwable ta) { if (logLevel.equalsIgnoreCase("info")) { if (logger.isInfoEnabled()) { logger.info(message, ta); } } else if (logLevel.equalsIgnoreCase("debug")) { if (logger.isDebugEnabled()) { logger.debug(message, ta); } } else if (logLevel.equalsIgnoreCase("error")) { if (logger.isErrorEnabled()) { logger.error(message, ta); } } else if (logLevel.equalsIgnoreCase("trace")) { if (logger.isTraceEnabled()) { logger.trace(message, ta); } } else if (logLevel.equalsIgnoreCase("warn")) { if (logger.isWarnEnabled()) { logger.warn(message, ta); } } else if (logLevel.equalsIgnoreCase("fatal")) { if (logger.isFatalEnabled()) { logger.fatal(message, ta); } } else { logger.error("Passed unknown log level " + logLevel + " to Aspect - logging to error instead!"); logger.error(message, ta); } }
From source file:org.eclipse.smila.connectivity.framework.schema.ConfigurationLoader.java
/** * Unmarshall index order configuration. * //from w w w . j a v a2s . com * @param is * xml input stream * * @return index order configuration * * @throws JAXBException * the JAXB exception * @throws IOException * Signals that an I/O exception has occurred. * @throws SchemaNotFoundException * the index order schema not found exception */ public static DataSourceConnectionConfig unmarshall(final InputStream is) throws JAXBException, IOException, SchemaNotFoundException { final Log log = LogFactory.getLog(ConfigurationLoader.class); if (is == null) { throw new SchemaRuntimeException("Configaration stream is null!"); } InputStream inputStream = null; try { java.io.ByteArrayOutputStream bos = new ByteArrayOutputStream(); IOUtils.copy(is, bos); final byte[] array = bos.toByteArray(); bos = null; inputStream = new ByteArrayInputStream(array); // preinit context JaxbThreadContext.setPluginContext(Thread.currentThread(), null); // unmarshall first time to locate plug-in final JAXBContext jaxbContext = newSimpleContext(); jaxbContext.createUnmarshaller().unmarshal(inputStream); IOUtils.closeQuietly(inputStream); final JaxbPluginContext pluginContext = JaxbThreadContext.getPluginContext(Thread.currentThread()); final Unmarshaller finalUnmarshaller = pluginContext.createValidatingUnmarshaller(); inputStream = new ByteArrayInputStream(array); // unmarshall second time by plug-in return (DataSourceConnectionConfig) finalUnmarshaller.unmarshal(inputStream); } catch (final SchemaNotFoundException e) { if (log.isErrorEnabled()) { log.error(e); } throw e; } finally { JaxbThreadContext.removeKey(Thread.currentThread()); IOUtils.closeQuietly(is); IOUtils.closeQuietly(inputStream); } }
From source file:org.eclipse.smila.lucene.internal.LuceneSchemaResolver.java
/** * {@inheritDoc}//from w w w.ja va 2s . c om * * @see org.eclipse.smila.utils.xml.SchemaResolver#getSchemaByName(java.lang.String) */ @Override public byte[] getSchemaByName(final String schemaName) { final Log log = LogFactory.getLog(getClass()); final Set<String> schemas = new HashSet<String>(); for (final String schema : KNOWN_SCHEMAS) { schemas.add("../xml/" + schema); } if (!schemas.contains(schemaName)) { // not responsible for schema loading. return null; } final File folder = ConfigUtils.getConfigFolder(LuceneService.BUNDLE_NAME, "xml"); if (folder == null) { if (log.isErrorEnabled()) { log.error("unable to locate configuration folder [" + LuceneService.BUNDLE_NAME + "/xml]"); } return null; } FileInputStream fis = null; final String fileName = folder.getPath() + "/" + schemaName; try { fis = new FileInputStream(fileName); final byte[] schema = IOUtils.toByteArray(fis); return schema; } catch (final Exception exception) { if (log.isErrorEnabled()) { log.error("unable to read schema file [" + fileName + "]", exception); } return null; } finally { IOUtils.closeQuietly(fis); } }
From source file:org.eclipse.smila.management.jmx.client.helpers.ConfigLoader.java
/** * Creates the validation event handler. * /*from w w w . j av a 2 s.c o m*/ * @return the validation event handler */ public static ValidationEventHandler createValidationEventHandler() { return new ValidationEventHandler() { public boolean handleEvent(final ValidationEvent ve) { final Log log = LogFactory.getLog(Main.class); if (ve.getSeverity() != ValidationEvent.WARNING) { final ValidationEventLocator vel = ve.getLocator(); if (log.isErrorEnabled()) { log.error("Line:Col[" + vel.getLineNumber() + ":" + vel.getColumnNumber() + "]:" + ve.getMessage()); } return false; } return true; } }; }
From source file:org.eclipse.smila.processing.pipelets.xmlprocessing.util.XMLUtils.java
/** * A 32 byte GUID generator (Globally Unique ID). These artificial keys SHOULD <strong>NOT </strong> be seen by the * user, not even touched by the DBA but with very rare exceptions, just manipulated by the database and the programs. * /* w w w.j a v a 2 s. c o m*/ * Usage: Add an id field (type java.lang.String) to your EJB, and add setId(XXXUtil.generateGUID(this)); to the * ejbCreate method. * * @param o * a Object * @return a String */ public static final String generateGUID(Object o) { final Log log = LogFactory.getLog(XMLUtils.class); final StringBuffer tmpBuffer = new StringBuffer(16); if (s_hexServerIP == null) { java.net.InetAddress localInetAddress = null; try { // get the inet address localInetAddress = java.net.InetAddress.getLocalHost(); } catch (java.net.UnknownHostException uhe) { // todo: find better way to get around this... final String msg = "ConfigurationUtil: Could not get the local IP address using InetAddress.getLocalHost()!"; System.err.println(msg); if (log.isErrorEnabled()) { log.error(uhe); } return null; } final byte[] serverIP = localInetAddress.getAddress(); s_hexServerIP = hexFormat(getInt(serverIP), 8); } final String hashcode = hexFormat(System.identityHashCode(o), 8); tmpBuffer.append(s_hexServerIP); tmpBuffer.append(hashcode); final long timeNow = System.currentTimeMillis(); final int timeLow = (int) timeNow & 0xFFFFFFFF; final int node = SEEDER.nextInt(); final StringBuffer guid = new StringBuffer(32); guid.append(hexFormat(timeLow, 8)); guid.append(tmpBuffer.toString()); guid.append(hexFormat(node, 8)); return guid.toString(); }
From source file:org.eclipse.smila.search.CoreSchemaResolver.java
/** * {@inheritDoc}/*from www. ja v a 2 s . c o m*/ * * @see org.eclipse.smila.utils.xml.SchemaResolver#getSchemaByName(java.lang.String) */ public byte[] getSchemaByName(final String schemaName) { final Log log = LogFactory.getLog(getClass()); final Set<String> schemas = new HashSet<String>(); for (final String schema : KNOWN_SCHEMAS) { schemas.add("../xml/" + schema); } if (!schemas.contains(schemaName)) { // not responsible for schema loading. return null; } final File folder = ConfigUtils.getConfigFolder(EIFActivator.BUNDLE_NAME, "xml"); if (folder == null) { if (log.isErrorEnabled()) { log.error("unable to locate configuration folder [" + EIFActivator.BUNDLE_NAME + "/xml]"); } return null; } FileInputStream fis = null; final String fileName = folder.getPath() + "/" + schemaName; try { fis = new FileInputStream(fileName); final byte[] schema = IOUtils.toByteArray(fis); return schema; } catch (final Exception exception) { if (log.isErrorEnabled()) { log.error("unable to read schema file [" + fileName + "]", exception); } return null; } finally { IOUtils.closeQuietly(fis); } }