diff --git a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/config/LdapConfiguration.java b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/config/LdapConfiguration.java index 1932878d..c917d5d0 100644 --- a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/config/LdapConfiguration.java +++ b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/config/LdapConfiguration.java @@ -54,7 +54,7 @@ public class LdapConfiguration { contextSource.setBase(base); contextSource.setUserDn(username); contextSource.setPassword(password); - // fix garbled characters + // fix garbled characters config.put("java.naming.ldap.attributes.binary", "objectGUID"); contextSource.setPooled(true); diff --git a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/LdapAuthenticationFilter.java b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/LdapAuthenticationFilter.java index 9ce982a3..1b86b34f 100644 --- a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/LdapAuthenticationFilter.java +++ b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/LdapAuthenticationFilter.java @@ -73,14 +73,12 @@ public class LdapAuthenticationFilter extends UsernamePasswordAuthenticationFilt */ private boolean postOnly = true; - /** * filter obtains the username and password of LDAP and assembles it on the token. * Then give the token for authorization */ @Override - public Authentication attemptAuthentication(HttpServletRequest request - , HttpServletResponse response) throws AuthenticationException { + public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { if (postOnly && !"POST".equals(request.getMethod())) { throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); } else { diff --git a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/model/LdapUserInfo.java b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/model/LdapUserInfo.java index 9a09c0b8..69bd1a27 100644 --- a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/model/LdapUserInfo.java +++ b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/model/LdapUserInfo.java @@ -1,3 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 cn.hippo4j.auth.model; import com.fasterxml.jackson.annotation.JsonIgnore; diff --git a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/LdapService.java b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/LdapService.java index 823286d3..4fd8d860 100644 --- a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/LdapService.java +++ b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/LdapService.java @@ -21,6 +21,7 @@ package cn.hippo4j.auth.service; * Ldap service. */ public interface LdapService { + /** * Login ldap */ diff --git a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/LdapServiceImpl.java b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/LdapServiceImpl.java index bb43be02..1f03ee59 100644 --- a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/LdapServiceImpl.java +++ b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/LdapServiceImpl.java @@ -52,9 +52,8 @@ public class LdapServiceImpl implements LdapService { public void login(String username, String password) { try { ldapTemplate.authenticate(LdapQueryBuilder.query() - .where(accountAttribute).is(username) - .and(query().where("objectClass").is(objectClassName)) - , password); + .where(accountAttribute).is(username) + .and(query().where("objectClass").is(objectClassName)), password); log.debug("{} ldap Login successful", username); } catch (EmptyResultDataAccessException e) { throw new UsernameNotFoundException("ldap Can't find the user information "); diff --git a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/LdapUserDetailsServiceImpl.java b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/LdapUserDetailsServiceImpl.java index ee5411f1..a66a4872 100644 --- a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/LdapUserDetailsServiceImpl.java +++ b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/LdapUserDetailsServiceImpl.java @@ -70,8 +70,7 @@ public class LdapUserDetailsServiceImpl implements UserDetailsService { ldapService.login(userName, loginUser.getPassword()); // By querying the data inventory this user does not exist UserInfo userInfo = userMapper.selectOne(Wrappers.lambdaQuery(UserInfo.class) - .eq(UserInfo::getUserName, userName) - ); + .eq(UserInfo::getUserName, userName)); // the database does not, create a ROLE_USER permission to the default user, password is empty if (Objects.isNull(userInfo)) { userInfo = new UserInfo(); diff --git a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/UserDetailsServiceImpl.java b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/UserDetailsServiceImpl.java index 960c25ab..5029024c 100644 --- a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/UserDetailsServiceImpl.java +++ b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/UserDetailsServiceImpl.java @@ -64,8 +64,7 @@ public class UserDetailsServiceImpl implements UserDetailsService { LoginUser loginUser = (LoginUser) request.getAttribute("loginUser"); String loginPassword = loginUser.getPassword(); UserInfo userInfo = userMapper.selectOne(Wrappers.lambdaQuery(UserInfo.class) - .eq(UserInfo::getUserName, userName) - ); + .eq(UserInfo::getUserName, userName)); if (Objects.isNull(userInfo)) { throw new UsernameNotFoundException(userName); } diff --git a/threadpool/server/auth/src/test/java/cn/hippo4j/auth/toolkit/BCryptPasswordEncoderTest.java b/threadpool/server/auth/src/test/java/cn/hippo4j/auth/toolkit/BCryptPasswordEncoderTest.java index f1d8a24b..fe0d3195 100644 --- a/threadpool/server/auth/src/test/java/cn/hippo4j/auth/toolkit/BCryptPasswordEncoderTest.java +++ b/threadpool/server/auth/src/test/java/cn/hippo4j/auth/toolkit/BCryptPasswordEncoderTest.java @@ -1,3 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 cn.hippo4j.auth.toolkit; import cn.hippo4j.common.toolkit.Assert;