@Test public void addUser() { UserDO userDO = new UserDO(); userDO.setUsername("test003"); userDO.setPwd("123456"); userDO.setMail("userTest001@qq.com"); userDO.setDisplayName("测试账户"); System.err.println(authService.addUser(userDO)); }
public BusinessWrapper<Boolean> addUser(UserDO userDO) { if (StringUtils.isEmpty(userDO.getUsername())) return new BusinessWrapper<>(ErrorCode.usernameIsNull); UserDO ldapUserDO = getUserByName(userDO.getUsername()); if (ldapUserDO != null) { userDao.saveUserInfo(ldapUserDO); userService.addUserMobile(ldapUserDO.getId()); return new BusinessWrapper<>(true); } else { try { HashMap<String, String> configMap = acqConfigMap(); String userDN = configMap.get(LdapItemEnum.LDAP_USER_DN.getItemKey()); String dn = "cn=" + userDO.getUsername() + "," + userDN; BasicAttribute ocattr = new BasicAttribute("objectClass"); ocattr.add("top"); ocattr.add("person"); ocattr.add("inetorgperson"); ocattr.add("organizationalPerson"); Attributes attrs = new BasicAttributes(); attrs.put(ocattr); attrs.put("cn", userDO.getUsername()); attrs.put("sn", userDO.getUsername()); attrs.put("displayName", userDO.getDisplayName()); attrs.put("mail", userDO.getMail()); attrs.put("userpassword", userDO.getPwd()); ldapFactory.getLdapTemplateInstanceByType(LdapDO.LdapTypeEnum.cmdb.getDesc()).bind(dn, null, attrs); loginCredentialCheck(userDO.getUsername(), userDO.getPwd()); return new BusinessWrapper<>(true); } catch (Exception ex) { ex.printStackTrace(); return new BusinessWrapper<>(ErrorCode.serverFailure); } } }
AuthServiceImpl implements AuthService, InitializingBean { public BusinessWrapper<Boolean> addUser(UserDO userDO) { if (StringUtils.isEmpty(userDO.getUsername())) return new BusinessWrapper<>(ErrorCode.usernameIsNull); UserDO ldapUserDO = getUserByName(userDO.getUsername()); if (ldapUserDO != null) { userDao.saveUserInfo(ldapUserDO); userService.addUserMobile(ldapUserDO.getId()); return new BusinessWrapper<>(true); } else { try { HashMap<String, String> configMap = acqConfigMap(); String userDN = configMap.get(LdapItemEnum.LDAP_USER_DN.getItemKey()); String dn = "cn=" + userDO.getUsername() + "," + userDN; BasicAttribute ocattr = new BasicAttribute("objectClass"); ocattr.add("top"); ocattr.add("person"); ocattr.add("inetorgperson"); ocattr.add("organizationalPerson"); Attributes attrs = new BasicAttributes(); attrs.put(ocattr); attrs.put("cn", userDO.getUsername()); attrs.put("sn", userDO.getUsername()); attrs.put("displayName", userDO.getDisplayName()); attrs.put("mail", userDO.getMail()); attrs.put("userpassword", userDO.getPwd()); ldapFactory.getLdapTemplateInstanceByType(LdapDO.LdapTypeEnum.cmdb.getDesc()).bind(dn, null, attrs); loginCredentialCheck(userDO.getUsername(), userDO.getPwd()); return new BusinessWrapper<>(true); } catch (Exception ex) { ex.printStackTrace(); return new BusinessWrapper<>(ErrorCode.serverFailure); } } } }
AuthServiceImpl implements AuthService, InitializingBean { public BusinessWrapper<Boolean> addUser(UserDO userDO) { if (StringUtils.isEmpty(userDO.getUsername())) return new BusinessWrapper<>(ErrorCode.usernameIsNull); UserDO ldapUserDO = getUserByName(userDO.getUsername()); if (ldapUserDO != null) { userDao.saveUserInfo(ldapUserDO); userService.addUserMobile(ldapUserDO.getId()); return new BusinessWrapper<>(true); } else { try { HashMap<String, String> configMap = acqConfigMap(); String userDN = configMap.get(LdapItemEnum.LDAP_USER_DN.getItemKey()); String dn = "cn=" + userDO.getUsername() + "," + userDN; BasicAttribute ocattr = new BasicAttribute("objectClass"); ocattr.add("top"); ocattr.add("person"); ocattr.add("inetorgperson"); ocattr.add("organizationalPerson"); Attributes attrs = new BasicAttributes(); attrs.put(ocattr); attrs.put("cn", userDO.getUsername()); attrs.put("sn", userDO.getUsername()); attrs.put("displayName", userDO.getDisplayName()); attrs.put("mail", userDO.getMail()); attrs.put("userpassword", userDO.getPwd()); ldapFactory.getLdapTemplateInstanceByType(LdapDO.LdapTypeEnum.cmdb.getDesc()).bind(dn, null, attrs); loginCredentialCheck(userDO.getUsername(), userDO.getPwd()); return new BusinessWrapper<>(true); } catch (Exception ex) { ex.printStackTrace(); return new BusinessWrapper<>(ErrorCode.serverFailure); } } }  }
AuthServiceImpl implements AuthService, InitializingBean { public BusinessWrapper<Boolean> addUser(UserDO userDO) { if (StringUtils.isEmpty(userDO.getUsername())) return new BusinessWrapper<>(ErrorCode.usernameIsNull); UserDO ldapUserDO = getUserByName(userDO.getUsername()); if (ldapUserDO != null) { userDao.saveUserInfo(ldapUserDO); userService.addUserMobile(ldapUserDO.getId()); return new BusinessWrapper<>(true); } else { try { HashMap<String, String> configMap = acqConfigMap(); String userDN = configMap.get(LdapItemEnum.LDAP_USER_DN.getItemKey()); String dn = "cn=" + userDO.getUsername() + "," + userDN; BasicAttribute ocattr = new BasicAttribute("objectClass"); ocattr.add("top"); ocattr.add("person"); ocattr.add("inetorgperson"); ocattr.add("organizationalPerson"); Attributes attrs = new BasicAttributes(); attrs.put(ocattr); attrs.put("cn", userDO.getUsername()); attrs.put("sn", userDO.getUsername()); attrs.put("displayName", userDO.getDisplayName()); attrs.put("mail", userDO.getMail()); attrs.put("userpassword", userDO.getPwd()); ldapFactory.getLdapTemplateInstanceByType(LdapDO.LdapTypeEnum.cmdb.getDesc()).bind(dn, null, attrs); loginCredentialCheck(userDO.getUsername(), userDO.getPwd()); return new BusinessWrapper<>(true); } catch (Exception ex) { ex.printStackTrace(); return new BusinessWrapper<>(ErrorCode.serverFailure); } } }  @Override BusinessWrapper<UserDO> loginCredentialCheck(String username, String password); @Override BusinessWrapper<Boolean> logout(String username); @Override String getUserByToken(String token); @Override BusinessWrapper<Boolean> checkUserHasResourceAuthorize(String token, String resourceName); @Override BusinessWrapper<List<ResourceDO>> checkAndGetUserHasResourceAuthorize(String token, String resourceName, List<String> authGroupList); @Override TableVO<List<ResourceGroupDO>> getResourceGroups(String groupCode, int page, int length); @Override BusinessWrapper<Boolean> saveResourceGroup(ResourceGroupDO resourceGroupDO); @Override BusinessWrapper<Boolean> delResourceGroup(long groupId); @Override TableVO<List<ResourceVO>> getResources(long groupId, String resourceName, int authType, int page, int length); @Override BusinessWrapper<Boolean> saveResource(ResourceVO resourceVO); @Override BusinessWrapper<Boolean> delResource(long resourceId); @Override RoleDO getRoleById(long roleId); @Override TableVO<List<RoleDO>> getRoles(long resourceId, String roleName, int page, int length); @Override BusinessWrapper<Boolean> saveRole(RoleDO roleDO); @Override BusinessWrapper<Boolean> delRole(long roleId); @Override TableVO<List<ResourceVO>> getRoleBindResources(long roleId, long resourceGroupId, int page, int length); @Override TableVO<List<ResourceVO>> getRoleUnbindResources(long roleId, long resourceGroupId, int page, int length); @Override BusinessWrapper<Boolean> roleResourceBind(long roleId, long resourceId); @Override BusinessWrapper<Boolean> roleResourceUnbind(long roleId, long resourceId); @Override TableVO<List<UserVO>> getUsers(String username, long roleId, int page, int length); @Override BusinessWrapper<Boolean> userRoleBind(long roleId, String username); @Override BusinessWrapper<Boolean> userRoleUnbind(long roleId, String username); @Override List<String> getUserGroup(String username); @Override List<Long> getUserGroupIds(String username); @Override List<Long> getUserRoleIds(String username); @Override UserDO getUserByName(String username); @Override List<UserDO> getUsersByRole(long roleId); @Override BusinessWrapper<Boolean> unbindUser(String username); @Override BusinessWrapper<Boolean> delUser(String username); @Override BusinessWrapper<Boolean> leaving(String username); @Override void afterPropertiesSet(); @Override List<String> searchBambooGroupFilter(String username); @Override List<String> searchLdapGroup(String username); @Override boolean isJiraUsers(String username); @Override boolean isConfluenceUsers(String username); @Override boolean isGroupMember(String username, String groupName); @Override BusinessWrapper<Boolean> resetToken(); @Override boolean checkUserInLdapGroup(UserDO userDO, ServerGroupDO serverGroupDO); @Override boolean addMemberToGroup(UserDO userDO, ServerGroupDO serverGroupDO); @Override boolean addMemberToGroup(UserDO userDO, String groupName); boolean checkUserInLdapGroup(UserDO userDO, String groupName); @Override boolean delMemberToGroup(UserDO userDO, ServerGroupDO serverGroupDO); @Override boolean delMemberToGroup(UserDO userDO, String groupName); @Override boolean removeMember2Group(String username, String groupName); @Override BusinessWrapper<Boolean> removeMember2Group(String username); BusinessWrapper<Boolean> addUser(UserDO userDO); @Override BusinessWrapper<Boolean> closeMailAccount(String username); @Override BusinessWrapper<Boolean> activeMailAccount(String username); @Override BusinessWrapper<Boolean> addLdapGroup(String username, String groupname); @Override BusinessWrapper<Boolean> delLdapGroup(String username, String groupname); @Override boolean setMailUserAccountStatus(UserDO userDO, String status); @Override String getMailAccountStatus(String mail); @Override boolean checkUserInLdap(String username); @Override String getAccountLocked(String username); @Override List<String> searchBambooGroup(); @Override List<UserDO> queryUsersByRoleName(String roleName); }
AuthServiceImpl implements AuthService, InitializingBean { public BusinessWrapper<Boolean> addUser(UserDO userDO) { if (StringUtils.isEmpty(userDO.getUsername())) return new BusinessWrapper<>(ErrorCode.usernameIsNull); UserDO ldapUserDO = getUserByName(userDO.getUsername()); if (ldapUserDO != null) { userDao.saveUserInfo(ldapUserDO); userService.addUserMobile(ldapUserDO.getId()); return new BusinessWrapper<>(true); } else { try { HashMap<String, String> configMap = acqConfigMap(); String userDN = configMap.get(LdapItemEnum.LDAP_USER_DN.getItemKey()); String dn = "cn=" + userDO.getUsername() + "," + userDN; BasicAttribute ocattr = new BasicAttribute("objectClass"); ocattr.add("top"); ocattr.add("person"); ocattr.add("inetorgperson"); ocattr.add("organizationalPerson"); Attributes attrs = new BasicAttributes(); attrs.put(ocattr); attrs.put("cn", userDO.getUsername()); attrs.put("sn", userDO.getUsername()); attrs.put("displayName", userDO.getDisplayName()); attrs.put("mail", userDO.getMail()); attrs.put("userpassword", userDO.getPwd()); ldapFactory.getLdapTemplateInstanceByType(LdapDO.LdapTypeEnum.cmdb.getDesc()).bind(dn, null, attrs); loginCredentialCheck(userDO.getUsername(), userDO.getPwd()); return new BusinessWrapper<>(true); } catch (Exception ex) { ex.printStackTrace(); return new BusinessWrapper<>(ErrorCode.serverFailure); } } }  @Override BusinessWrapper<UserDO> loginCredentialCheck(String username, String password); @Override BusinessWrapper<Boolean> logout(String username); @Override String getUserByToken(String token); @Override BusinessWrapper<Boolean> checkUserHasResourceAuthorize(String token, String resourceName); @Override BusinessWrapper<List<ResourceDO>> checkAndGetUserHasResourceAuthorize(String token, String resourceName, List<String> authGroupList); @Override TableVO<List<ResourceGroupDO>> getResourceGroups(String groupCode, int page, int length); @Override BusinessWrapper<Boolean> saveResourceGroup(ResourceGroupDO resourceGroupDO); @Override BusinessWrapper<Boolean> delResourceGroup(long groupId); @Override TableVO<List<ResourceVO>> getResources(long groupId, String resourceName, int authType, int page, int length); @Override BusinessWrapper<Boolean> saveResource(ResourceVO resourceVO); @Override BusinessWrapper<Boolean> delResource(long resourceId); @Override RoleDO getRoleById(long roleId); @Override TableVO<List<RoleDO>> getRoles(long resourceId, String roleName, int page, int length); @Override BusinessWrapper<Boolean> saveRole(RoleDO roleDO); @Override BusinessWrapper<Boolean> delRole(long roleId); @Override TableVO<List<ResourceVO>> getRoleBindResources(long roleId, long resourceGroupId, int page, int length); @Override TableVO<List<ResourceVO>> getRoleUnbindResources(long roleId, long resourceGroupId, int page, int length); @Override BusinessWrapper<Boolean> roleResourceBind(long roleId, long resourceId); @Override BusinessWrapper<Boolean> roleResourceUnbind(long roleId, long resourceId); @Override TableVO<List<UserVO>> getUsers(String username, long roleId, int page, int length); @Override BusinessWrapper<Boolean> userRoleBind(long roleId, String username); @Override BusinessWrapper<Boolean> userRoleUnbind(long roleId, String username); @Override List<String> getUserGroup(String username); @Override List<Long> getUserGroupIds(String username); @Override List<Long> getUserRoleIds(String username); @Override UserDO getUserByName(String username); @Override List<UserDO> getUsersByRole(long roleId); @Override BusinessWrapper<Boolean> unbindUser(String username); @Override BusinessWrapper<Boolean> delUser(String username); @Override BusinessWrapper<Boolean> leaving(String username); @Override void afterPropertiesSet(); @Override List<String> searchBambooGroupFilter(String username); @Override List<String> searchLdapGroup(String username); @Override boolean isJiraUsers(String username); @Override boolean isConfluenceUsers(String username); @Override boolean isGroupMember(String username, String groupName); @Override BusinessWrapper<Boolean> resetToken(); @Override boolean checkUserInLdapGroup(UserDO userDO, ServerGroupDO serverGroupDO); @Override boolean addMemberToGroup(UserDO userDO, ServerGroupDO serverGroupDO); @Override boolean addMemberToGroup(UserDO userDO, String groupName); boolean checkUserInLdapGroup(UserDO userDO, String groupName); @Override boolean delMemberToGroup(UserDO userDO, ServerGroupDO serverGroupDO); @Override boolean delMemberToGroup(UserDO userDO, String groupName); @Override boolean removeMember2Group(String username, String groupName); @Override BusinessWrapper<Boolean> removeMember2Group(String username); BusinessWrapper<Boolean> addUser(UserDO userDO); @Override BusinessWrapper<Boolean> closeMailAccount(String username); @Override BusinessWrapper<Boolean> activeMailAccount(String username); @Override BusinessWrapper<Boolean> addLdapGroup(String username, String groupname); @Override BusinessWrapper<Boolean> delLdapGroup(String username, String groupname); @Override boolean setMailUserAccountStatus(UserDO userDO, String status); @Override String getMailAccountStatus(String mail); @Override boolean checkUserInLdap(String username); @Override String getAccountLocked(String username); @Override List<String> searchBambooGroup(); @Override List<UserDO> queryUsersByRoleName(String roleName); static final String MAIL_ACCOUNT_STATUS_CLOSED; static final String MAIL_ACCOUNT_STATUS_LOCKED; static final String MAIL_ACCOUNT_STATUS_ACTIVE; }