InMemoryUsernameProvider implements UsernameProvider { @Override public String getUsername(String externalApplicationName, String externalUsername) { ApplicationMappings existentMapping = getApplicationsMap().get(externalApplicationName); if (existentMapping == null) { throw new MappingNotFoundException( "Application named '" + externalApplicationName + "' is not present in the current mappings"); } String pentahoUsername = existentMapping.getUsernamesMap().get(externalUsername); if (pentahoUsername == null) { throw new MappingNotFoundException("External username '" + externalUsername + "' not found in the mappings for application '" + externalApplicationName + "'"); } return pentahoUsername; } 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 testGetUsername() { inMemoryProvider.addMapping(APP, EXTERNAL_USER, PENTAHO_USER); String username = inMemoryProvider.getUsername(APP, EXTERNAL_USER); assertEquals(PENTAHO_USER, username); }
@Test(expected = MappingNotFoundException.class) public void testGetUsernameNotFound() { inMemoryProvider.getUsername(APP, "iDoNotExist"); }