Java Code Examples for org.apache.juli.logging.Log#error()

The following examples show how to use org.apache.juli.logging.Log#error() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultInstanceManager.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private static void loadProperties(Set<String> classNames, String resourceName,
        String messageKey, Log log) {
    Properties properties = new Properties();
    ClassLoader cl = DefaultInstanceManager.class.getClassLoader();
    try (InputStream is = cl.getResourceAsStream(resourceName)) {
        if (is == null) {
            log.error(sm.getString(messageKey, resourceName));
        } else {
            properties.load(is);
        }
    } catch (IOException ioe) {
        log.error(sm.getString(messageKey, resourceName), ioe);
    }
    if (properties.isEmpty()) {
        return;
    }
    for (Map.Entry<Object, Object> e : properties.entrySet()) {
        if ("restricted".equals(e.getValue())) {
            classNames.add(e.getKey().toString());
        } else {
            log.warn(sm.getString(
                    "defaultInstanceManager.restrictedWrongValue",
                    resourceName, e.getKey(), e.getValue()));
        }
    }
}
 
Example 2
Source File: DefaultInstanceManager.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
private static Properties loadProperties(String resourceName, String errorString, Log log) {
    Properties result = new Properties();
    ClassLoader cl = DefaultInstanceManager.class.getClassLoader();
    InputStream is = null;
    try {
        is = cl.getResourceAsStream(resourceName);
        if (is ==null) {
            log.error(errorString);
        } else {
            result.load(is);
        }
    } catch (IOException ioe) {
        log.error(errorString, ioe);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
            }
        }
    }
    return result;
}
 
Example 3
Source File: CallbackHandlerImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {

    String name = null;
    Principal principal = null;
    Subject subject = null;
    String[] groups = null;

    if (callbacks != null) {
        // Need to combine data from multiple callbacks so use this to hold
        // the data
        // Process the callbacks
        for (Callback callback : callbacks) {
            if (callback instanceof CallerPrincipalCallback) {
                CallerPrincipalCallback cpc = (CallerPrincipalCallback) callback;
                name = cpc.getName();
                principal = cpc.getPrincipal();
                subject = cpc.getSubject();
            } else if (callback instanceof GroupPrincipalCallback) {
                GroupPrincipalCallback gpc = (GroupPrincipalCallback) callback;
                groups = gpc.getGroups();
            } else {
                // This is a singleton so need to get correct Logger for
                // current TCCL
                Log log = LogFactory.getLog(CallbackHandlerImpl.class);
                log.error(sm.getString("callbackHandlerImpl.jaspicCallbackMissing",
                        callback.getClass().getName()));
            }
        }

        // Create the GenericPrincipal
        Principal gp = getPrincipal(principal, name, groups);
        if (subject != null && gp != null) {
            subject.getPrivateCredentials().add(gp);
        }
    }
}
 
Example 4
Source File: SecurityClassLoad.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public static void securityClassLoad(ClassLoader loader) {

        if (System.getSecurityManager() == null) {
            return;
        }

        final String basePackage = "org.apache.jasper.";
        try {
            // Ensure XMLInputFactory is loaded with Tomcat's class loader
            loader.loadClass(basePackage + "compiler.EncodingDetector");

            loader.loadClass(basePackage + "runtime.JspFactoryImpl$PrivilegedGetPageContext");
            loader.loadClass(basePackage + "runtime.JspFactoryImpl$PrivilegedReleasePageContext");

            loader.loadClass(basePackage + "runtime.JspRuntimeLibrary");

            loader.loadClass(basePackage + "runtime.ServletResponseWrapperInclude");
            loader.loadClass(basePackage + "runtime.TagHandlerPool");
            loader.loadClass(basePackage + "runtime.JspFragmentHelper");

            loader.loadClass(basePackage + "runtime.ProtectedFunctionMapper");

            loader.loadClass(basePackage + "runtime.PageContextImpl");
            loadAnonymousInnerClasses(loader, basePackage + "runtime.PageContextImpl");

            loader.loadClass(basePackage + "runtime.JspContextWrapper");

            // Trigger loading of class and reading of property
            SecurityUtil.isPackageProtectionEnabled();

            loader.loadClass(basePackage + "servlet.JspServletWrapper");

            loadAnonymousInnerClasses(loader, "runtime.JspWriterImpl");
        } catch (ClassNotFoundException ex) {
            Log log = LogFactory.getLog(SecurityClassLoad.class);
            log.error("SecurityClassLoad", ex);
        }
    }
 
Example 5
Source File: JDBCStore.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Load the Session associated with the id <code>id</code>.
 * If no such session is found <code>null</code> is returned.
 *
 * @param id a value of type <code>String</code>
 * @return the stored <code>Session</code>
 * @exception ClassNotFoundException if an error occurs
 * @exception IOException if an input/output error occurred
 */
@Override
public Session load(String id) throws ClassNotFoundException, IOException {
    StandardSession _session = null;
    org.apache.catalina.Context context = getManager().getContext();
    Log contextLog = context.getLogger();

    synchronized (this) {
        int numberOfTries = 2;
        while (numberOfTries > 0) {
            Connection _conn = getConnection();
            if (_conn == null) {
                return null;
            }

            ClassLoader oldThreadContextCL = context.bind(Globals.IS_SECURITY_ENABLED, null);

            try {
                if (preparedLoadSql == null) {
                    String loadSql = "SELECT " + sessionIdCol + ", "
                            + sessionDataCol + " FROM " + sessionTable
                            + " WHERE " + sessionIdCol + " = ? AND "
                            + sessionAppCol + " = ?";
                    preparedLoadSql = _conn.prepareStatement(loadSql);
                }

                preparedLoadSql.setString(1, id);
                preparedLoadSql.setString(2, getName());
                try (ResultSet rst = preparedLoadSql.executeQuery()) {
                    if (rst.next()) {
                        try (ObjectInputStream ois =
                                getObjectInputStream(rst.getBinaryStream(2))) {
                            if (contextLog.isDebugEnabled()) {
                                contextLog.debug(sm.getString(
                                        getStoreName() + ".loading", id, sessionTable));
                            }

                            _session = (StandardSession) manager.createEmptySession();
                            _session.readObjectData(ois);
                            _session.setManager(manager);
                        }
                    } else if (context.getLogger().isDebugEnabled()) {
                        contextLog.debug(getStoreName() + ": No persisted data object found");
                    }
                    // Break out after the finally block
                    numberOfTries = 0;
                }
            } catch (SQLException e) {
                contextLog.error(sm.getString(getStoreName() + ".SQLException", e));
                if (dbConnection != null)
                    close(dbConnection);
            } finally {
                context.unbind(Globals.IS_SECURITY_ENABLED, oldThreadContextCL);
                release(_conn);
            }
            numberOfTries--;
        }
    }

    return _session;
}