com.github.houbb.privilege.proxy.support.acquire.PrivilegeAcquireAnnotation Maven / Gradle / Ivy
package com.github.houbb.privilege.proxy.support.acquire;
import com.github.houbb.heaven.annotation.ThreadSafe;
import com.github.houbb.heaven.util.common.ArgUtil;
import com.github.houbb.heaven.util.util.ArrayUtil;
import com.github.houbb.privilege.api.annotation.PrivilegeAcquire;
import com.github.houbb.privilege.api.api.IPrivilegeAcquire;
import com.github.houbb.privilege.api.api.IPrivilegeInfo;
import com.github.houbb.privilege.core.support.info.PrivilegeInfo;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* 权限信息
* @author binbin.hou
* @since 0.0.4
*/
@ThreadSafe
public class PrivilegeAcquireAnnotation implements IPrivilegeAcquire {
/**
* 注解信息
* @since 0.0.4
*/
private final PrivilegeAcquire privilegeAcquire;
public PrivilegeAcquireAnnotation(PrivilegeAcquire privilegeAcquire) {
ArgUtil.notNull(privilegeAcquire, "privilegeAcquire");
this.privilegeAcquire = privilegeAcquire;
}
@Override
public List acquirePrivilege() {
String[] codes = privilegeAcquire.code();
if(ArrayUtil.isEmpty(codes)) {
return Collections.emptyList();
}
List resultList = new ArrayList<>(codes.length);
for(String code : codes) {
IPrivilegeInfo info = PrivilegeInfo.of(code);
resultList.add(info);
}
return resultList;
}
}