Example usage for java.net URLStreamHandler getClass

List of usage examples for java.net URLStreamHandler getClass

Introduction

In this page you can find the example usage for java.net URLStreamHandler getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:jenkins.security.Security637Test.java

@Test
@Issue("SECURITY-637")
public void urlSafeDeserialization_inXStreamContext() {
    rr.addStep(new Statement() {
        @Override//from w ww .  ja  v a 2 s .c  o m
        public void evaluate() throws Exception {
            FreeStyleProject project = rr.j.createFreeStyleProject("project-with-url");
            URLJobProperty URLJobProperty = new URLJobProperty(
                    // url to be wrapped
                    new URL("https://www.google.com/"),
                    // safe url, not required to be wrapped
                    new URL("https", null, -1, "", null));
            project.addProperty(URLJobProperty);

            project.save();
        }
    });

    rr.addStep(new Statement() {
        @Override
        public void evaluate() throws Exception {
            FreeStyleProject project = rr.j.jenkins.getItemByFullName("project-with-url",
                    FreeStyleProject.class);
            assertNotNull(project);

            Field handlerField = URL.class.getDeclaredField("handler");
            handlerField.setAccessible(true);

            URLJobProperty urlJobProperty = project.getProperty(URLJobProperty.class);
            for (URL url : urlJobProperty.urlSet) {
                URLStreamHandler handler = (URLStreamHandler) handlerField.get(url);
                if (StringUtils.isEmpty(url.getHost())) {
                    assertThat(handler.getClass().getName(), not(containsString("SafeURLStreamHandler")));
                } else {
                    assertThat(handler.getClass().getName(), containsString("SafeURLStreamHandler"));
                }
            }
        }
    });
}