2

初めての方、よろしくお願いします!

Vaadin で生成されたページを Guice を使用してフィルタリングするように Shiro を構成するのに少し問題があります。

Apache Shiro のガイドなどを含むさまざまな Web サイトをオンラインで調べました。問題は、ほとんどの Web サイトが「古い」方法、つまり Shiro 1.1 (ネイティブの Guice サポートがない) を使用する傾向があることです。

ここに問題があります。私のページは Shiro でフィルタリングされません。メソッド認証にAOPを使用したり、web.xmlでフィルターを手動で設定したりするなど、無数のことを試しました。shiro.ini ファイルを設定することもできます (これは、どのような状況でもやりたくありません)。

私が使用しているもののリストは次のとおりです。 - Shiro 1.2.0-SNAPSHOT - Guice 3.0 - Vaadin 6.7.4

ここに私のweb.xmlがあります:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                             http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">

    <display-name>App</display-name>

    <context-param>
        <description>Vaadin production mode</description>
        <param-name>productionMode</param-name>
        <param-value>false</param-value>
    </context-param>

    <filter>
        <filter-name>guiceFilter</filter-name>
        <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>guiceFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>
        <listener-class>com.app.GuiceServletInjector</listener-class>
    </listener>

</web-app>

サーブレットインジェクターは次のとおりです。

public class GuiceServletInjector extends GuiceServletContextListener {
    private ServletContext servletContext;

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        servletContext = servletContextEvent.getServletContext();
        super.contextInitialized(servletContextEvent);
    }

    @Override
    protected Injector getInjector() {
        return Guice.createInjector(new GuiceServletModule(), new ShiroConfigurationModule(servletContext));
    }

次に、リクエストを Vaadin アプリに渡す ServletModule を作成します。

protected void configureServlets() {
    bind(Application.class).to(VaadinMainWindow.class).in(ServletScopes.SESSION);

    bind(BasicHttpAuthenticationFilter.class).in(Singleton.class);
    filter("/*").through(BasicHttpAuthenticationFilter.class);

    serve("/*", "*").with(VaadinApp.class);
}

また、インジェクターの段階で、レルムなどを処理する ShiroConfigurationModule を作成していることに注意してください。

public class ShiroConfigurationModule extends ShiroWebModule {

    @Inject
    public ShiroConfigurationModule(ServletContext servletContext) {
        super(servletContext);
    }

    @Override
    protected void configureShiroWeb() {
        bindRealm().to(ShiroBaseRealm.class).in(Singleton.class);
        bind(Realm.class).to(ShiroBaseRealm.class).in(Singleton.class);

        processMethodInterceptors();
    }

    private void processMethodInterceptors() {
        MethodInterceptor interceptor = new AopAllianceAnnotationsAuthorizingMethodInterceptor();
        bindInterceptor(any(), annotatedWith(RequiresRoles.class), interceptor);
        bindInterceptor(any(), annotatedWith(RequiresPermissions.class), interceptor);
        bindInterceptor(any(), annotatedWith(RequiresAuthentication.class), interceptor);
        bindInterceptor(any(), annotatedWith(RequiresUser.class), interceptor);
        bindInterceptor(any(), annotatedWith(RequiresGuest.class), interceptor);
    }
}

レルム クラスは、supports() に対して「true」を返しますが、ユーザーが存在しないことをシミュレートして、すべてに対して「null」を返します。

何か間違ったことをしたり、ステップを逃したりする可能性は非常に高いです。少なくとも基本的なHTTP認証を取得できるように、誰かが私が欠けているものを説明してくれませんか?

どうもありがとう!モ。

4

2 に答える 2

-1

そのため、Shiro で多くのテストといじりを行った後 (最終的に 1.2 リリースを使用するだけでなく)、私は動作するようになりました。

私は自分のサイトに詳細な回答を書きました(主に書きやすいからです!)。見てください:

http://www.mofirouz.com/wordpress/2012/01/guice-shiro-1-2-and-vaadingwt/

頑張ってください!

于 2012-01-25T07:43:01.097 に答える