스프링 부트 액튜에이터 - LDAP 헬스엔드포인트 투척 NPE
Spring Boot 앱에서는spring-security-ldap
앱에 액세스할 수 있는 사용자를 인증합니다.인증에는 기능적으로 문제가 없지만,/authenticator/health
ldap 에 대해서, 다음의 상태를 취득합니다.
"ldap": {
"status": "DOWN",
"error": "java.lang.NullPointerException: null"
}
이 늘 포인터 예외를 추적하면 이 트레이스를 얻을 수 있습니다.env.put(Context.SECURITY_PRINCIPAL, userDn);
:
java.lang.NullPointerException: null
at java.util.Hashtable.put(Unknown Source) ~[na:1.8.0_111]
at org.springframework.ldap.core.support.SimpleDirContextAuthenticationStrategy.setupEnvironment(SimpleDirContextAuthenticationStrategy.java:42) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.ldap.core.support.AbstractContextSource.setupAuthenticatedEnvironment(AbstractContextSource.java:194) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.ldap.core.support.AbstractContextSource.getAuthenticatedEnv(AbstractContextSource.java:582) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.ldap.core.support.AbstractContextSource.doGetContext(AbstractContextSource.java:134) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.ldap.core.support.AbstractContextSource.getReadOnlyContext(AbstractContextSource.java:158) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.ldap.core.LdapTemplate.executeReadOnly(LdapTemplate.java:802) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.actuate.health.LdapHealthIndicator.doHealthCheck(LdapHealthIndicator.java:46) ~[spring-boot-actuator-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at org.springframework.boot.actuate.health.AbstractHealthIndicator.health(AbstractHealthIndicator.java:43) ~[spring-boot-actuator-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at org.springframework.boot.actuate.health.CompositeHealthIndicator.health(CompositeHealthIndicator.java:68) [spring-boot-actuator-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at org.springframework.boot.actuate.endpoint.HealthEndpoint.invoke(HealthEndpoint.java:81) [spring-boot-actuator-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.getHealth(HealthMvcEndpoint.java:171) [spring-boot-actuator-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(HealthMvcEndpoint.java:145) [spring-boot-actuator-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_111]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_111]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_111]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) [spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) [spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) [spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) [spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) [spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) [spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) [spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635) [tomcat-embed-core-8.5.15.jar:8.5.15]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) [spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) [tomcat-embed-core-8.5.15.jar:8.5.15]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-8.5.15.jar:8.5.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.15.jar:8.5.15]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-embed-websocket-8.5.15.jar:8.5.15]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.15.jar:8.5.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.15.jar:8.5.15]
...
마지막으로 보안 설정은 다음과 같습니다.
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Value("${security.ldap.url}")
private String ldapUrl;
@Value("${security.ldap.user-search-base}")
private String ldapUserSearchBase;
@Value("${security.ldap.group-search-base}")
private String ldapGroupSearchBase;
@Value("${security.ldap.group-role-attribute}")
private String ldapGroupRoleAttribute;
@Value("${security.ldap.authorized-role}")
private String ldapAuthorizedRole;
@Override
protected void configure(HttpSecurity http) throws Exception {
// secure all core/data rest endpoints with basic auth
http.authorizeRequests()
.antMatchers("/core/data/unauthenticated/**").permitAll()
.antMatchers("/core/data/**").hasRole(ldapAuthorizedRole)
.and().httpBasic()
.and().csrf().disable();
// do not create sessions for security
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
@Autowired
public void configure(AuthenticationManagerBuilder auth) throws Exception {
// use ldap as the authentication provider
auth.ldapAuthentication()
.userSearchBase(ldapUserSearchBase)
.userSearchFilter("(uid={0})")
.groupSearchBase(ldapGroupSearchBase)
.groupSearchFilter("uniqueMember={0}")
.groupRoleAttribute(ldapGroupRoleAttribute)
.contextSource()
.url(ldapUrl);
}
}
콘솔에 다음과 같은 메시지가 나타납니다.2017-10-24 12:37:28.867 INFO 12788 --- [ restartedMain] o.s.l.c.support.AbstractContextSource : Property 'userDn' not set - anonymous context will be used for read-write operations
하지만 이것은 우리의 기대이고 우리는 그것을 잘 알고 있다.헬스 엔드 포인트는 이것을 존중하지 않는 것 같습니다.이것이 우리 코드의 버그인지 스프링 부트 자동 설정의 문제인지 알 수 없습니다.
액튜에이터 엔드 포인트의 동작에 대해서는 잘 모르기 때문에, 이것이 명백하다면 사과드립니다.감사합니다!
이것은 수정이 커밋된 spring-ldap 버그입니다만, 메인에 Marge 되어 있지 않은 것 같습니다.spring-ldap
아직 분기하지 않았습니다.
단, 이 속성을 에 추가하는 것을 발견했습니다.application.properties
는 문제를 해결합니다.
management.health.ldap.enabled=false
또 하나의 솔루션은 LDAP Spring 속성에 credential을 입력하여 LDAPAutoConfiguration에 의해 선택되도록 하는 것입니다.
spring.ldap.username=myuser@mydomain.com
spring.ldap.password=secret
spring.ldap.urls=ldap://mydomain.com:389
이렇게 하면 상태 점검을 계속 사용할 수 있습니다.
언급URL : https://stackoverflow.com/questions/46916921/spring-boot-actuator-ldap-health-endpoint-throwing-npe
'programing' 카테고리의 다른 글
파이어베이스 호스팅에 워드프레스를 설치하려면 어떻게 해야 하나요? (0) | 2023.02.15 |
---|---|
spring-boot-starter-web과 spring-boot-starter-web-services 및 spring-boot-starter-jersey의 차이점 (0) | 2023.02.15 |
"오브젝트 리터럴은 알려진 속성만 지정할 수 있습니다"라는 오류가 표시되는 이유는 무엇입니까? (0) | 2023.02.15 |
역직렬화 시 속성 무시 (0) | 2023.02.15 |
워드프레스, 게시물 유형 목록 페이지에 사용자 지정 버튼 추가 (0) | 2023.02.15 |