1

私の問題に対する明確な答えが見つからないため、ここに書きました。

私のプロジェクトは Spring MVC と Spring Security を使用しています。Webアプリケーション用に両方をうまくインストールしました(もちろんJavaを使用)。post および get メソッドでアクセスできますが、ユーザーが通常の形式の Spring Security を介して接続された後でのみです。

これから、ユーザーは次のようなアドレスでリクエストを行います。

../../get.request?request=getListCommand

get.request は Spring MVC からのマッピングです。このアクセスは、ユーザーが認証された後にのみ有効になります!

私がする必要があること: たとえば、次のようなアドレスを使用して、以前に認証されていなくても、このリクエストに直接アクセスする可能性を追加します。

http://123.123.123.123:123/get.request?request=getListCommand&j_password=myPassword&j_username=myName

また

same thing with the post protocol and the params given (request=getListCommand, j_password=myPassword, j_username=myName)

もちろん、リクエストが実行されて結果が返される前に、認証を行う必要があります。

多くの Web サイトで検索するか、Spring セキュリティ Web サイトで直接検索しました。彼らは、フィルターチェーン、独自のユーザー名認証、RMI について話しています。しかし、上で提示したことを実行する完全な例は実際には見つかりませんでした。

そのように私を助けることができる人に感謝します。

ps:Spring セキュリティのすべてのデフォルトまたは最も単純な構成を使用します (風水スタイルではありません :-))

これが私のsecurit context xmlファイルです

<http realm="NexCap Up"
        auto-config="true"
        access-denied-page="/www/jsp/authentication/accessDenied.jsp"
        create-session="always"
        disable-url-rewriting="true">          
            <port-mappings>
                <port-mapping http="8084" https="8443"/>
            </port-mappings>        

            <intercept-url pattern="/www/jsp/authentication/connexion.jsp"                    
                access='IS_AUTHENTICATED_ANONYMOUSLY' requires-channel="https"/>

            <intercept-url pattern="/www/jsp/authentication/connexionFailed.jsp" 
                access='IS_AUTHENTICATED_ANONYMOUSLY'  />

            <intercept-url pattern="/www/jsp/authentication/applicationExit.jsp" 
                access='IS_AUTHENTICATED_ANONYMOUSLY'  /> 


          <intercept-url 
                pattern="/get.Request" 
                method="GET"
                access="ROLE_REMOTE" />

             <intercept-url 
                pattern="/post.Request"  
                method="POST"
                access="ROLE_REMOTE" />

            <intercept-url pattern="/**" 
                access="ROLE_REMOTE,ROLE_SCRIPT"  />
       <form-login 
            authentication-failure-url="/www/jsp/authentication/connexionFailed.jsp"
            login-page="/www/jsp/authentication/connexion.jsp"
            default-target-url="/www/jsp/index.jsp"
            always-use-default-target="true"/>

        <logout
            logout-success-url="/www/jsp/authentication/applicationExit.jsp"
            invalidate-session="true"/>

        <session-management
            invalid-session-url="/www/jsp/authentication/invalidSession.jsp"
            session-authentication-error-url = "/www/jsp/authentication/authentificationError.jsp"
            session-fixation-protection="none">

            <!-- Sessions concurrentes -->
            <concurrency-control 
                error-if-maximum-exceeded="false"
                expired-url="/www/jsp/authentication/sessionExpired.jsp"
                max-sessions="1" />

        </session-management>

    </http>

そして、春のセキュリティに関する web.xml ファイルの部分

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Security</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>


<filter>
  <display-name>springSecurityFilterChain</display-name>
  <filter-name>springSecurityFilterChain</filter-name>
  <filter-class>
      org.springframework.web.filter.DelegatingFilterProxy
  </filter-class>

<filter-mapping>
   <filter-name>springSecurityFilterChain</filter-name>
   <url-pattern>/*</url-pattern>

<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>
       /WEB-INF/spring/secu-config.xml
   </param-value>

4

1 に答える 1

0

applicationContext-security.xmlWEB-INF にがあると仮定します。
applicationContext-security.xml を投稿できれば素晴らしいと思います
。また、Spring Security のほぼデフォルトの構成を持っていることもできます。

フォローすることをお勧めします。

最初にあなたのURLを/public/get.request?request=getListCommand

次に、次のスニペットを applicationContext-security.xml に追加します

<http use-expressions="true">
 <intercept-url pattern="/public/**" access="permitAll" />
 <!-- You can add n number of filters here-->
</http>

それが行うことは、 の下のすべてのパスのセキュリティをバイパスすることです/public/。URL を変更する理由は、アプリケーション全体を公開したくない場合があるためです。

以下は私のXMLの例です。
また、私の認証プロバイダーはカスタムなので、混同しないでください。私の<http>セクションを見るだけで、アプリケーションに実装する方法がわかります。

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">

    <global-method-security pre-post-annotations="enabled" jsr250-annotations="enabled" secured-annotations="enabled">
        <!-- AspectJ pointcut expression that locates our "post" method and applies security that way
        <protect-pointcut expression="execution(* bigbank.*Service.post*(..))" access="ROLE_TELLER"/>
        -->
    </global-method-security>

    <http use-expressions="true">
        <intercept-url pattern="/favicon.ico" access="permitAll" />
        <intercept-url pattern="/static/**" access="permitAll"/>
        <intercept-url pattern="/login.jsp*" access="permitAll"/>
        <intercept-url pattern="/Admin/**" access="hasAnyRole('ROLE_SUPER_USER')"/>
        <form-login login-page="/login.jsp" authentication-failure-url="/login.jsp?login_error=1" />
        <http-basic/>
        <logout logout-success-url="/login.jsp"/>
        <remember-me user-service-ref="loginService" />
        <!-- Uncomment to limit the number of sessions a user can have -->
     </http>

    <authentication-manager>
        <authentication-provider user-service-ref="loginService">
         <password-encoder hash="md5"/>
        </authentication-provider>
    </authentication-manager>

    <beans:bean id="loginService" class="com.indyaah.service.LoginService">
    </beans:bean>
    <beans:bean id="authService" class="com.indyaah.service.AuthService" />
</beans:beans>

ご覧のとおりlogin.jsp、ログインせずに匿名で静的コンテンツ (images/js/css/etc.) にアクセスできるようにしています。

この助けを願っています。

理解にさらに助けが必要な場合はお知らせください。

于 2012-10-11T13:43:40.037 に答える