在Heroku Java Web App的“shiro.ini”文件中配置“apiKey.properties”文件

时间:2015-01-12 13:20:35

标签: heroku shiro stormpath

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

1 个答案:

答案 0 :(得分:3)

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

那么,你可以做什么:

  1. 在您的应用程序中创建以下类:
  2.    
       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更改为:
    2.    
       apiKeyProps = com.stormpath.sample.client.ApiKeyEnvVariables
       #stormpathClient.apiKeyFileLocation = /Users/XXXX/.stormpath/apiKey.properties
       stormpathClient.apiKeyProperties = $apiKeyProps
      
      1. 设置STORMPATH_API_KEY_IDSTORMPATH_API_KEY_SECRET个环境变量。例如:
      2.    
           heroku config:set STORMPATH_API_KEY_ID=2JQQCIG5E8EKN4DKBT7R151
           heroku config:set STORMPATH_API_KEY_ID=1oYULQMkS3dwKkl6wtbNd93IyUrRehCsEJJrIrMwuI0
        

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

        希望有所帮助!