Просмотр исходного кода

ldap对接,9.27前问题修复

fangq 4 лет назад
Родитель
Сommit
309eb83458

+ 31 - 0
pom.xml

@@ -235,6 +235,15 @@
                     <version>${spring.boot.version}</version>
                     <configuration>
                         <finalName>${project.build.finalName}</finalName>
+                        <!-- 分包 -->
+                        <layout>ZIP</layout>
+                        <includes>
+                            <include>
+                                <groupId>non-exists</groupId>
+                                <artifactId>non-exists</artifactId>
+                            </include>
+                        </includes>
+                        <!-- 分包 -->
                     </configuration>
                     <executions>
                         <execution>
@@ -268,6 +277,7 @@
                             </goals>
                         </execution>
                     </executions>-->
+
                 </plugin>
             </plugins>
         </pluginManagement>
@@ -288,7 +298,28 @@
                     </compilerArgs>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>copy-dependencies</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>copy-dependencies</goal>
+                        </goals>
+                        <configuration>
+                            <!--target/lib是依赖jar包的输出目录,根据自己喜好配置-->
+                            <outputDirectory>target/lib</outputDirectory>
+                            <excludeTransitive>false</excludeTransitive>
+                            <stripVersion>false</stripVersion>
+                            <includeScope>runtime</includeScope>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
         </plugins>
+
     </build>
 
     <repositories>

+ 7 - 1
src/main/java/org/springblade/bank/keypwd/controller/KeyPwdController.java

@@ -247,12 +247,18 @@ public class KeyPwdController extends BladeController {
 		return R.status(true);
 	}
 
+	/**
+	 * 根據交接日期來排序,判斷最新一條記錄
+	 * @param category
+	 * @param orgNo
+	 * @return
+	 */
 	@GetMapping("/getByCategoryAndType")
 	@ApiOperationSupport(order = 8)
 	@ApiOperation(value = "获取最新一条记录", notes = "传入category,type")
 	public R getByCategoryAndType(@ApiParam(required = true) @RequestParam String category, @ApiParam(required = true) @RequestParam String orgNo){
 		LambdaQueryWrapper<KeyPwd> eq = new QueryWrapper<>(new KeyPwd()).lambda().eq(KeyPwd::getCategory, category)
-			.eq(KeyPwd::getOrgNo, orgNo).orderByDesc(KeyPwd::getFillingDate);
+			.eq(KeyPwd::getOrgNo, orgNo).orderByDesc(KeyPwd::getHandoverDate);
 		List<KeyPwd> list = keyPwdService.list(eq);
 		if (list != null && list.size() > 0){
 			return R.data(list.get(0));

+ 1 - 1
src/main/java/org/springblade/bank/keypwd/mapper/KeyPwdMapper.xml

@@ -57,7 +57,7 @@
                 AND receiver_name like '%${keyPwd.receiverName}%'
             </if>
         </if>
-        ORDER BY create_time DESC
+        ORDER BY handover_date DESC
     </select>
 
 </mapper>

+ 0 - 1
src/main/java/org/springblade/bank/returns/controller/ReturnsController.java

@@ -203,7 +203,6 @@ public class ReturnsController extends BladeController {
 			}
 		}
 
-
 		returns.setProcess(2);
 		boolean save = returnsService.saveOrUpdate(returns);
 		return R.status(save);

+ 7 - 0
src/main/java/org/springblade/bank/sealhandover/controller/SealHandoverController.java

@@ -272,6 +272,13 @@ public class SealHandoverController extends BladeController {
 		return R.status(true);
 	}
 
+	/**
+	 * 根據交接日期來排序,判斷最新一條記錄
+	 * @param sealNo
+	 * @param sealType
+	 * @param orgNo
+	 * @return
+	 */
 	@GetMapping("/getByNoAndType")
 	@ApiOperationSupport(order = 8)
 	@ApiOperation(value = "获取最新一条记录", notes = "传入category,type")

+ 5 - 1
src/main/java/org/springblade/bank/sealhandover/mapper/SealHandoverMapper.xml

@@ -24,6 +24,7 @@
         <result column="remark" property="remark"/>
         <result column="filling_date" property="fillingDate"/>
         <result column="filling_person" property="fillingPerson"/>
+        <result column="is_turn_in" property="isTurnIn"/>
     </resultMap>
 
 
@@ -39,6 +40,9 @@
             <if test="sealHandover.sealNo!=null">
                 AND seal_no = '${sealHandover.sealNo}'
             </if>
+           <if test="sealHandover.isTurnIn!=null">
+                AND is_turn_in = '${sealHandover.isTurnIn}'
+            </if>
             <if test="sealHandover.sealType!=null">
                 AND seal_type in
                 <foreach item="sealType" collection="sealHandover.sealTypes" separator="," open="(" close=")" index="">
@@ -59,7 +63,7 @@
                 AND receiver_name like '%${sealHandover.receiverName}%'
             </if>
         </if>
-        ORDER BY create_time DESC
+        ORDER BY handover_date DESC
     </select>
 
 </mapper>

+ 20 - 0
src/main/java/org/springblade/bank/userlog/mapper/UserLogMapper.xml

@@ -25,6 +25,26 @@
 
     <select id="selectUserLogPage" resultMap="userLogResultMap">
         select * from zh_user_log where is_deleted = 0
+        <if test="userLog!=null">
+            <if test="userLog.orgNo!=null">
+                AND org_no = '${userLog.orgNo}'
+            </if>
+            <if test="userLog.personNo!=null">
+                AND person_no = '${userLog.personNo}'
+            </if>
+            <if test="userLog.tableName!=null">
+                AND table_name = '${userLog.tableName}'
+            </if>
+             <if test="userLog.operationType!=null">
+                AND operation_type = '${userLog.operationType}'
+            </if>
+
+            <if test="userLog.createTime_begin!=null and userLog.createTime_end!=null">
+                and create_time BETWEEN '${userLog.createTime_begin}' and '${userLog.createTime_end}'
+            </if>
+
+        </if>
+        ORDER BY create_time DESC
     </select>
 
 </mapper>

+ 3 - 0
src/main/java/org/springblade/bank/userlog/vo/UserLogVO.java

@@ -33,4 +33,7 @@ import io.swagger.annotations.ApiModel;
 public class UserLogVO extends UserLog {
 	private static final long serialVersionUID = 1L;
 
+	private String createTime_begin;
+	private String createTime_end;
+
 }

+ 0 - 22
src/main/java/org/springblade/ldap/service/LdapService.java

@@ -1,22 +0,0 @@
-package org.springblade.ldap.service;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.ldap.core.LdapTemplate;
-import org.springframework.ldap.filter.EqualsFilter;
-
-public class LdapService {
-
-	/**
-	 * AD认证
-	 *
-	 * @param username 用户名
-	 * @param password 密码
-	 */
-	boolean ldapAuth(String username, String password) {
-		EqualsFilter filter = new EqualsFilter("sAMAccountName", username);
-		return ldapTemplate.authenticate("", filter.toString(), password);
-	}
-
-	@Autowired
-	private LdapTemplate ldapTemplate;
-}

+ 26 - 0
src/main/java/org/springblade/modules/auth/endpoint/BladeTokenEndPoint.java

@@ -16,6 +16,7 @@
  */
 package org.springblade.modules.auth.endpoint;
 
+import cn.hutool.crypto.digest.DigestUtil;
 import com.github.xiaoymin.knife4j.annotations.ApiSort;
 import com.wf.captcha.SpecCaptcha;
 import io.swagger.annotations.Api;
@@ -34,13 +35,18 @@ import org.springblade.core.secure.BladeUser;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tenant.annotation.NonDS;
 import org.springblade.core.tool.support.Kv;
+import org.springblade.core.tool.utils.DesUtil;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.core.tool.utils.WebUtil;
+import org.springblade.modules.auth.ldap.service.LdapService;
 import org.springblade.modules.auth.provider.ITokenGranter;
 import org.springblade.modules.auth.provider.TokenGranterBuilder;
 import org.springblade.modules.auth.provider.TokenParameter;
 import org.springblade.modules.auth.utils.TokenUtil;
 import org.springblade.modules.system.entity.UserInfo;
+import org.springblade.modules.system.service.IParamService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.Assert;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
@@ -64,6 +70,11 @@ public class BladeTokenEndPoint {
 
 	private final BladeRedis bladeRedis;
 	private final JwtProperties jwtProperties;
+	private final IParamService paramService;
+
+	@Autowired
+	private LdapService ldapService;
+
 
 	@ApiLog("登录用户验证")
 	@PostMapping("/oauth/token")
@@ -77,6 +88,21 @@ public class BladeTokenEndPoint {
 		String grantType = WebUtil.getRequest().getParameter("grant_type");
 		String refreshToken = WebUtil.getRequest().getParameter("refresh_token");
 
+		String ldapOpen = paramService.getValue("account.ldapOpen");
+		String decryptFormHex = DesUtil.decryptFormHex(password, "cyzh2020");
+		if (ldapOpen != null && "true".equals(ldapOpen)){
+			System.out.println("decryptFormHex=" + decryptFormHex);
+
+			boolean ldapAuth = ldapService.ldapAuth(username, decryptFormHex);
+//			boolean ldapAuth = false;
+			Assert.isTrue(ldapAuth, "ldap驗證失敗,請確認用戶名和密碼是否正確!");
+			// 用了ldap用戶驗證鑒權之後,系統原鑒權保留,但需要把所有用戶的密碼統一改為123456,統一用此密碼去登錄
+			password = "123456";
+		}else{
+			String passwordMD5 = DigestUtil.md5Hex(decryptFormHex);
+			password = passwordMD5;
+		}
+
 		String userType = Func.toStr(WebUtil.getRequest().getHeader(TokenUtil.USER_TYPE_HEADER_KEY), TokenUtil.DEFAULT_USER_TYPE);
 
 		TokenParameter tokenParameter = new TokenParameter();

+ 1 - 1
src/main/java/org/springblade/ldap/config/LdapConfig.java → src/main/java/org/springblade/modules/auth/ldap/config/LdapConfig.java

@@ -1,4 +1,4 @@
-package org.springblade.ldap.config;
+package org.springblade.modules.auth.ldap.config;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.autoconfigure.ldap.LdapProperties;

+ 26 - 0
src/main/java/org/springblade/modules/auth/ldap/entity/Person.java

@@ -0,0 +1,26 @@
+package org.springblade.modules.auth.ldap.entity;
+
+import lombok.Data;
+import org.springframework.ldap.odm.annotations.Attribute;
+import org.springframework.ldap.odm.annotations.DnAttribute;
+import org.springframework.ldap.odm.annotations.Entry;
+import org.springframework.ldap.odm.annotations.Id;
+
+import javax.naming.Name;
+
+@Entry(base = "ou=people,dc=didispace,dc=com", objectClasses = "inetOrgPerson")
+@Data
+public class Person {
+	@Id
+	private Name id;
+	@DnAttribute(value = "uid")
+	private String uid;
+	@Attribute(name = "cn")
+	private String commonName;
+	@Attribute(name = "sn")
+	private String suerName;
+	private String userPassword;
+	@Attribute(name="ou")
+	private String group;
+
+}

+ 74 - 0
src/main/java/org/springblade/modules/auth/ldap/service/LdapService.java

@@ -0,0 +1,74 @@
+package org.springblade.modules.auth.ldap.service;
+
+import cn.hutool.crypto.digest.DigestUtil;
+import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
+import org.springblade.core.tool.utils.AesUtil;
+import org.springblade.core.tool.utils.DesUtil;
+import org.springblade.modules.auth.ldap.entity.Person;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.ldap.core.LdapTemplate;
+import org.springframework.ldap.filter.EqualsFilter;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+
+import static org.springframework.ldap.query.LdapQueryBuilder.query;
+
+@Service
+public class LdapService {
+
+	@Autowired
+	private LdapTemplate ldapTemplate;
+
+
+
+	/**
+	 * AD认证
+	 *
+	 * @param username 用户名
+	 * @param password 密码
+	 */
+	public boolean ldapAuth(String username, String password) {
+		ldapTemplate.setIgnorePartialResultException(true);
+		EqualsFilter filter = new EqualsFilter("sAMAccountName", username);
+		return ldapTemplate.authenticate("", filter.toString(), password);
+	}
+
+	public List findAll() throws Exception {
+		ldapTemplate.setIgnorePartialResultException(true);
+		return ldapTemplate.findAll(Person.class);
+	}
+
+	public void findAll2(){
+		Person person = ldapTemplate.findOne(query().where("uid").is("ldapuser2"), Person.class);
+		System.out.println(person);
+	}
+
+	public Person create(Person person){
+		ldapTemplate.create(person);
+		return person;
+	}
+
+	public Person findByCn(String cn){
+		String encryptToHex = DesUtil.encryptToHex("admin123", "cyzh2020");
+		System.out.println("encryptToHex=" + encryptToHex);
+
+		String decryptFormHex = DesUtil.decryptFormHex(encryptToHex, "cyzh2020");
+		System.out.println("decryptFormHex=" + decryptFormHex);
+
+		String admin123 = DigestUtil.md5Hex("admin123");
+		System.out.println("md5=" + admin123);
+
+		return ldapTemplate.findOne(query().where("cn").is(cn),Person.class);
+	}
+
+	public Person modifyPerson(Person person){
+		ldapTemplate.update(person);
+		return person;
+	}
+
+	public void deletePerson(Person person){
+		ldapTemplate.delete(person);
+	}
+}

+ 23 - 0
src/main/java/org/springblade/modules/system/controller/UserController.java

@@ -40,12 +40,15 @@ import org.springblade.core.tool.constant.BladeConstant;
 import org.springblade.core.tool.constant.RoleConstant;
 import org.springblade.core.tool.utils.DateUtil;
 import org.springblade.core.tool.utils.StringPool;
+import org.springblade.modules.auth.ldap.entity.Person;
+import org.springblade.modules.auth.ldap.service.LdapService;
 import org.springblade.modules.system.entity.User;
 import org.springblade.modules.system.excel.UserExcel;
 import org.springblade.modules.system.excel.UserImporter;
 import org.springblade.modules.system.service.IUserService;
 import org.springblade.modules.system.vo.UserVO;
 import org.springblade.modules.system.wrapper.UserWrapper;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 import springfox.documentation.annotations.ApiIgnore;
@@ -71,6 +74,8 @@ import static org.springblade.core.cache.constant.CacheConstant.USER_CACHE;
 public class UserController {
 
 	private final IUserService userService;
+	@Autowired
+	private LdapService ldapService;
 
 	/**
 	 * 查询单条
@@ -322,4 +327,22 @@ public class UserController {
 		return R.data(userService.selectUserSearch(user, query));
 	}
 
+	@PostMapping("/testLogin")
+	public R testLogin(User user){
+		boolean b = ldapService.ldapAuth(user.getAccount(), user.getPassword());
+		return R.status(b);
+	}
+
+	@GetMapping("/findAllUser")
+	public R findAllUser() throws Exception {
+		List<Person> all = ldapService.findAll();
+		return R.data(all);
+	}
+
+	@GetMapping("/findByCn")
+	public R findByCn( @RequestParam String cn){
+		Person person = ldapService.findByCn(cn);
+		return R.data(person);
+	}
+
 }

+ 2 - 2
src/main/resources/application-prod.yml

@@ -22,8 +22,8 @@ spring:
   ldap:
     urls: ldap://22.236.1.35:389
     base: DC=mo,DC=ad,DC=boc-ap,DC=com
-    username: ou=acs,ou=componentaccounts,dc=platform,dc=xxxx,dc=com
-    password:
+    username: mosormadm01
+    password: Admin1089
 
 #第三方登陆
 social: