So, I'm not particularly familiar with stormpath so I can't help with your
first question. However, on your second I might be able to.
You instantiate a Realm, but it doesn't appear that you ever do anything
with it.
What if, you move this realm instantiation code into
createWebSecurityManager - that way you can just set the realm on the
security manager?
```java
protected WebSecurityManager createWebSecurityManager() {
ApplicationRealm stormpathRealm = new ApplicationRealm();
DefaultSecurityManager securityManager = new
DefaultSecurityManager(stormpathRealm);
MemoryConstrainedCacheManager cacheManager = new
MemoryConstrainedCacheManager();
securityManager.setCacheManager(cacheManager);
//Initializing Stormpath
ClientFactory stormpathClient = new ClientFactory();
stormpathClient.setCacheManager(cacheManager);
InputStream apiKeyIS=SettingsProperties.
class.getClassLoader().getResourceAsStream(stormpathApiKeyFile);
stormpathClient.setApiKeyInputStream(apiKeyIS);
stormpathRealm.setClient(stormpathClient.getInstance());
stormpathRealm.setApplicationRestUrl(applicationRestUrl);
stormpathRealm.setName(groupRoleResolverModeNames);
DefaultGroupRoleResolver groupRoleResolver = new
DefaultGroupRoleResolver();
stormpathRealm.setGroupRoleResolver(groupRoleResolver);
WebSecurityManager sm = super.createWebSecurityManager();
((RealmSecurityManager)sm).setRealm(stormpathRealm);
return sm;
}
```
This does introduce the restriction that your INI file specifies a
SecurityManager that implements RealmSecurityManager - but most do.
On Fri, Aug 8, 2014 at 10:45 AM, tanvir <[email protected]> wrote:
> Hi,
> I have spent several days trying to find a solution for my issue so any
> help
> would be more than welcome! I am using stormpath as my Client. Although I
> know all the reasons why apiKeyFile should not be located inside the
> project
> classpath, This is exactly what I need to do but I am having trouble
> setting
> it properly.
>
> Currently in my shiro.ini I have-
> _______________
> ...
> stormpathClient = com.stormpath.shiro.client.ClientFactory
> stormpathClient.cacheManager = $cacheManager
> stormpathClient.apiKeyFileLocation = c:/stormpathApiKey.properties
> stormpathRealm = com.stormpath.shiro.realm.ApplicationRealm
> stormpathRealm.client = $stormpathClient
> ...
> _______________
>
>
> When I change the apiKeyFileLocation to without the quote
> '/stormpathApiKey.properties' or '/WEB-INF/stormpathApiKey.properties' it
> does not work even though the file is present in both the src and the
> WEB-INF folder.
>
>
> I have also tried writing my own Environment Initializer class
> IniWebEnvironment but that didn't work either. Here is what I tried to do:
>
> _______________
> public class ShiroWebEnvironment extends IniWebEnvironment{
> private static final String applicationRestUrl =
> "https://api.stormpath.com/v1/applications/APPHREF";
> private static final String stormpathApiKeyFile =
> "stormpathApiKey.properties";
>
> @Override
> public void init() {
>
> Settings settings = new Settings();
> String location = settings.getStormpathIniFilePath();
> Ini ini = createIni(location, false);
>
> ApplicationRealm stormpathRealm = new ApplicationRealm();
> DefaultSecurityManager securityManager = new
> DefaultSecurityManager(stormpathRealm);
>
> MemoryConstrainedCacheManager cacheManager = new
> MemoryConstrainedCacheManager();
> securityManager.setCacheManager(cacheManager);
>
> //Initializing Stormpath
> ClientFactory stormpathClient = new ClientFactory();
> stormpathClient.setCacheManager(cacheManager);
> InputStream
>
> apiKeyIS=SettingsProperties.class.getClassLoader().getResourceAsStream(stormpathApiKeyFile);
> stormpathClient.setApiKeyInputStream(apiKeyIS);
> stormpathRealm.setClient(stormpathClient.getInstance());
>
> stormpathRealm.setApplicationRestUrl(applicationRestUrl);
> stormpathRealm.setName(groupRoleResolverModeNames);
>
> DefaultGroupRoleResolver groupRoleResolver = new
> DefaultGroupRoleResolver();
> stormpathRealm.setGroupRoleResolver(groupRoleResolver);
>
> this.setIni(ini);
> super.init();
>
> }
> _______________
>
>
> Thank you so much!
>
>
>
> --
> View this message in context:
> http://shiro-user.582556.n2.nabble.com/Dynamically-set-Client-apiKeyFileLocation-value-during-initialization-shiro-ini-tp7580145.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>