2014-12-24 4 views
2

내 프로젝트의 보안 필터를 만들려고합니다. 나는 if !session.user then redirect to action error을 확인한다. 요점은 session.usercontroller 'installation'action 'index'에서 생성되는 것입니다 그러나Grails 보안은 하나만 제외하고 모든 작업을 필터링합니다.

all(controller: 'accounting|installation|installer|sales|service|serviceOrder|document', action: '*') { 
      before = { 
       if (!session.user) { 
        redirect(controller: 'installation', action: 'errors') 
        return false 
       } 
      } 
      after = { Map model -> 

      } 
      afterView = { Exception e -> 

      } 
     } 

: 여기에 내 현재 코드입니다. 그렇다면 index action없이 어떻게 필터링 할 수 있습니까? 제안 사항을 보내 주시면 감사하겠습니다. 감사.

+0

Blog를 볼 ?? – Abs

+0

그래, 그게 전부 야. –

답변

1

all(controller: 'accounting|installation|installer|sales|service|serviceOrder|document', action: '*') { 
     before = { 
     if (!(controllerName == 'installation' && actionName == 'index')) { 
      if (!session.user) { 
       redirect(controller: 'installation', action: 'errors') 
       return false 
      } 
      } 
     } 
     after = { Map model -> 

     } 
     afterView = { Exception e -> 

     } 
    } 
+0

여러분의 해결책을 시도하고이 메시지를 받았습니다 :'Firefox가 서버가이 주소에 대한 요청을 결코 완료하지 않을 방법으로 리디렉션 중임을 발견했습니다. 때때로이 문제는 쿠키를 사용하지 않거나 거부함으로써이 문제가 발생할 수 있습니다. ' –

+0

브라우저에서 쿠키를 사용하도록 설정 : https://support.mozilla.org/en-US/kb/enable-and-disable-cookies-website-preferences –

0

희망은 당신이 다음 액션 인덱스를 제외하려는 때문에, 이것을 시도, 질문을 이해 ... 당신은 invert:true 을 사용할 수 있습니다

all(controller: 'accounting|installation|installer|sales|service|serviceOrder|document', action: '*',actionExclude:'index'){.... 

감사

+0

얘들 아, 네 해법을 시도하고이 메시지를 받는다.'Firefox가 서버가이 주소에 대한 요청을 결코 완료하지 않을 방법으로 리다이렉트하고 있음을 발견했다. 때때로이 문제는 쿠키를 사용하지 않거나 거부함으로써이 문제가 발생할 수 있습니다. ' –

+0

1. 쿠키를 사용합니다. 2. "캐시 지우기": 도구> 옵션> 고급> 네트워크> 캐시 된 웹 콘텐츠 : "지금 지우기"3. 다른 브라우저에서 시도해보십시오. 이는 전송되지 않거나 차단 된 손상된 쿠키 또는 쿠키로 인해 발생할 수 있습니다. http://kb.mozillazine.org/Cookies –

3

시도 예 :

def filters = { 
    allExceptIndex(controller:"installation",action:"index",invert:true) { 
     before = { 
     } 
     after = { Map model -> 
     } 
     afterView = { Exception e -> 
     } 
    } 
} 
더 참고로

는`installation` 컨트롤러의`index`action을 제외한 모든 컨트롤러의 행동에 체크`경우 (! session.user) {...}를`싶으 셨나요