在 Heroku Java Web App 的 "shiro.ini" 文件中配置 "apiKey.properties" 文件
Configure "apiKey.properties" file in "shiro.ini" file in Heroku Java Web App
我正在尝试使用 Stormpath 用户管理插件和 Apache Shiro 在 Heroku 中构建一个 Web 应用程序。
当我查看 "shiro.ini" 文件中提到的示例代码时,它会在 属性 "stormpathClient.apiKeyFileLocation" 中提供 "apiKey.properties" 文件的路径。
请建议我们如何在 Heroku 应用程序中配置 "apiKey.properties" 包含 STORMPATH API KEY ID 和 SECRET 的文件路径。
在 Heroku 中,您可以将 Api 密钥 ID 和密钥放入环境变量中,如 here 所述。
那么,您可以做什么:
- 在您的应用程序中创建以下 class:
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。
希望对您有所帮助!
我正在尝试使用 Stormpath 用户管理插件和 Apache Shiro 在 Heroku 中构建一个 Web 应用程序。 当我查看 "shiro.ini" 文件中提到的示例代码时,它会在 属性 "stormpathClient.apiKeyFileLocation" 中提供 "apiKey.properties" 文件的路径。 请建议我们如何在 Heroku 应用程序中配置 "apiKey.properties" 包含 STORMPATH API KEY ID 和 SECRET 的文件路径。
在 Heroku 中,您可以将 Api 密钥 ID 和密钥放入环境变量中,如 here 所述。
那么,您可以做什么:
- 在您的应用程序中创建以下 class:
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。
希望对您有所帮助!