我正在尝试使用SpringBoot使用LDAP进行身份验证,但我在命名异常时出错,我是新手,但我看到了这篇文章,这篇文章使用spring LDAP API使用LDAP进行身份验证,而不使用spring security
pom.xml
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
</dependency> -> 2.3.2
@Configuration
public class LdapConfig {
/** The ldap url. */
@Value("${ldap.url}")
private String ldapUrl; // ldap://MYCOMPANY.com:389
/** The ldap access password. */
@Value("${ldap.password}")
private String ldapAccessPassword; // Password to access LDAP
/** The ldap U base user. */
@Value("${ldap.base}")
private String ldapUBaseUser; // OU=USERS,OU=ACCOUNTS,DC=rg,DC=MYCOMPANY,DC=com
/**
* Context source.
*
* @return the ldap context source
*/
@Bean
public LdapContextSource contextSource() {
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl(ldapUrl);
contextSource.setPassword(ldapAccessPassword);
contextSource.setBase(ldapUBaseUser);
return contextSource;
}
/**
* Ldap template.
*
* @return the ldap template
*/
@Bean
public LdapTemplate ldapTemplate() {
return new LdapTemplate(contextSource());
}
}
@Autowired
private LdapTemplate ldapTemplate;
@Value("${ldap.base}")
private String base; // WHY DO I REPEAT THIS VALUE ??? In my @configuration I especified the base
public boolean existUser(String usr, String pwd) {
try {
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("mailNickname", usr));
Boolean authenticate = ldapTemplate.authenticate(base, filter.encode(), pwd);
boolean result = authenticate.booleanValue();
if(!result) {
LOGGER.info("The: " + usr + " , is failed.");
}
return result;
} catch (Exception e) {
LOGGER.error("Error existUser() --> " +e);
e.printStackTrace();
return false;
}
}
最后,我用user和password调用我的方法existUser()作为前端,我需要知道这个user/password是否存在于LDAP中,但是我得到了这个错误:
12-02-2020 09:03:27.821 [http-nio-80-exec-5] ERROR e.c.service.impl.LoginServiceImp.existUser -Error existUser() --> org.springframework.ldap.UncategorizedLdapException: Uncategorized exception occured during LDAP processing; nested exception is javax.naming.NamingException: [LDAP: e rror code 1 - 000004DC: LdapErr: DSID-0C0907C2, comment: In order to perform this operation a s uccessful bind must be completed on the connection., data 0, v2580]; remaining name 'OU=USERS,O U=ACCOUNTS,DC=rg,DC=MYCOMPANY,DC=com'
org.springframework.ldap.UncategorizedLdapException: Uncategorized exception occured during LDAP processing; nested exception is javax.naming.NamingException: [LDAP: error code 1 - 000004DC:LdapErr: DSID-0C0907C2, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v2580]; remaining name 'OU=USERS,OU=ACCOUNTS,DC=rg,DC=rep sol,DC=com'
at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:228)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:397)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:309)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:642)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:578)
at org.springframework.ldap.core.LdapTemplate.authenticate(LdapTemplate.java:1441)
at org.springframework.ldap.core.LdapTemplate.authenticate(LdapTemplate.java:1426)
at org.springframework.ldap.core.LdapTemplate.authenticate(LdapTemplate.java:1369)
at es.MYPROJECT.service.impl.LoginServiceImp.existUser(LoginServiceImp.java:29)
at es.MYPROJECT.controller.LoginController.login(LoginController.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43 )
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHand lerMethod.java:205)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(Invoc ableHandlerMethod.java:133)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod. invokeAndHandle(ServletInvocableHandlerMethod.java:97)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.i nvokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.h andleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(Abstr actHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java: 967)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:9 01)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.jav a:970)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCh ain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java :166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCh ain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java :166)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:317)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(Exceptio nTranslationFilter.java:114)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionMan agementFilter.java:137)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilt er(AnonymousAuthenticationFilter.java:111)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter. doFilter(SecurityContextHolderAwareRequestFilter.java:170)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(Reque stCacheAwareFilter.java:63)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutF ilter.java:116)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.ja va:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWr iterFilter.java:64)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.ja va:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(S ecurityContextPersistenceFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFil ter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.ja va:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy. java:214)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177 )
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilter Proxy.java:347)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy. java:263)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCh ain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java :166)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextF ilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.ja va:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCh ain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java :166)
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutForm ContentFilter.java:108)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.ja va:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCh ain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java :166)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMet hodFilter.java:81)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.ja va:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCh ain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java :166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEnc odingFilter.java:197)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.ja va:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCh ain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java :166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:50 4)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:7 90)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: javax.naming.NamingException: [LDAP: error code 1 - 000004DC: LdapErr: DSID-0C0907C2 , comment: In order to perform this operation a successful bind must be completed on the connec tion., data 0, v2580]; remaining name 'OU=USERS,OU=ACCOUNTS,DC=rg,DC=MYCOMPANY,DC=com'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3194)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3100)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2891)
at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1846)
at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1769)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:392)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContex t.java:358)
at javax.naming.directory.InitialDirContext.search(InitialDirContext.java:276)
at org.springframework.ldap.core.LdapTemplate$3.executeSearch(LdapTemplate.java:303)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:363)
... 92 more
谢了。
在执行搜索操作之前,需要进行身份验证(绑定)。您需要将contextsource.setuserdn(“userdn”);
添加到ldapcontextsource,或者尝试:
/**
* this method is used to verify and authenticate the user.
*
* @param login user's login
* @param password user's password
*/
public void verifyCredentials(String login, String password)
{
LdapQuery query = LdapQueryBuilder.query().where("cn").is(login);
ldapTemplate.authenticate(query, password);
}
接口说明 验证验证码 如需调用,请访问 开发者文档 来查看详细的接口使用说明 该接口仅开放给已获取SDK的开发者 如开启https功能,请求地址的协议应改为https,如:https://www.example.com/wish3dearth/api/access/v1.0.0/getLicenseInfo API地址 GET /authcenter/api/verify/v1.0.0/check
我需要应用一个双值验证,这需要与圆周率匹配。我正在考虑使用@pattern(regex=“3.14159265359”)。这是使用Hibernate验证约束应用这样一个约束的最佳方式吗?谢谢
我现在把这两者搞混了。我知道Hibernate Validator6是Bean验证2.0规范的参考实现。它支持分组、错误消息国际化、自定义方法验证等。问题是Spring5支持这些特性还是我只剩下Hibernate Validator6了? 网上所有的参考例子都建议使用Hibernate验证器,没有什么关于Spring验证的发现,请建议或指向其他链接。
我有以下场景:我正在尝试处理一个表单,模型属性是一个具有String和Long属性的bean。众所周知,bean验证提供了很多注释来帮助我们确定数据的有效性。我面临的是,对于Long属性的情况,我只能使用@NotNull和另一个注释(我不记得它的名字)来强制用户输入正数。如果用户输入例如“sdf”,应用程序会抛出一个BIG异常。所以我想知道的是,如果用户在爆炸前输入了一个数字(因为我不能使用@Pa
我刚接触vee validate。我想知道您如何验证按钮是否已按下。我已经用ValidationObserver包装了我的表单,其中有一个v形槽无效。我希望用户被要求选择一个按钮,这将允许用户继续到下一页。 代码验证观察员,我包装我的表单: 下面的代码是我需要知道如何设置用户从列表中选择按钮所需的验证。 和结束我的形式我有按钮,允许用户继续。该按钮将被禁用,直到表单完成并且没有验证错误。但我也想确
我已经使用extend from创建了自定义规则。所以我有这个 当为false且为true时,从上述代码中,它会被上一条规则覆盖,因此结果始终被视为true而不是false 那么我如何才能做到这一点呢? 规则: