2017-12-19 11 views
0

FluentSecurity를 ​​사용하여 권한 부여를 구성하는 ASP.NET MVC 웹 사이트에서 작업하고 있습니다. 이제 현재 사용자가 대상 작업에 액세스 할 수있는 경우에만 표시되는 사용자 정의 ActionLink 도우미가 필요합니다.FluentSecurity 구성에서 정보를 동적으로 추출하십시오.

FluentSecurity Configuration (예 : SecurityConfiguration 클래스 사용)에서 동적으로 알 수있는 방법이 있는지 알고 싶습니다. 현재 로그인 한 사용자가 이름 (문자열)과 컨트롤러 이름 (문자열). FluentSecurity https://github.com/kristofferahl/FluentSecurity의 소스 코드를 보면서 많은 시간을 보냅니다. 그러나 성공하지 못했습니다. 예를 들어

는 :

public bool HasAccess(string controllerName, string actionName) { 
     //code I'm looking for goes here 
} 

답변

0

마지막으로, 나는 나 자신이 다른 도움이 될 수 있습니다 응답 할 것이다.

난 그냥 HandleSecurityAttribute 클래스의 OnAuthorization 메서드를 에뮬레이트합니다. 이 코드는 잘 작동합니다.

public static bool HasAccess(string fullControllerName, string actionName) 
    { 
     ISecurityContext contx = SecurityContext.Current; 
     contx.Data.RouteValues = new RouteValueDictionary(); 

     var handler = new SecurityHandler(); 

     try 
     { 
      var result = handler.HandleSecurityFor(fullControllerName, actionName, contx); 
      return (result == null); 
     } catch (PolicyViolationException) 
     { 
      return false; 
     } 

    }