2013-10-10 26 views
1

我正在將Shiro集成到我的dropwizard webapp中。我已經得到了該在Dropwizard中Shiro將我重定向到登錄頁面

  • 四郎認識到需要認證的資源,並送我到登錄頁面(/ auth /中登錄)
  • 四郎提醒我,如果登錄失敗,因爲密碼錯誤(點/認證/登錄?loginFailed =真)
  • 四郎只有當我嘗試成功後

訪問受保護的資源(如/管理/ **)

  • 四郎重定向到一個定義的頁面重定向。然而, shiro總是把我送到l ogin頁面,如果我嘗試訪問受保護的資源,無論我是否已登錄。我相信登錄正在運行;我也相信shiro不尊重我是否已經登錄過。

    我shiro.ini:

    [main] 
    # some other stuff 
    authc = org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter 
    authc.loginUrl = /auth/login 
    
    # NOTE: URLs are evaluated in order, and the first matching pattern is accepted. 
    [urls] 
    /static/** = noSessionCreation, anon 
    /auth/** = authc 
    /admin/** = authc 
    /** = anon 
    

    另外值得注意的是:我收到說

    0:0:0:0:0:0:0:1%0 - - [10/Oct/2013:18:23:54 +0000] "GET /auth/login;JSESSIONID=65e06b39-30e5-45dd-85f9-b2a1c29fc3af HTTP/1.1" 200 739 4 4 
    WARN [2013-10-10 18:24:08,485] com.sun.jersey.spi.container.servlet.WebComponent: 
    A servlet request, to the URI http://blah:8080/auth/login, contains form 
    parameters in the request body but the request body has been consumed by the servlet 
    or a servlet filter accessing the request parameters. Only resource methods using 
    @FormParam will work as expected. Resource methods consuming the request body by other 
    means will not work as expected. 
    

    錯誤,每次訪問/管理導致錯誤302我不不知道回答這個問題還有什麼相關的。我已經探索了其他幾個「Shiro不斷重定向我登錄」的問題,但大多數都直接使用web.xmls,Dropwizard並未使用,也不知道正在應用哪些過濾器。我的同事使用相同的方法來讓shiro與他的dropwizard項目一起工作。

    在決定是否將他發送到登錄頁面之前,shiro如何驗證用戶身份?

  • 回答

    1

    我發現了這個問題。下面是更多的shiro.ini的,特別是會話管理部分:(並會刪除它一會兒)

    sessionManager = org.apache.shiro.web.session.mgt.DefaultWebSessionManager 
    # NOTE: The session ID cookie seems to be required in order for authentication to work as intended. 
    # If the presence of cookies is a deal-breaker, further investigation will be required. 
    # Here we enable the Secure attribute (serve over SSL only) for this cookie; 
    # the HttpOnly attribute (not accessible by JavaScript) is enabled by default. 
    #sessionManager.sessionIdCookie.secure = true 
    # enabled Ehcache following advice from Shiro docs 
    sessionDAO = org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO 
    sessionManager.sessionDAO = $sessionDAO 
    # can optionally add session listeners here if actions need to be performed on session start/stop/expiration 
    # sessionManager.sessionListeners = $listener_1, $listener_2, ... 
    securityManager.sessionManager = $sessionManager 
    

    我評論的sessionIdCookie.secure事實證明,如果沒有啓用SSL,cookies是不當該變量設置爲true時存儲。這解釋了url欄中的JSESSIONID查詢參數,但是爲什麼在驗證之後,它立即忘記了我,並決定我需要再次登錄。