Skip to content

Commit

Permalink
Create own Jackson module for Spring Boot Admin Server (codecentric#1404
Browse files Browse the repository at this point in the history
)

* Fix code style issue

* Create own Jackson module for Spring Boot Admin Server

preparation for codecentric#1348
  • Loading branch information
srempfer authored Apr 27, 2020
1 parent 31537a4 commit 53ce34a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
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

0 comments on commit 53ce34a

Please sign in to comment.