InMemoryUsernameProvider implements UsernameProvider { public void loadJsonMappings(String json) throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); @SuppressWarnings("unchecked") Map<String, ApplicationMappings> maps = (Map<String, ApplicationMappings>) mapper.readValue(json, new TypeReference<Map<String, ApplicationMappings>>() { }); setApplicationsMap(maps); } 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 testLoadJsonMappings() throws JsonParseException, JsonMappingException, IOException { InputStream stream = this.getClass().getClassLoader().getResourceAsStream("pentaho-transparent-authentication-mappings.json"); assertNotNull(stream); InMemoryUsernameProvider provider = new InMemoryUsernameProvider(); provider.loadJsonMappings(stream); String pentahoUser = provider.getUsername("showcase", "user0.3"); assertNotNull(pentahoUser); assertEquals("tiffany", pentahoUser); }