InMemoryUsernameProvider implements UsernameProvider { public void loadJsonMappingsFromFile(String fileName) throws JsonParseException, JsonMappingException, IOException { String text = null; try { File file = new File(fileName); text = FileUtils.readFileToString(file); } catch (Exception e) { logger.error("Error", e); throw e; } loadJsonMappings(text); } InMemoryUsernameProvider(); String getInitFileLocation(); void setInitFileLocation(String initFileLocation); Map<String, ApplicationMappings> getApplicationsMap(); void setApplicationsMap(Map<String, ApplicationMappings> applicationsMap); @Override String getUsername(String externalApplicationName, String externalUsername); void addMapping(String app, String externalUsername, String pentahoUser); String removeMapping(String app, String externalUsername); String toJson(); void loadJsonMappings(String json); void loadJsonMappings(InputStream stream); void initFromConfiguration(); void loadJsonMappingsFromFile(String fileName); @Override boolean isAppNameMapped(String externalAppName); public String initFileLocation; }
@Test public void testLoadJsonMappingsFromFile() throws JsonParseException, JsonMappingException, IOException { String filename = "src/test/resources/pentaho-transparent-authentication-mappings.json"; inMemoryProvider.loadJsonMappingsFromFile(filename); String pentahoUser = inMemoryProvider.getUsername("showcase", "user0.3"); assertNotNull(pentahoUser); assertEquals("tiffany", pentahoUser); }