0

我们有带有wl_unprotected安全测试的 MobileFirst 适配器,可以从后端进程中使用它。

我们应用了以下解决方案来保护它通过正常 URL 调用

  • 要从外部客户端应用程序调用的安全团队受限 URL。

有没有更好的解决方案可以用来保护这个适配器?

4

1 回答 1

2

IBM MobileFirst Platform Developers Center 博客中有一篇非常好的文章,介绍了如何做到这一点。为后端访问保护适配器过程 https://developer.ibm.com/mobilefirstplatform/2015/02/04/protect-adapter-backend/

更多详细信息请参阅文章,但这里是文章的摘要。

您可以使用基本 HTTP 身份验证来保护该适配器。使用securityTestrealmloginModule更新您的authenticationConfig.xml文件,如下所示:

身份验证配置.xml

  <securityTests>
    <!-- your other security tests -->
    <customSecurityTest name="BackendAccessSecurity">
     <test realm="BackendAccessRealm" isInternalUserID="true"/>
    </customSecurityTest>
  </securityTests>

  <realms>
    <!-- your other realms -->
    <realm name="BackendAccessRealm" loginModule="BackendAccessLogin">
      <className>com.worklight.core.auth.ext.BasicAuthenticator</className>
      <parameter name="basic-realm-name" value="Private"/>
    </realm>
  </realms>
  <loginModules>
    <!-- your other login modules -->
    <loginModule name="BackendAccessLogin">
      <className>com.sample.auth.ConfiguredIdentityLoginModule</className>
      <parameter name="username-property" value="backend.username"/>
      <parameter name="password-property" value="backend.password"/>
    </loginModule>
  </loginModules>

worklight.properties

##
# Backend access credentials
##
backend.username=user
backend.password=password

配置的IdentityLoginModule.java

  @Override
  public void init(Map<String, String> options) throws MissingConfigurationOptionException {
    String usernameProperty = options.remove(USERNAME_PROPERTY_CONF);
    if (usernameProperty == null) throw new MissingConfigurationOptionException(USERNAME_PROPERTY_CONF);
    String passwordProperty = options.remove(PASSWORD_PROPERTY_CONF);
    if (passwordProperty == null) throw new MissingConfigurationOptionException(PASSWORD_PROPERTY_CONF);
    super.init(options);

    WorklightConfiguration conf = WorklightConfiguration.getInstance();
    configuredUsername = conf.getStringProperty(usernameProperty);
    configuredPassword = conf.getStringProperty(passwordProperty);

    if (configuredUsername == null || configuredUsername.length() == 0) {
      throw new IllegalStateException("ConfiguredIdentityLoginModule cannot resolve property " + usernameProperty + ". Please check project configuration properties.");
    }

    if (configuredPassword == null || configuredPassword.length() == 0) {
      throw new IllegalStateException("ConfiguredIdentityLoginModule cannot resolve property " + usernameProperty + ". Please check project configuration properties.");
    }

  }

  @Override
  public boolean login(Map<String, Object> authenticationData) {
    populateCache(authenticationData);
    return configuredUsername.equals(username) && configuredPassword.equals(password);
  }

最后,使用BackendAccessSecurity.

于 2015-02-25T17:32:53.560 回答