Package org.nutz.ngqa.service

Source Code of org.nutz.ngqa.service.AuthServiceImpl

package org.nutz.ngqa.service;

import java.util.Map;

import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.ngqa.api.AuthService;
import org.nutz.ngqa.api.meta.AuthContext;
import org.nutz.ngqa.bean.Role;
import org.nutz.ngqa.bean.User;

/**鉴权服务*/
@IocBean(name="authService")
public class AuthServiceImpl implements AuthService {

  //检查特定上下文所对应的授权是否合法
  public boolean isAuth(AuthContext authContext) {
    String[] needRoles = authContext.getAuth().value();
    Role[] hasRoles = authContext.getUser().getRoles();
    Map<String, Role> roles = authContext.getRoles();
    for (String roleName : needRoles) {
      Role role = roles.get(roleName);
      for (Role role2 : hasRoles) {
        if (!role.getId().equals(role2.getId()))
          return false;
      }
    }
    return true;
  }

  public boolean addAuth(User user, AuthContext authContext) {
    return false;
  }

  public boolean removeAuth(User user, AuthContext authContext) {
    return false;
  }

}
TOP

Related Classes of org.nutz.ngqa.service.AuthServiceImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.