1

次の beans.xml ファイルを含む単純な Apache CXF Web サービスがあります。

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans 
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns="http://www.springframework.org/schema/security"
    xmlns:ssec="http://cxf.apache.org/spring-security"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    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   
    http://cxf.apache.org/spring-security 
    http://cxf-spring-security.googlecode.com/svn/trunk/cxf-spring-security/src/main/resources/schemas/spring-security.xsd
    http://cxf.apache.org/jaxws 
    http://cxf.apache.org/schemas/jaxws.xsd">

    <beans:import resource="classpath:META-INF/cxf/cxf.xml" />

    <http auto-config='true' >
        <http-basic/>
        <anonymous enabled="false"/>                
    </http>

    <beans:bean id="methodSecurityInterceptor"
          class="org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor">            

          <beans:property name="authenticationManager" ref="authenticationManager"/>                      
          <beans:property name="accessDecisionManager" ref="accessDecisionManager"/>                                          
          <beans:property name="securityMetadataSource">
            <beans:value>
                org.mycompany.com.CxfSpringSecuredService.HelloWorldImpl.sayHi=ROLE_OPERATOR
                org.mycompany.com.CxfSpringSecuredService.HelloWorldImpl.sayHiAdmin*=ROLE_ADMIN,ROLE_SUPERVISOR
                org.mycompany.com.CxfSpringSecuredService.HelloWorldImpl.deleteAccounts*=ROLE_SUPERVISOR
            </beans:value>
          </beans:property>                                                 
    </beans:bean>

    <beans:bean id="accessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased">
       <beans:property name="decisionVoters">
          <beans:list>
              <beans:bean class="org.springframework.security.access.vote.RoleVoter" />                          
          </beans:list>
       </beans:property>
    </beans:bean>

    <authentication-manager alias="authenticationManager">
        <authentication-provider>
            <user-service>          
                <user name="operator" password="operator" authorities="ROLE_OPERATOR" />
                <user name="admin" password="admin" authorities="ROLE_ADMIN" />
                <user name="sup" password="sup" authorities="ROLE_SUPERVISOR" />                  
            </user-service>
        </authentication-provider>
    </authentication-manager>       


    <jaxws:endpoint 
      id="helloWorld" 
      implementor="org.mycompany.com.CxfSpringSecuredService.HelloWorldImpl" 
      address="/HelloWorld" />  

</beans:beans>

私の Web サービスの実装は、次の 3 つの単純なメソッドです。

@WebService(endpointInterface = "org.mycompany.com.CxfSpringSecuredService.HelloWorld")
public class HelloWorldImpl implements HelloWorld {

    public String sayHi(String text) {          

        SecurityContext context =  SecurityContextHolder.getContext();
        if (context != null){
            Authentication authentication = context.getAuthentication();
            if (authentication != null){
                Collection<GrantedAuthority> roles = authentication.getAuthorities();

                if (roles != null){  
                    GrantedAuthority[] authorities = new GrantedAuthority[roles.size()];
                    roles.toArray(authorities);                 
                    for (int i = 0; i < authorities.length; i++)                    
                        text = text + " " + authorities[i];
                }
            }
        }               


        return "Hello " + text;
    }

    public String sayHiAdmin(){    

        return "Hello admin";
    }

    public String deleteAccounts(String name){
        return "Accounts deleted by " + name;
    }
}

Web サービスを呼び出し、SOAP ヘッダー内で認証情報を渡す C# クライアントがあります。例外で次のメッセージが表示されるので、クライアントが認証情報を渡していることがわかります。

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic realm="Spring Security Application"'.

無効な資格情報を発行した場合。適切な資格情報を発行し、各 Web サービス呼び出しに対して正しい応答を取得します。ここまでは順調ですね。

オペレーターに資格情報を渡し、メソッド deleteAccounts を呼び出すと、上記と同じ承認済みエラーが発生することが予想されましたが、webservice メソッドは正しく呼び出されます。

ここでSpring Frameworkのドキュメントを調べましたが、何が欠けているのか判断できません。

何か案は?

ティア。

編集: ユーザー設定を修正しました。

4

0 に答える 0