我正在尝试使用Stormpath用户管理插件和Apache Shiro在Heroku中构建Web应用程序。 当我查看" shiro.ini"中提到的示例代码时文件提供" apiKey.properties"文件的属性" stormpathClient.apiKeyFileLocation"中的路径。 请建议我们如何配置" apiKey.properties"文件的路径,包含Heroku应用程序中的STORMPATH API KEY ID和SECRET。
答案 0 :(得分:3)
在Heroku中,您可以将Api Key ID和Secret置于环境变量中,如here所述。
那么,你可以做什么:
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"));
}
}
shiro.ini
更改为: apiKeyProps = com.stormpath.sample.client.ApiKeyEnvVariables
#stormpathClient.apiKeyFileLocation = /Users/XXXX/.stormpath/apiKey.properties
stormpathClient.apiKeyProperties = $apiKeyProps
STORMPATH_API_KEY_ID
和STORMPATH_API_KEY_SECRET
个环境变量。例如: heroku config:set STORMPATH_API_KEY_ID=2JQQCIG5E8EKN4DKBT7R151
heroku config:set STORMPATH_API_KEY_ID=1oYULQMkS3dwKkl6wtbNd93IyUrRehCsEJJrIrMwuI0
现在,当你的应用程序启动时,Stormpath会自动从环境变量中选择Api Key Id和Secret。
希望有所帮助!