若依是一套基於Spring Cloud和Vue前後端分離的許可權管理系統,其文檔詳細介紹了若依的功能與使用方法,本文將從多個方面對若依文檔進行詳解。
一、快速開始
若依文檔提供了詳細的快速開始指南,可以幫助開發者快速了解若依的使用方法。
在快速開始指南中,首先介紹了若依需要的環境和依賴,包括Java 8、Maven 3.3+、MySQL 5.7+等,具體介紹了如何在本地搭建開發環境。
接著,文檔介紹了如何下載若依源代碼,並進行編譯和運行。文檔給出了詳細的步驟和截圖,方便開發者進行實踐。
cd whvn-auth-system
mvn clean package -DskipTests
java -jar whvn-auth-system/whvn-auth-system.jar
除了以上內容,快速開始指南還介紹了如何使用Postman進行介面測試以及如何在IDE中進行調試等。
二、系統管理
系統管理是若依的核心功能之一,主要包括用戶管理、角色管理、菜單管理、部門管理等,若依文檔對這些功能都進行了詳細的介紹。
例如,在用戶管理方面,文檔詳細介紹了如何進行用戶的增刪改查、如何為用戶分配角色等,同時還介紹了如何通過Excel批量導入用戶。
/**
* 保存用戶信息
*/
@PreAuthorize("@ss.hasPermi('system:user:add')")
@PostMapping
public AjaxResult add(@Validated @RequestBody SysUser user)
{
if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user.getUserName())))
{
return AjaxResult.error("新增用戶'" + user.getUserName() + "'失敗,登錄賬號已存在");
}
else if (UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
{
return AjaxResult.error("新增用戶'" + user.getUserName() + "'失敗,手機號碼已存在");
}
else if (UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
{
return AjaxResult.error("新增用戶'" + user.getUserName() + "'失敗,郵箱賬號已存在");
}
user.setSalt(ShiroUtils.randomSalt());
user.setPassword(passwordService.encryptPassword(user.getUserName(), user.getPassword(), user.getSalt()));
return toAjax(userService.insertUser(user));
}
類似的,菜單管理、角色管理、部門管理等功能也都有詳細的介紹和代碼示例。
三、安全管理
若依文檔也重點介紹了安全管理方面的內容,包括用戶認證、API介面安全等。
對於用戶認證,若依採用了Shiro框架,文檔介紹了如何進行自定義Realm以及如何實現多種認證方式等。
public class UserRealm extends AuthorizingRealm
{
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals)
{
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
SysUser user = ShiroUtils.getSysUser();
// 獲取角色集合
Set<String> roles = roleService.selectRoleKeys(user.getUserId());
authorizationInfo.setRoles(roles);
// 獲取許可權集合
Set<String> perms = menuService.selectPermsByUserId(user.getUserId());
authorizationInfo.setStringPermissions(perms);
return authorizationInfo;
}
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException
{
String username = (String)token.getPrincipal();
String password = new String((char[])token.getCredentials());
SysUser user = userService.selectUserByUserName(username);
if (user == null)
{
throw new UnknownAccountException("用戶不存在");
}
if (!passwordService.matches(user, password))
{
throw new IncorrectCredentialsException("密碼不正確");
}
if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
{
throw new LockedAccountException("用戶已被刪除");
}
return new SimpleAuthenticationInfo(user, password, getName());
}
}
在API介面安全方面,若依文檔詳細介紹了如何使用Spring Security進行API介面的安全控制,包括如何設置跨域、如何進行用戶認證、如何進行介面許可權控制等。
四、前端開發
若依採用了Vue.js作為前端框架,文檔也有詳細的介紹和代碼示例。主要包括如何使用Vue Router、如何使用Element UI等。
export default [
{
path: '/login',
component: () => import('@/views/login/index'),
hidden: true,
meta: { title: '登錄' }
},
{
path: '/',
component: Layout,
redirect: '/dashboard',
children: [
{
path: 'dashboard',
component: () => import('@/views/dashboard/index'),
name: 'Dashboard',
meta: { title: '首頁', icon: 'dashboard', affix: true }
}
]
},
{
path: '/system',
component: Layout,
redirect: '/system/user',
name: 'System',
meta: { title: '系統管理', icon: 'system' },
children: [
{
path: 'user',
component: () => import('@/views/system/user/index'),
name: 'User',
meta: { title: '用戶管理', icon: 'user' }
},
{
path: 'role',
component: () => import('@/views/system/role/index'),
name: 'Role',
meta: { title: '角色管理', icon: 'peoples' }
},
{
path: 'menu',
component: () => import('@/views/system/menu/index'),
name: 'Menu',
meta: { title: '菜單管理', icon: 'tree-table' }
}
]
}
]
類似的,文檔還介紹了如何進行前後端聯調、如何進行許可權控制等內容。
原創文章,作者:ZIVGE,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/370173.html