-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Kryo use setRegistrationRequired(true) by default
Signed-off-by: jansupol <[email protected]>
- Loading branch information
Showing
9 changed files
with
226 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...n/java/org/glassfish/jersey/kryo/internal/RegistrationNotRequiredKryoContextResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.jersey.kryo.internal; | ||
|
||
import com.esotericsoftware.kryo.Kryo; | ||
|
||
import javax.ws.rs.ext.ContextResolver; | ||
|
||
/** | ||
* Backwards compatibility ContextResolver. | ||
* It should only be used when the user specifically agrees on a vulnerability provided when the | ||
* <code>KryoFeature#registrationRequired(false)</code> is used. | ||
* The default behaviour is demanded to require {@code ContextResolver} with | ||
* <pre> | ||
* public Kryo getContext(Class<?> type) { | ||
* ... | ||
* Kryo kryo = new Kryo(); | ||
* kryo.setRegistrationRequired(true); | ||
* kryo.register(The_class_for_which_the_KryoMessageBodyProvider_should_be_allowed); | ||
* ... | ||
* return kryo; | ||
* } | ||
* </pre> | ||
*/ | ||
public class RegistrationNotRequiredKryoContextResolver implements ContextResolver<Kryo> { | ||
@Override | ||
public Kryo getContext(Class<?> type) { | ||
return new Kryo(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
incubator/kryo/src/test/java/org/glassfish/jersey/kryo/PersonResourceBaseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.jersey.kryo; | ||
|
||
import org.glassfish.jersey.test.JerseyTest; | ||
import org.junit.Test; | ||
|
||
import javax.ws.rs.client.Entity; | ||
import javax.ws.rs.core.Response; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public abstract class PersonResourceBaseTest extends JerseyTest { | ||
|
||
@Test | ||
public void testGet() { | ||
final Person getResponse = target().request().get(Person.class); | ||
assertEquals("Wolfgang", getResponse.name); | ||
assertEquals(21, getResponse.age); | ||
assertEquals("Salzburg", getResponse.address); | ||
} | ||
|
||
@Test | ||
public void testPost() { | ||
final Person[] testData = new Person[] {new Person("Joseph", 23, "Nazareth"), new Person("Mary", 18, "Nazareth")}; | ||
for (Person original : testData) { | ||
final Person postResponse = target().request() | ||
.post(Entity.entity(original, "application/x-kryo"), Person.class); | ||
assertEquals(original, postResponse); | ||
} | ||
} | ||
|
||
@Test | ||
public void testPut() { | ||
final Response putResponse = target().request().put(Entity.entity(new Person("Jules", 12, "Paris"), | ||
"application/x-kryo")); | ||
assertEquals(204, putResponse.getStatus()); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...yo/src/test/java/org/glassfish/jersey/kryo/PersonResourceRegistrationNotRequiredTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.jersey.kryo; | ||
|
||
import org.glassfish.jersey.client.ClientConfig; | ||
import org.glassfish.jersey.server.ResourceConfig; | ||
import org.glassfish.jersey.test.TestProperties; | ||
|
||
import javax.ws.rs.core.Application; | ||
|
||
public class PersonResourceRegistrationNotRequiredTest extends PersonResourceBaseTest { | ||
@Override | ||
protected Application configure() { | ||
enable(TestProperties.LOG_TRAFFIC); | ||
enable(TestProperties.DUMP_ENTITY); | ||
return new ResourceConfig().register(PersonResource.class).register(KryoFeature.registrationRequired(false)); | ||
} | ||
|
||
@Override | ||
protected void configureClient(final ClientConfig config) { | ||
config.register(KryoFeature.registrationRequired(false)); | ||
} | ||
} |
Oops, something went wrong.