Mule にデプロイされた RestFul Web サービスで基本認証を使用しており、組み込みの Spring Security によって強化されたセキュリティです。Mule 3.3.0 を使用しています。
mflow を main.xml と connector.xml の 2 つの部分に分割しました。その理由は、機能テストの実行中に、AMQ などのすべてのエンドポイントがスタブ化される、connector.xml の代わりに別の mflow connector-test.xml を渡すためです。ただし、Rest については、まだ適切なエンドポイントを使用しています。Mule 機能テストでは、apache commons httpclient を使用して、これらのエンドポイントに対して安静な WS 呼び出しを行い、応答を待ってから、テストに合格したかどうかを確認します。
Mule スタンドアロンでも同じ機能が正常に動作します。つまり、REST Web サービスが正常にデプロイされ、http REST リクエストを作成できます。基本認証を取得してから、応答を返します。ただし、機能テスト中に認証を行うと、メッセージで失敗します
Exception stack is:
1. There is no Security Provider reqistered called "org.mule.security.DefaultMuleAuthentication" (org.mule.api.security.SecurityProviderNotFoundException)
org.mule.security.MuleSecurityManager:107 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/security/SecurityProviderNotFoundException.html)
********************************************************************************
Root Exception stack trace:
org.mule.api.security.SecurityProviderNotFoundException: There is no Security Provider reqistered called "org.mule.security.DefaultMuleAuthentication"
at org.mule.security.MuleSecurityManager.authenticate(MuleSecurityManager.java:107)
at org.mule.transport.http.filters.HttpBasicAuthenticationFilter.authenticateInbound(HttpBasicAuthenticationFilter.java:134)
at org.mule.security.AbstractEndpointSecurityFilter.authenticate(AbstractEndpointSecurityFilter.java:58)
at org.mule.security.AbstractAuthenticationFilter.doFilter(AbstractAuthenticationFilter.java:56)
at org.mule.security.AbstractEndpointSecurityFilter.doFilter(AbstractEndpointSecurityFilter.java:49)
at org.mule.processor.SecurityFilterMessageProcessor.process(SecurityFilterMessageProcessor.java:52)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:43)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:43)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:43)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:43)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:43)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:43)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:43)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:43)
at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:192)
at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:174)
at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:166)
at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:153)
at org.mule.transport.http.HttpMessageReceiver$HttpWorker$1.process(HttpMessageReceiver.java:310)
at org.mule.transport.http.HttpMessageReceiver$HttpWorker$1.process(HttpMessageReceiver.java:305)
at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:20)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:34)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:18)
at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:58)
at org.mule.execution.ResolvePreviousTransactionInterceptor.execute(ResolvePreviousTransactionInterceptor.java:48)
at org.mule.execution.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:54)
at org.mule.execution.ValidateTransactionalStateInterceptor.execute(ValidateTransactionalStateInterceptor.java:44)
at org.mule.execution.IsolateCurrentTransactionInterceptor.execute(IsolateCurrentTransactionInterceptor.java:44)
at org.mule.execution.ExternalTransactionInterceptor.execute(ExternalTransactionInterceptor.java:52)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:32)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:17)
at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:113)
at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:34)
at org.mule.transport.http.HttpMessageReceiver$HttpWorker.doRequest(HttpMessageReceiver.java:304)
at org.mule.transport.http.HttpMessageReceiver$HttpWorker.processRequest(HttpMessageReceiver.java:250)
at org.mule.transport.http.HttpMessageReceiver$HttpWorker.run(HttpMessageReceiver.java:163)
at org.mule.work.WorkerContext.run(WorkerContext.java:311)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
セキュリティ プロバイダが登録されない理由はありますか?
ここに設定があります..
main.xml の内容
<flow name="RestFlow" doc:name="RestFlow">
<inbound-endpoint ref="restEndPoint" mimeType="text/xml">
<mule-ss:http-security-filter realm="easervices-realm" />
</inbound-endpoint>
<jersey:resources doc:name="REST">
<component>
<spring-object bean="createCompany"/>
</component>
<component>
<spring-object bean="activateNumbers"/>
</component>
</jersey:resources>
</flow>
........
ご覧のとおり、セキュリティ ビットは上記のように RestFlow に挿入されています。残りのセキュリティ設定は、connector.xml(live) または connector-test.xml(test) で行います。
connector-test.xml の内容- 機能テストを実行するためにメモリにデプロイする際の注意点 Rest エンドポイントはポート 8098 にデプロイされますが、セキュリティには関係ないはずです
<spring:beans>
<spring:import resource="classpath:spring/external-service-config-stub.xml" />
<ss:authentication-manager alias="authenticationManager">
<ss:authentication-provider>
<ss:password-encoder hash="sha" />
<ss:user-service id="userService">
<ss:user name="adminportal" password="0314795e56347590b54b7da2afba3456fgcd4968"
authorities="ROLE_ADMIN" />
</ss:user-service>
</ss:authentication-provider>
</ss:authentication-manager>
<ss:global-method-security
pre-post-annotations="enabled" jsr250-annotations="enabled" />
</spring:beans>
<http:endpoint exchange-pattern="request-response" host="localhost"
port="8098" path="mypath" name="restEndPoint" doc:name="HTTP" />
<mule-ss:security-manager>
<mule-ss:delegate-security-provider
name="memory-provider" delegate-ref="authenticationManager" />
</mule-ss:security-manager>
connector.xml の内容- mule-standalone でデプロイする際の注意点
<spring:beans>
<spring:import resource="classpath:spring/external-service-config.xml" />
<ss:authentication-manager alias="authenticationManager">
<ss:authentication-provider>
<ss:password-encoder hash="sha" />
<ss:user-service id="userService">
<ss:user name="adminportal" password="0314795e56347590b54b7da2afba3456fgcd4968"
authorities="ROLE_ADMIN" />
</ss:user-service>
</ss:authentication-provider>
</ss:authentication-manager>
<ss:global-method-security
pre-post-annotations="enabled" jsr250-annotations="enabled" />
<context:property-placeholder location="classpath:config/mule-config.properties" />
</spring:beans>
<http:endpoint exchange-pattern="request-response" host="localhost"
port="8088" path="mypath" name="restEndPoint" mimeType="text/xml"
doc:name="HTTP" />
<mule-ss:security-manager>
<mule-ss:delegate-security-provider
name="memory-provider" delegate-ref="authenticationManager" />
</mule-ss:security-manager>
テストの実行中に http rest 要求を行う機能テスト コードのコードを呼び出します。
httpClient.getState().setCredentials(
new AuthScope("localhost", 8098, "easervices-realm"),
new UsernamePasswordCredentials("adminportal",
"thepassword"));
httpClient.getParams().setAuthenticationPreemptive(true);
httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,
Collections.singleton(AuthPolicy.BASIC));
final PostMethod meth = new PostMethod("http://localhost:8098/horizon"
+ url);
meth.setDoAuthentication(true);
meth.setRequestEntity(new StringRequestEntity(xml, "text/xml",
"ISO-8859-1"));
// meth.addRequestHeader("Content-Type", "text/xml");
httpClient.executeMethod(meth);
親切に助けてください。同じセキュリティ設定が connector.xml で使用され、アプリケーションがスタンドアロン Mule 3.3.0 にデプロイされると、正常にデプロイされ、基本認証も正常に実行されます。Mule サーバがメモリ内で起動され、テスト設定を使用してテスト用にデプロイされたアプリケーションで Mule Functional テストを実行すると、何らかの理由でセキュリティ プロバイダが登録されません。