Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.

Coming from a support question: It would be nice to provide OS-independent ApiKey File Reader #18

Open
mrioan opened this issue Aug 20, 2014 · 1 comment

Comments

@mrioan
Copy link
Contributor

mrioan commented Aug 20, 2014

One user had the problem that the shiro.ini in Windows was:

stormpathClient.apiKeyFileLocation = C:/stormpathApiKey.properties 

while in Linux:

stormpathClient.apiKeyFileLocation = /home/user/stormpathApiKey.properties 

We might want to provide a way to read properties in an OS-independent way.

BTW, I suggested to user to do:

public class ApiKeyReader extends Reader {
    private static Logger logger = LoggerFactory.getLogger(ApiKeyReader.class);

    private FileReader reader;

    public ApiKeyReader() {
        try {
            String osName = System.getProperty("os.name");
            if(osName.contains("Mac OS") || osName.contains("linux")) {
                reader = new FileReader("/Users/mario/.stormpath/api1Key.properties");
            } else if(osName.contains("windows")) {
                reader = new FileReader("c:/apiKey.properties");
            } else {
                throw new RuntimeException("Unrecognized OS: " + osName);
            }
        } catch (FileNotFoundException e) {
            logger.error(e.getMessage());
        }

    }

    @Override
    public int read(char[] chars, int i, int i2) throws IOException {
        return reader.read(chars, i, i2);
    }

    @Override
    public void close() throws IOException {
        reader.close();
    }
}

Then, in shiro.ini change this:

stormpathClient.apiKeyFileLocation = C:/stormpathApiKey.properties

to

apikeyReader = com.stormpath.test.ApiKeyReader 
stormpathClient.apiKeyReader = $apikeyReader
@mrioan mrioan changed the title Coming from a support question: It would be nice to provide OS-independent ApiKeyLocation Coming from a support question: It would be nice to provide OS-independent ApiKey File Reader Aug 20, 2014
@descmdr
Copy link

descmdr commented Sep 28, 2014

Another option is to be able to place the file relative to the shiro.ini file. I'm not sure how to do that the "right way", but my own webapp is organized such that "classpath:../apiKey.properties" works.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants