Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.
This repository was 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

Description

@mrioan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions