Example usage for org.apache.commons.logging Log warn

List of usage examples for org.apache.commons.logging Log warn

Introduction

In this page you can find the example usage for org.apache.commons.logging Log warn.

Prototype

void warn(Object message);

Source Link

Document

Logs a message with warn log level.

Usage

From source file:org.alfresco.extension.bulkimport.util.LogUtils.java

public final static void warn(final Log log, final String message) {
    log.warn(PREFIX + message);
}

From source file:org.alfresco.repo.module.LoggerModuleComponent.java

@Override
protected void executeInternal() throws Throwable {
    String moduleId = super.getModuleId();
    String name = super.getName();
    Log logger = LogFactory.getLog(moduleId + "." + name);
    switch (logLevel) {
    case INFO:/*from  w ww  .  java2  s  . co  m*/
        logger.info(message);
        break;
    case WARN:
        logger.warn(message);
        break;
    case ERROR:
        logger.error(message);
        break;
    }
}

From source file:org.alfresco.repo.webdav.auth.BaseNTLMAuthenticationFilter.java

/**
 * Process a type 3 NTLM message/*  w  ww.j a v a2s  . 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.alfresco.service.cmr.admin.RepoUsageStatus.java

/**
 * Log warnings and errors to the given logger
 *//*from ww w .  jav a 2  s . com*/
public void logMessages(Log logger) {
    for (String msg : warnings) {
        logger.warn(msg);
    }
    for (String msg : errors) {
        logger.error(msg);
    }
}

From source file:org.alfresco.service.cmr.repository.NodeRef.java

private static void logNodeRefError(String nodeRefId, Log logger) {
    if (logger.isWarnEnabled()) {
        StringBuilder msg = new StringBuilder();
        msg.append("Target Node: ").append(nodeRefId);
        msg.append(" is not a valid NodeRef and has been ignored.");
        logger.warn(msg.toString());
    }//from w w  w. ja  v a2  s .c o  m
}

From source file:org.alfresco.util.LogUtil.java

/**
 * Log an I18Nized message to WARN.//from  ww w .j av a  2  s  . c om
 * 
 * @param logger        the logger to use
 * @param messageKey    the message key
 * @param args          the required message arguments
 */
public static final void warn(Log logger, String messageKey, Object... args) {
    logger.warn(I18NUtil.getMessage(messageKey, args));
}

From source file:org.amplafi.flow.impl.FlowStateImpl.java

protected void warn(String message) {
    Log log = getLog();
    if (log != null) {
        log.warn(message);
    }
}

From source file:org.apache.camel.component.cxf.mtom.MtomTestHelper.java

static boolean isAwtHeadless(org.apache.commons.logging.Log log, org.slf4j.Logger logger) {
    Assert.assertFalse("Both loggers are not allowed to be null!", log == null && logger == null);
    boolean headless = Boolean.getBoolean("java.awt.headless");
    if (headless) {
        // having the conversion characters %c{1} inside log4j.properties will reveal us the
        // test class currently running as we make use of it's logger to warn about skipping!
        String warning = "Running headless. Skipping test as Images may not work.";
        if (log != null) {
            log.warn(warning);
        }/*ww  w  .  ja v a2  s.c o m*/

        if (logger != null) {
            logger.warn("Running headless. Skipping test as Images may not work.");
        }
    }

    return headless;
}

From source file:org.apache.cayenne.access.loader.NamePatternMatcher.java

/**
 * Returns an array of Patterns. Takes a comma-separated list of patterns, attempting
 * to convert them to the java.util.regex.Pattern syntax. E.g.
 * <p>/*w ww  .j a va2  s. co m*/
 * <code>"billing_*,user?"</code> will become an array of two expressions:
 * <p>
 * <code>^billing_.*$</code><br>
 * <code>^user.?$</code><br>
 */
public static Pattern[] createPatterns(Log logger, String patternString) {
    if (patternString == null) {
        return new Pattern[0];
    }
    String[] patternStrings = tokenizePattern(patternString);
    List<Pattern> patterns = new ArrayList<Pattern>(patternStrings.length);

    for (String patternString1 : patternStrings) {

        // test the pattern
        try {
            patterns.add(Pattern.compile(patternString1));
        } catch (PatternSyntaxException e) {

            if (logger != null) {
                logger.warn("Ignoring invalid pattern [" + patternString1 + "], reason: " + e.getMessage());
            }
        }
    }

    return patterns.toArray(new Pattern[patterns.size()]);
}

From source file:org.apache.cayenne.dbsync.filter.NamePatternMatcher.java

/**
 * Returns an array of Patterns. Takes a comma-separated list of patterns, attempting
 * to convert them to the java.util.regex.Pattern syntax. E.g.
 * <p>/*  ww  w.j  av a 2 s .  c  om*/
 * <code>"billing_*,user?"</code> will become an array of two expressions:
 * <p>
 * <code>^billing_.*$</code><br>
 * <code>^user.?$</code><br>
 */
public static Pattern[] createPatterns(Log logger, String patternString) {
    if (patternString == null) {
        return new Pattern[0];
    }
    String[] patternStrings = tokenizePattern(patternString);
    List<Pattern> patterns = new ArrayList<>(patternStrings.length);

    for (String patternString1 : patternStrings) {

        // test the pattern
        try {
            patterns.add(Pattern.compile(patternString1));
        } catch (PatternSyntaxException e) {

            if (logger != null) {
                logger.warn("Ignoring invalid pattern [" + patternString1 + "], reason: " + e.getMessage());
            }
        }
    }

    return patterns.toArray(new Pattern[patterns.size()]);
}