我使用的API充当后端服务和外部客户端之间的网关。我正在尝试使用用户/密码基本编码通过基本身份验证来保护对我的API的访问。在遵循了一些指南之后,我在API中添加了处理程序部分,以便管理auth模块。
我尝试了此部分:
<handlers>
<handler class="org.wso2.rest.BasicAuthHandler"/>
</handlers>
尽管我更改了用户admin的密码,但Auth处理程序对我仍然有效,但仅具有admin / admin凭据。 如何添加用户并让他使用具有特定凭据的API?
答案 0 :(得分:0)
我按照以下步骤使用WSO2 EI管理控制台创建了一个用户。
然后,我按照1
中的说明部署了以下API<api xmlns="http://ws.apache.org/ns/synapse" name="StockQuoteAPI"
context="/stockquote">
<resource methods="GET" uri-template="/view/{symbol}">
<inSequence>
<payloadFactory media-type="xml">
<format>
<m0:getQuote xmlns:m0="http://services.samples">
<m0:request>
<m0:symbol>$1</m0:symbol>
</m0:request>
</m0:getQuote>
</format>
<args>
<arg evaluator="xml" expression="get-property('uri.var.symbol')"/>
</args>
</payloadFactory>
<header name="Action" scope="default" value="urn:getQuote"/>
<send>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService" format="soap11"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
<handlers>
<handler class="org.wso2.carbon.integrator.core.handler.RESTBasicAuthHandler"/>
</handlers>
</api>
然后我可以使用带有新用户名/密码的邮递员发送请求。
1 https://docs.wso2.com/display/EI650/Applying+Security+to+an+API#ApplyingSecuritytoanAPI-BasicAuthUsingaBasicAuthhandler
答案 1 :(得分:0)
感谢您的回复。我试图在我的api中通过“ org.wso2.carbon.integrator.core.handler.RESTBasicAuthHandler”更改“ org.wso2.rest.BasicAuthHandler”并重新部署它。我收到此错误
Caused by: java.lang.ClassNotFoundException: org.wso2.carbon.integrator.core.handler.RESTBasicAuthHandler cannot be found by synapse-core_2.1.7.wso2v60
似乎我需要.jar文件才能加载它,但我找不到它。您能提供一个下载链接吗?
答案 2 :(得分:0)
我升级到ESB的6.5.0版本,并且可以正常工作。谢谢!