-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: U…Credentials bean-introspection-module=false
Suppor serialization of UsernamePasswordCredentials for jackson.bean-introspection-module=false
- Loading branch information
Showing
6 changed files
with
121 additions
and
1 deletion.
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
20 changes: 20 additions & 0 deletions
20
test-suite-jackson-databind-bean-introspection-module-false/build.gradle.kts
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,20 @@ | ||
plugins { | ||
id("java-library") | ||
id("io.micronaut.build.internal.security-tests") | ||
} | ||
dependencies { | ||
testAnnotationProcessor(mn.micronaut.inject.java) | ||
testImplementation(libs.junit.jupiter.api) | ||
testImplementation(mnTest.micronaut.test.junit5) | ||
testRuntimeOnly(libs.junit.jupiter.engine) | ||
|
||
testRuntimeOnly(mnLogging.logback.classic) | ||
testImplementation(projects.micronautSecurity) | ||
testImplementation(projects.micronautSecurityJwt) | ||
testImplementation(mn.micronaut.http.client) | ||
testImplementation(mn.micronaut.http.server.netty) | ||
testImplementation(mn.micronaut.jackson.databind) | ||
} | ||
tasks.withType<Test> { | ||
useJUnitPlatform() | ||
} |
40 changes: 40 additions & 0 deletions
40
...d/beanintrospectionfalse/UsernamePasswordCredentialsBeanIntrospectionModuleFalseTest.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,40 @@ | ||
package io.micronaut.security.jacksondatabind.beanintrospectionfalse; | ||
|
||
import io.micronaut.context.annotation.Property; | ||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.core.util.StringUtils; | ||
import io.micronaut.http.HttpRequest; | ||
import io.micronaut.http.client.BlockingHttpClient; | ||
import io.micronaut.http.client.HttpClient; | ||
import io.micronaut.http.client.annotation.Client; | ||
import io.micronaut.security.authentication.AuthenticationRequest; | ||
import io.micronaut.security.authentication.AuthenticationResponse; | ||
import io.micronaut.security.authentication.provider.HttpRequestAuthenticationProvider; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Singleton; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
|
||
@Property(name = "jackson.bean-introspection-module", value = StringUtils.FALSE) | ||
@Property(name = "micronaut.security.token.jwt.signatures.secret.generator.secret", value = "pleaseChangeThisSecretForANewOne") | ||
@Property(name = "micronaut.security.authentication", value = "bearer") | ||
@Property(name = "spec.name", value = "UsernamePasswordCredentialsBeanIntrospectionModuleFalseTest") | ||
@MicronautTest | ||
class UsernamePasswordCredentialsBeanIntrospectionModuleFalseTest { | ||
|
||
@Test | ||
void testUsernamePasswordCredentialsDeserializationIfBeanIntrospectionModuleFalse(@Client("/")HttpClient httpClient) { | ||
BlockingHttpClient client = httpClient.toBlocking(); | ||
assertDoesNotThrow(() -> client.exchange(HttpRequest.POST("/login", "{\"username\":\"sherlock\",\"password\":\"password\"}"))); | ||
} | ||
|
||
@Requires(property = "spec.name", value = "UsernamePasswordCredentialsBeanIntrospectionModuleFalseTest") | ||
@Singleton | ||
static class CustomAuthenticationProvider<B> implements HttpRequestAuthenticationProvider<B> { | ||
@Override | ||
public AuthenticationResponse authenticate(HttpRequest<B> requestContext, AuthenticationRequest<String, String> authRequest) { | ||
return AuthenticationResponse.success("sherlock"); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...naut/security/jacksondatabind/beanintrospectionfalse/UsernamePasswordCredentialsTest.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,41 @@ | ||
package io.micronaut.security.jacksondatabind.beanintrospectionfalse; | ||
|
||
import io.micronaut.context.annotation.Property; | ||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.core.util.StringUtils; | ||
import io.micronaut.http.HttpRequest; | ||
import io.micronaut.http.client.BlockingHttpClient; | ||
import io.micronaut.http.client.HttpClient; | ||
import io.micronaut.http.client.annotation.Client; | ||
import io.micronaut.security.authentication.AuthenticationRequest; | ||
import io.micronaut.security.authentication.AuthenticationResponse; | ||
import io.micronaut.security.authentication.provider.HttpRequestAuthenticationProvider; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Singleton; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
|
||
@Property(name = "micronaut.security.token.jwt.signatures.secret.generator.secret", value = "pleaseChangeThisSecretForANewOne") | ||
@Property(name = "micronaut.security.authentication", value = "bearer") | ||
@Property(name = "spec.name", value = "UsernamePasswordCredentialsTest") | ||
@MicronautTest | ||
class UsernamePasswordCredentialsTest { | ||
|
||
@Test | ||
void testUsernamePasswordCredentialsDeserializationIfBeanIntrospectionModuleFalse(@Client("/") HttpClient httpClient) { | ||
BlockingHttpClient client = httpClient.toBlocking(); | ||
String json = """ | ||
{"username":"sherlock","password":"password"}"""; | ||
assertDoesNotThrow(() -> client.exchange(HttpRequest.POST("/login", json))); | ||
} | ||
|
||
@Requires(property = "spec.name", value = "UsernamePasswordCredentialsTest") | ||
@Singleton | ||
static class CustomAuthenticationProvider<B> implements HttpRequestAuthenticationProvider<B> { | ||
@Override | ||
public AuthenticationResponse authenticate(HttpRequest<B> requestContext, AuthenticationRequest<String, String> authRequest) { | ||
return AuthenticationResponse.success("sherlock"); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
test-suite-jackson-databind-bean-introspection-module-false/src/test/resources/logback.xml
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,11 @@ | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
<root level="info"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
<logger name="io.micronaut.http.client" level="TRACE"/> | ||
</configuration> |