1

我正在尝试使用 Stormpath 用户管理插件和 Apache Shiro 在 Heroku 中构建 Web 应用程序。当我浏览“shiro.ini”文件中提到的示例代码时,在属性“stormpathClient.apiKeyFileLocation”中提供“apiKey.properties”文件的路径。请建议我们如何在 Heroku 应用程序中配置“apiKey.properties”文件的路径,其中包含 STORMPATH API KEY ID 和 SECRET。

4

1 回答 1

3

在 Heroku 中,您可以将 Api Key ID 和 Secret 放在环境变量中,如此所述。

所以,你可以做什么:

  1. 在您的应用程序中创建以下类:
   package com.stormpath.sample.client;

   import java.util.Properties;

   public class ApiKeyEnvVariables extends Properties {

       public ApiKeyEnvVariables() {
           super.put("apiKey.id", System.getenv("STORMPATH_API_KEY_ID"));
           super.put("apiKey.secret", System.getenv("STORMPATH_API_KEY_SECRET"));
       }
   }
  1. 改变你shiro.ini的样子:
 apiKeyProps = com.stormpath.sample.client.ApiKeyEnvVariables
 #stormpathClient.apiKeyFileLocation = /Users/XXXX/.stormpath/apiKey.properties
 stormpathClient.apiKeyProperties = $apiKeyProps
  1. 设置STORMPATH_API_KEY_IDSTORMPATH_API_KEY_SECRET环境变量。例如:
   heroku config:set STORMPATH_API_KEY_ID=2JQQCIG5E8EKN4DKBT7R151
   heroku config:set STORMPATH_API_KEY_ID=1oYULQMkS3dwKkl6wtbNd93IyUrRehCsEJJrIrMwuI0

现在,当您的应用程序启动时,Stormpath 将自动从环境变量中选择 Api Key Id 和 Secret。

希望有帮助!

于 2015-01-13T19:46:33.047 回答