如何为后端进程保护MobileFirst适配器?

时间:2015-02-25 16:57:17

标签: ibm-mobilefirst mobilefirst-server mobilefirst-adapters

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

我们应用以下解决方案来保护通过普通网址调用

  • 安全小组限制从外部客户端应用程序调用的URL。

有没有更好的解决方案可用于保护此适配器?

1 个答案:

答案 0 :(得分:2)

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

请转到文章了解更多详情,但这是本文的摘要。

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

<强> authenticationConfig.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

<强> ConfiguredIdentityLoginModule.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保护您的适配器。