Class: acl

acl

new acl(opts)

acl对象
Name Type Description
opts Object 配置属性 格式:{uri:'网络地址'}

Methods

addUserRoles(opts, cb)

添加用户角色
Name Type Default Description
opts Object {} optional 参数
cb callback function(err,doc){} optional 回调
Examples
opts参数:{
 token: 用户令牌(必填)
 id: 用户ObjectId(必填)
 role: 角色数组(必填)
}
cb参数格式:
成功响应:
doc: {
}
错误响应:
doc: {
 err: 错误码,
 msg: 错误信息
}

filter(opts, cb)

过滤效验
Name Type Default Description
opts Object {} optional 参数
cb callback function(err,doc){} optional 回调
Examples
opts参数:{
 token: 用户令牌(可选)
 path: 请求路径(可选, 默认'')
 method: 请求类型(可选, 默认'')
}
cb参数格式:
成功响应:
doc: {
 id: '用户id',
 token: '经验证后的token',
 userRoles: '(数组)该用户拥有的角色',
 permissions: '(数组)该用户拥有的权限',
 resource: '对应的资源'
}
错误响应:
doc: {
 err: 错误码,
 msg: 错误信息
}

initPermissions(opts, cb)

初始化权限
Name Type Default Description
opts Object {} optional 参数
cb callback function(err,doc){} optional 回调
Examples
opts参数:{
 token: 用户令牌(可选)
 json: 资源配置(可选)
}
cb参数格式:
成功响应:
doc: {
}
错误响应:
doc: {
 err: 错误码,
 msg: 错误信息
}

initResources(opts, cb)

初始化资源
Name Type Default Description
opts Object {} optional 参数
cb callback function(err,doc){} optional 回调
Examples
opts参数:{
 token: 用户令牌(可选)
 json: 资源配置(可选)
}
cb参数格式:
成功响应:
doc: {
}
错误响应:
doc: {
 err: 错误码,
 msg: 错误信息
}

removeUserRoles(opts, cb)

删除用户角色
Name Type Default Description
opts Object {} optional 参数
cb callback function(err,doc){} optional 回调
Examples
opts参数:{
 token: 用户令牌(必填)
 id: 用户ObjectId(必填)
 role: 角色数组(必填)
}
cb参数格式:
成功响应:
doc: {
}
错误响应:
doc: {
 err: 错误码,
 msg: 错误信息
}

userPermissions(opts, cb)

获取用户权限
Name Type Default Description
opts Object {} optional 参数
cb callback function(err,doc){} optional 回调
Examples
opts参数:{
 token: 用户令牌(可选)
 userId: 用户ObjectId(可选)
 resource: 资源数组(可选)
}
cb参数格式:
成功响应:
doc: {
 '对应的资源': ['权限']
}
错误响应:
doc: {
 err: 错误码,
 msg: 错误信息
}

userRoles(opts, cb)

获取用户拥有的角色
Name Type Default Description
opts Object {} optional 参数
cb callback function(err,doc){} optional 回调
Examples
opts参数:{
 token: 用户令牌(可选)
 id: 用户ObjectId(必填)
}
cb参数格式:
成功响应:
doc: {
 roles: ['角色']
}
错误响应:
doc: {
 err: 错误码,
 msg: 错误信息
}