Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create own Jackson module for Spring Boot Admin Server #1404

Merged
merged 2 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
* history mode</a>
*/
public class HomepageForwardingFilter implements Filter {

private static final Logger log = LoggerFactory.getLogger(HomepageForwardingFilter.class);

private final String homepage;
Expand Down Expand Up @@ -79,4 +80,5 @@ public void init(FilterConfig filterConfig) {
@Override
public void destroy() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@
import org.springframework.web.accept.ContentNegotiationManager;
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;

import de.codecentric.boot.admin.server.domain.values.Registration;
import de.codecentric.boot.admin.server.eventstore.InstanceEventStore;
import de.codecentric.boot.admin.server.services.ApplicationRegistry;
import de.codecentric.boot.admin.server.services.InstanceRegistry;
import de.codecentric.boot.admin.server.utils.jackson.RegistrationBeanSerializerModifier;
import de.codecentric.boot.admin.server.utils.jackson.RegistrationDeserializer;
import de.codecentric.boot.admin.server.utils.jackson.SanitizingMapSerializer;
import de.codecentric.boot.admin.server.utils.jackson.AdminServerModule;
import de.codecentric.boot.admin.server.web.ApplicationsController;
import de.codecentric.boot.admin.server.web.InstancesController;
import de.codecentric.boot.admin.server.web.client.InstanceWebClient;
Expand All @@ -48,11 +45,7 @@ public AdminServerWebConfiguration(AdminServerProperties adminServerProperties)

@Bean
public SimpleModule adminJacksonModule() {
SimpleModule module = new SimpleModule();
module.addDeserializer(Registration.class, new RegistrationDeserializer());
module.setSerializerModifier(new RegistrationBeanSerializerModifier(
new SanitizingMapSerializer(this.adminServerProperties.getMetadataKeysToSanitize())));
return module;
return new AdminServerModule(this.adminServerProperties.getMetadataKeysToSanitize());
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2014-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package de.codecentric.boot.admin.server.utils.jackson;

import com.fasterxml.jackson.databind.module.SimpleModule;

import de.codecentric.boot.admin.server.domain.values.Registration;

/**
* Jackson module for Spring Boot Admin Server.
*
* @author Stefan Rempfer
*/
public class AdminServerModule extends SimpleModule {

/**
* Construct the module with a pattern for registration metadata keys. The values of
* the matched metadata keys will be sanitized before serializing to json.
* @param metadataKeyPatterns pattern for metadata keys which should be sanitized
*/
public AdminServerModule(String[] metadataKeyPatterns) {
super(AdminServerModule.class.getName());

addDeserializer(Registration.class, new RegistrationDeserializer());
setSerializerModifier(new RegistrationBeanSerializerModifier(new SanitizingMapSerializer(metadataKeyPatterns)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.json.JSONObject;
import org.junit.Test;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
Expand All @@ -33,10 +32,7 @@ public class RegistrationDeserializerTest {
private final ObjectMapper objectMapper;

public RegistrationDeserializerTest() {
SimpleModule module = new SimpleModule();
module.addDeserializer(Registration.class, new RegistrationDeserializer());
module.setSerializerModifier(
new RegistrationBeanSerializerModifier(new SanitizingMapSerializer(new String[] { ".*password$" })));
AdminServerModule module = new AdminServerModule(new String[] { ".*password$" });
objectMapper = Jackson2ObjectMapperBuilder.json().modules(module).build();
}

Expand Down