Search in sources :

Example 1 with NoOpLog

use of org.apache.commons.logging.impl.NoOpLog in project windowbuilder by eclipse.

the class LayoutDescription method loadDescription.

// //////////////////////////////////////////////////////////////////////////
// 
// Utilities
// 
// //////////////////////////////////////////////////////////////////////////
private void loadDescription() throws Exception {
    // prepare resource
    String resourcePath = m_layoutClassName.replace('.', '/') + ".wbp-component.xml";
    ResourceInfo resourceInfo = DescriptionHelper.getResourceInfo(resourcePath, m_toolkit.getId());
    if (resourceInfo == null) {
        DesignerPlugin.log("Not found resource " + m_layoutClassName.replace('.', '/') + ".wbp-component.xml" + " in bundle " + m_toolkit.getId());
        return;
    }
    Digester digester;
    // prepare digester
    {
        digester = new Digester();
        digester.setLogger(new NoOpLog());
        digester.addRule("component/creation", new Rule() {

            @Override
            public void begin(String namespace, String name, Attributes attributes) throws Exception {
                final String id = attributes.getValue("id");
                digester.push(id != null ? id : StringUtils.EMPTY);
            }

            @Override
            public void end(String namespace, String name) throws Exception {
                digester.pop();
            }
        });
        digester.addRule("component/creation/source", new Rule() {

            @Override
            public void body(String namespace, String name, String text) throws Exception {
                final String id = (String) digester.peek();
                if (id.equals(m_creationId)) {
                    m_source = text;
                }
            }
        });
    }
    // do parse
    InputStream is = resourceInfo.getURL().openStream();
    try {
        digester.parse(is);
    } finally {
        IOUtils.closeQuietly(is);
    }
}
Also used : ResourceInfo(org.eclipse.wb.internal.core.model.description.resource.ResourceInfo) InputStream(java.io.InputStream) Digester(org.apache.commons.digester.Digester) Attributes(org.xml.sax.Attributes) Rule(org.apache.commons.digester.Rule) NoOpLog(org.apache.commons.logging.impl.NoOpLog)

Example 2 with NoOpLog

use of org.apache.commons.logging.impl.NoOpLog in project windowbuilder by eclipse.

the class ComponentDescriptionHelper method getDescription0.

/**
 * @param editor
 *          the {@link AstEditor} in context of which we work now.
 * @param key
 *          the {@link ComponentDescriptionKey} of requested {@link ComponentDescription}.
 * @param additionalDescriptionInfos
 *          additional {@link ClassResourceInfo}'s to parse after {@link ClassResourceInfo}'s
 *          collected for component {@link Class}. May be empty, but not <code>null</code>.
 *
 * @return the {@link ComponentDescription} of component with given {@link Class}.
 * @throws Exception
 *           if no {@link ComponentDescription} can be found.
 */
private static ComponentDescription getDescription0(AstEditor editor, ComponentDescriptionKey key, List<ClassResourceInfo> additionalDescriptionInfos) throws Exception {
    EditorState state = EditorState.get(editor);
    ILoadingContext context = EditorStateLoadingContext.get(state);
    Class<?> componentClass = key.getComponentClass();
    // 
    try {
        // prepare result description
        ComponentDescription componentDescription = new ComponentDescription(key);
        addConstructors(editor.getJavaProject(), componentDescription);
        componentDescription.setBeanInfo(ReflectionUtils.getBeanInfo(componentClass));
        componentDescription.setBeanDescriptor(new IntrospectionHelper(componentClass).getBeanDescriptor());
        // prepare list of description resources, from generic to specific
        LinkedList<ClassResourceInfo> descriptionInfos;
        {
            descriptionInfos = Lists.newLinkedList();
            DescriptionHelper.addDescriptionResources(descriptionInfos, context, componentClass);
            Assert.isTrueException(!descriptionInfos.isEmpty(), ICoreExceptionConstants.DESCRIPTION_NO_DESCRIPTIONS, componentClass.getName());
            // at last append additional description resource
            descriptionInfos.addAll(additionalDescriptionInfos);
        }
        // prepare Digester
        Digester digester;
        {
            digester = new Digester();
            digester.setLogger(new NoOpLog());
            addRules(digester, editor, componentClass);
        }
        // read descriptions from generic to specific
        for (ClassResourceInfo descriptionInfo : descriptionInfos) {
            ResourceInfo resourceInfo = descriptionInfo.resource;
            // read next description
            {
                componentDescription.setCurrentClass(descriptionInfo.clazz);
                digester.push(componentDescription);
                // do parse
                InputStream is = resourceInfo.getURL().openStream();
                try {
                    digester.parse(is);
                } finally {
                    IOUtils.closeQuietly(is);
                }
            }
            // clear parts that can not be inherited
            if (descriptionInfo.clazz == componentClass) {
                setDescriptionWithInnerTags(componentDescription, resourceInfo);
            } else {
                componentDescription.clearCreations();
                componentDescription.setDescription(null);
            }
        }
        // set toolkit
        if (componentDescription.getToolkit() == null) {
            for (int i = descriptionInfos.size() - 1; i >= 0; i--) {
                ClassResourceInfo descriptionInfo = descriptionInfos.get(i);
                ToolkitDescription toolkit = descriptionInfo.resource.getToolkit();
                if (toolkit != null) {
                    componentDescription.setToolkit(toolkit);
                    break;
                }
            }
            Assert.isTrueException(componentDescription.getToolkit() != null, ICoreExceptionConstants.DESCRIPTION_NO_TOOLKIT, componentClass.getName());
        }
        // icon, default creation
        setIcon(context, componentDescription, componentClass);
        configureDefaultCreation(componentDescription);
        // final operations
        {
            Assert.isNotNull(componentDescription.getModelClass());
            componentDescription.joinProperties();
        }
        // add to caches
        if (key.isPureComponent() && !"true".equals(componentDescription.getParameter("dontCacheDescription")) && shouldCacheDescriptions_inPackage(descriptionInfos.getLast(), componentClass)) {
            componentDescription.setCached(true);
        }
        // mark for caching presentation
        if (shouldCachePresentation(descriptionInfos.getLast(), componentClass)) {
            componentDescription.setPresentationCached(true);
        }
        // use processors
        for (IDescriptionProcessor processor : getDescriptionProcessors()) {
            processor.process(editor, componentDescription);
        }
        // well, we have result
        return componentDescription;
    } catch (SAXParseException e) {
        throw new DesignerException(ICoreExceptionConstants.DESCRIPTION_LOAD_ERROR, e.getException(), componentClass.getName());
    }
}
Also used : ClassResourceInfo(org.eclipse.wb.internal.core.model.description.resource.ClassResourceInfo) ResourceInfo(org.eclipse.wb.internal.core.model.description.resource.ResourceInfo) ComponentDescription(org.eclipse.wb.internal.core.model.description.ComponentDescription) InputStream(java.io.InputStream) ClassResourceInfo(org.eclipse.wb.internal.core.model.description.resource.ClassResourceInfo) IntrospectionHelper(org.eclipse.wb.internal.core.utils.reflect.IntrospectionHelper) IDescriptionProcessor(org.eclipse.wb.internal.core.model.description.IDescriptionProcessor) DesignerException(org.eclipse.wb.internal.core.utils.exception.DesignerException) EditorState(org.eclipse.wb.internal.core.utils.state.EditorState) SAXParseException(org.xml.sax.SAXParseException) Digester(org.apache.commons.digester.Digester) ToolkitDescription(org.eclipse.wb.internal.core.model.description.ToolkitDescription) NoOpLog(org.apache.commons.logging.impl.NoOpLog)

Example 3 with NoOpLog

use of org.apache.commons.logging.impl.NoOpLog in project windowbuilder by eclipse.

the class FactoryDescriptionHelper method prepareDigester.

// //////////////////////////////////////////////////////////////////////////
// 
// Rules
// 
// //////////////////////////////////////////////////////////////////////////
private static Digester prepareDigester(Class<?> factoryClass, EditorState state, final Map<Integer, FactoryMethodDescription> textualDescriptions) {
    Digester digester = new Digester() {

        private static final String DESCRIPTION_PATTERN = "factory/method/description";

        private int m_descriptionIndex;

        @Override
        public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
            // description with HTML support
            if (DESCRIPTION_PATTERN.equals(match)) {
                FactoryMethodDescription methodDescription = (FactoryMethodDescription) peek();
                textualDescriptions.put(m_descriptionIndex, methodDescription);
                m_descriptionIndex++;
            }
            // continue
            super.endElement(namespaceURI, localName, qName);
        }
    };
    digester.setLogger(new NoOpLog());
    addRules(digester, state, factoryClass);
    return digester;
}
Also used : Digester(org.apache.commons.digester.Digester) FactoryMethodDescription(org.eclipse.wb.internal.core.model.description.factory.FactoryMethodDescription) NoOpLog(org.apache.commons.logging.impl.NoOpLog)

Example 4 with NoOpLog

use of org.apache.commons.logging.impl.NoOpLog in project elasticsearch-hadoop by elastic.

the class AbstractKerberosClientTest method testProxyKerberosAuth.

@Test
public void testProxyKerberosAuth() throws Exception {
    String hivePrincipal = System.getProperty("tests.hive.principal");
    Assert.hasText(hivePrincipal, "Needs tests.hive.principal system property");
    String hiveKeytab = System.getProperty("tests.hive.keytab");
    Assert.hasText(hiveKeytab, "Needs tests.hive.keytab system property");
    String realUserName = hivePrincipal;
    String proxyUserName = "client";
    // Create a user that the real user will proxy as
    LOG.info("Creating proxied user");
    RestUtils.postData("_security/user/" + proxyUserName, ("{\n" + "  \"enabled\" : true,\n" + "  \"password\" : \"password\",\n" + "  \"roles\" : [ \"superuser\" ],\n" + "  \"full_name\" : \"Client McClientFace\"\n" + "}").getBytes());
    // This just mirrors the superuser role as they can impersonate all users
    LOG.info("Creating proxy role");
    RestUtils.postData("_security/role/proxier", ("{\n" + "  \"cluster\": [\n" + "    \"all\"\n" + "  ],\n" + "  \"indices\": [\n" + "    {\n" + "      \"names\": [\n" + "        \"*\"\n" + "      ],\n" + "      \"privileges\": [\n" + "        \"all\"\n" + "      ],\n" + "      \"allow_restricted_indices\": true\n" + "    }\n" + "  ],\n" + "  \"applications\": [\n" + "    {\n" + "      \"application\": \"*\",\n" + "      \"privileges\": [\n" + "        \"*\"\n" + "      ],\n" + "      \"resources\": [\n" + "        \"*\"\n" + "      ]\n" + "    }\n" + "  ],\n" + "  \"run_as\": [\n" + "    \"*\"\n" + "  ],\n" + "  \"transient_metadata\": {}\n" + "}").getBytes());
    LOG.info("Creating mapping for hive principal to proxier role");
    RestUtils.postData("_security/role_mapping/kerberos_proxy_client_mapping", ("{\"roles\":[\"proxier\"],\"enabled\":true,\"rules\":{\"field\":{\"username\":\"" + realUserName + "\"}}}").getBytes());
    org.apache.hadoop.conf.Configuration configuration = new org.apache.hadoop.conf.Configuration();
    SecurityUtil.setAuthenticationMethod(UserGroupInformation.AuthenticationMethod.KERBEROS, configuration);
    UserGroupInformation.setConfiguration(configuration);
    UserGroupInformation realUser = UserGroupInformation.loginUserFromKeytabAndReturnUGI(hivePrincipal, hiveKeytab);
    UserGroupInformation proxyUser = UserGroupInformation.createProxyUser(proxyUserName, realUser);
    proxyUser.doAs(new PrivilegedExceptionAction<Void>() {

        @Override
        public Void run() throws Exception {
            UserGroupInformation currentUser = UserGroupInformation.getCurrentUser();
            assertEquals("client", currentUser.getUserName());
            assertEquals("hive/build.elastic.co@BUILD.ELASTIC.CO", currentUser.getRealUser().getUserName());
            assertFalse(currentUser.hasKerberosCredentials());
            assertEquals(UserGroupInformation.AuthenticationMethod.PROXY, currentUser.getAuthenticationMethod());
            assertEquals(UserGroupInformation.AuthenticationMethod.KERBEROS, currentUser.getRealAuthenticationMethod());
            Settings testSettings = new TestSettings();
            testSettings.asProperties().remove(ConfigurationOptions.ES_NET_HTTP_AUTH_USER);
            testSettings.asProperties().remove(ConfigurationOptions.ES_NET_HTTP_AUTH_PASS);
            InitializationUtils.setUserProviderIfNotSet(testSettings, HadoopUserProvider.class, new NoOpLog());
            testSettings.setProperty(ConfigurationOptions.ES_SECURITY_AUTHENTICATION, "kerberos");
            testSettings.setProperty(ConfigurationOptions.ES_NET_SPNEGO_AUTH_ELASTICSEARCH_PRINCIPAL, "HTTP/build.elastic.co@BUILD.ELASTIC.CO");
            UserProvider userProvider = UserProvider.create(testSettings);
            assertTrue(userProvider.isEsKerberosEnabled());
            LOG.info("Getting cluster info");
            InitializationUtils.discoverClusterInfo(testSettings, LOG);
            LOG.info("Checking authenticate with Proxied User");
            NetworkClient network = new NetworkClient(testSettings);
            try {
                network.execute(new SimpleRequest(Request.Method.GET, "", "/_security/_authenticate", ""));
            } finally {
                network.close();
            }
            LOG.info("Getting an API Token");
            RestClient client = new RestClient(testSettings);
            EsToken proxyToken;
            try {
                proxyToken = client.createNewApiToken("proxyToken");
            } finally {
                client.close();
            }
            LOG.info("Making another client without the token available yet");
            network = new NetworkClient(testSettings);
            try {
                LOG.info("Checking authenticate to make sure it's still SPNEGO");
                network.execute(new SimpleRequest(Request.Method.GET, "", "/_security/_authenticate", ""));
                LOG.info("Adding token to user now");
                userProvider.getUser().addEsToken(proxyToken);
                LOG.info("Checking authenticate with same client again to make sure it's still SPNEGO");
                network.execute(new SimpleRequest(Request.Method.GET, "", "/_security/_authenticate", ""));
            } finally {
                network.close();
            }
            LOG.info("Making new client to pick up newly added token");
            network = new NetworkClient(testSettings);
            try {
                network.execute(new SimpleRequest(Request.Method.GET, "", "/_security/_authenticate", ""));
            } finally {
                network.close();
            }
            return null;
        }
    });
    RestUtils.delete("_security/role_mapping/kerberos_proxy_client_mapping");
}
Also used : HadoopUserProvider(org.elasticsearch.hadoop.mr.security.HadoopUserProvider) RestClient(org.elasticsearch.hadoop.rest.RestClient) SimpleRequest(org.elasticsearch.hadoop.rest.SimpleRequest) NetworkClient(org.elasticsearch.hadoop.rest.NetworkClient) EsToken(org.elasticsearch.hadoop.security.EsToken) HadoopUserProvider(org.elasticsearch.hadoop.mr.security.HadoopUserProvider) UserProvider(org.elasticsearch.hadoop.security.UserProvider) JdkUserProvider(org.elasticsearch.hadoop.security.JdkUserProvider) TestSettings(org.elasticsearch.hadoop.util.TestSettings) Settings(org.elasticsearch.hadoop.cfg.Settings) TestSettings(org.elasticsearch.hadoop.util.TestSettings) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) NoOpLog(org.apache.commons.logging.impl.NoOpLog) Test(org.junit.Test)

Example 5 with NoOpLog

use of org.apache.commons.logging.impl.NoOpLog in project platform_external_apache-http by android.

the class LogSource method makeNewLogInstance.

/**
 * Create a new {@link Log} implementation, based
 * on the given <i>name</i>.
 * <p>
 * The specific {@link Log} implementation returned
 * is determined by the value of the
 * <tt>org.apache.commons.logging.log</tt> property.
 * The value of <tt>org.apache.commons.logging.log</tt> may be set to
 * the fully specified name of a class that implements
 * the {@link Log} interface.  This class must also
 * have a public constructor that takes a single
 * {@link String} argument (containing the <i>name</i>
 * of the {@link Log} to be constructed.
 * <p>
 * When <tt>org.apache.commons.logging.log</tt> is not set,
 * or when no corresponding class can be found,
 * this method will return a Log4JLogger
 * if the log4j Logger class is
 * available in the {@link LogSource}'s classpath, or a
 * Jdk14Logger if we are on a JDK 1.4 or later system, or
 * NoOpLog if neither of the above conditions is true.
 *
 * @param name the log name (or category)
 */
public static Log makeNewLogInstance(String name) {
    Log log = null;
    try {
        Object[] args = new Object[1];
        args[0] = name;
        log = (Log) (logImplctor.newInstance(args));
    } catch (Throwable t) {
        log = null;
    }
    if (null == log) {
        log = new NoOpLog(name);
    }
    return log;
}
Also used : NoOpLog(org.apache.commons.logging.impl.NoOpLog) NoOpLog(org.apache.commons.logging.impl.NoOpLog)

Aggregations

NoOpLog (org.apache.commons.logging.impl.NoOpLog)11 Digester (org.apache.commons.digester.Digester)4 InputStream (java.io.InputStream)3 ResourceInfo (org.eclipse.wb.internal.core.model.description.resource.ResourceInfo)3 ToolkitDescription (org.eclipse.wb.internal.core.model.description.ToolkitDescription)2 ClassResourceInfo (org.eclipse.wb.internal.core.model.description.resource.ClassResourceInfo)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Rule (org.apache.commons.digester.Rule)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 ComponentDescription (org.eclipse.wb.internal.core.model.description.ComponentDescription)1 IDescriptionProcessor (org.eclipse.wb.internal.core.model.description.IDescriptionProcessor)1 FactoryMethodDescription (org.eclipse.wb.internal.core.model.description.factory.FactoryMethodDescription)1 DesignerException (org.eclipse.wb.internal.core.utils.exception.DesignerException)1 IntrospectionHelper (org.eclipse.wb.internal.core.utils.reflect.IntrospectionHelper)1 EditorState (org.eclipse.wb.internal.core.utils.state.EditorState)1 Settings (org.elasticsearch.hadoop.cfg.Settings)1 HadoopUserProvider (org.elasticsearch.hadoop.mr.security.HadoopUserProvider)1 NetworkClient (org.elasticsearch.hadoop.rest.NetworkClient)1 RestClient (org.elasticsearch.hadoop.rest.RestClient)1 SimpleRequest (org.elasticsearch.hadoop.rest.SimpleRequest)1