WSO2 EI API服务的基本身份验证

问题描述 投票:0回答:1

我正在使用WSO2-EI 6.4.0。我已经用link尝试了这种开发。它对我有用。但是我需要从其他后端服务获取用户名和密码。在此示例中,显示了用户名和密码。我已添加该代码供您参考。请帮助我从属性文件中获取那些用户名和密码。

public boolean processSecurity(String credentials) {
        String decodedCredentials = new String(new Base64().decode(credentials.getBytes()));
        String usernName = decodedCredentials.split(":")[0];
        String password = decodedCredentials.split(":")[1];
        if ("admin".equals(username) && "admin".equals(password)) {
            return true;
        } else {
            return false;
        }
}

我已经添加了WSO2 EI处理程序,如下所示。我需要传递来自后台服务的值或调用其他序列并加载。

<api context="/test">
    <resource methods="POST">
        <inSequence>
        ................
        </inSequence>
        <outSequence>
        ................
        </outSequence>
    </resource>
    <handlers>        
         <handler class="rezg.ride.common.BasicAuthHandler">
            <property name="cm_password" value="admin"/>
            <property name="cm_userName" value="admin"/>
         </handler>
    </handlers>
</api>

[当我们运行上述API时,处理程序会先运行,然后再按入和出顺序运行。因此,在运行此BasicAuthHandler之前,我需要获取调用Sequence或其他方法的用户名和密码。

wso2 wso2esb basic-authentication wso2carbon wso2ei
1个回答
0
投票

如果需要从类调解器中读取属性文件,则直接进行Java属性文件读取。请参考以下读取属性文件的呼叫示例。在这种情况下,只需读取conf目录中存在的carbon.properties文件即可。

public boolean mediate(MessageContext context) {
        String passwordFileLocation = System.getProperty("conf.location")+"/carbon.properties";
        try (FileInputStream input = new FileInputStream(passwordFileLocation)) {
            Properties prop = new Properties();

            // load a properties file
            prop.load(input);
            log.info("------org.wso2.CipherTransformation : " + prop.getProperty("org.wso2.CipherTransformation"));

        } catch (IOException ex) {
            ex.printStackTrace();
        }
       return true;
    }

要获取服务器位置和配置,在wso2服务器启动时设置了JAVA系统属性。以下是一些有用的系统系统属性。

  • carbon.local.ip
  • carbon.home
  • conf.location
© www.soinside.com 2019 - 2024. All rights reserved.