Wednesday, 21 August 2019

Is H2 Accessing filtered out???


2019-08-20 23:46:55.835  INFO 17304 --- [  restartedMain] pertySourcedRequestMappingHandlerMapping : Mapped URL path [/v2/api-docs] onto method [public org.springframework.http.ResponseEntity springfox.documentation.swagger2.web.Swagger2Controller.getDocumentation(java.lang.String,javax.servlet.http.HttpServletRequest)]
2019-08-20 23:46:56.231  INFO 17304 --- [  restartedMain] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher@1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@626f6b95, org.springframework.security.web.context.SecurityContextPersistenceFilter@18dc3684, org.springframework.security.web.header.HeaderWriterFilter@c731e97, org.springframework.security.web.authentication.logout.LogoutFilter@70ed9554, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@332ce77b, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@27720351, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@70321b31, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@72cf2f4, org.springframework.security.web.session.SessionManagementFilter@600eb289, org.springframework.security.web.access.ExceptionTranslationFilter@b28bf68, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@783b78d]
2019-08-20 23:46:56.234  INFO 17304 --- [  restartedMain] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: Ant [pattern='/h2/**'], [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@1bdf7eab, org.springframework.security.web.context.SecurityContextPersistenceFilter@737f3bd, org.springframework.security.web.header.HeaderWriterFilter@ecd60f, org.springframework.security.web.authentication.logout.LogoutFilter@13670ab, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@39a4d12b, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@27a48a12, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@411e6c47, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@32643e76, org.springframework.security.web.session.SessionManagementFilter@bc96433, org.springframework.security.web.access.ExceptionTranslationFilter@1aa74293, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@6c7ee478]
2019-08-20 23:46:56.261  INFO 17304 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]

Tuesday, 20 August 2019

How to setup H2 web console in SpringBoot

Springboot may auto-config H2 database, once it sees the dependency in the classpath.

How to set up the H2 database virtual console in Spring boot, to show H2 tables in a browser.

Go to the resource folder,  and add the following in the property file

spring.h2.console.enabled=true

thus h2 browser console will be enabled.

You may specify h2 console path
spring.h2.console.path=/h2

otherwise, the default will be /h2-console

spring-boot will config the database driver by default
Driver class: org.h2.Driver

You need to specify the JDBC URL for the project
spring.datasource.url= jdbc:h2:file:~/dev-db

Otherwise, the default value will be
JDBC URL:  jdbc url:  jdbc:h2:~/test

It may also specify username and password
spring.datasource.usename = xxx
spring.datasource.password = yyy

link to the URL: localhost:8080/h2

you will see the login console.

Click button 'connect', it shows the database management tool in the browser.






Sunday, 4 August 2019

Escaping refeences

Escaping references is a way to protect the data from being polluted.

fx: when returning a list of users from a class; even the list is encapsulated, but the reference to the list may be exposed to external after returning the same list to the external. On the case, the content may be modified by an external process.

There are two ways to escape the reference:
1. not returning an instance reference directly; fx. returning un-modified collections(immutable).
2. using the interface to customise the data model that is only readable.

How javax.inject.provider autowired in Spring

When moving a legacy code from the Guice to Spring boot, how to handle the injection of javax.inject.Provider ?  

Spring implements JSR 330 staring from Spring 3.0; the javax.inject annotations are supported too in the spring.

It seems that Autowire and Inject are doing the same in the spring;
So it looks that when auto-wiring a Provider, it should return a T type instance(scope = prototype? )

needs to go further to know


Spring - Using JSR 330 Provider to Inject Narrower Scoped Bean

Can Jackson Deserialize Java Time ZonedDateTime

Yes, but must include JSR310. Thus ZonedDateTime can be deserialized directly from JSON response to POJO field. <dependency> <g...