BackendServiceImpl extends RemoteServiceServlet implements BackendService { static List<String> getGroupMemberships(Document samlToken) throws XPathExpressionException { List<String> groupMemberships = new ArrayList<>(); XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); String expression = "/*[local-name()='Assertion']" + "/*[local-name()='AttributeStatement']" + "/*[local-name()='Attribute'][@Name=\"memberOf\"]" + "/*[local-name()='AttributeValue']"; XPathExpression expr = xpath.compile(expression); NodeList nodeList = (NodeList) expr.evaluate(samlToken, XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); i++) { Node item = nodeList.item(i); groupMemberships.add(item.getTextContent().split(",")[0].split("=")[1]); } return groupMemberships; }  @Override void init(); @Override void destroy(); @Override DtoRegion[] loadRegions(String filter); @Override void storeRegions(DtoRegion[] regions); @Override DtoProductSet[] getProductSets(String filter); @Override DtoProcessorDescriptor[] getProcessors(String filterString); @Override DtoAggregatorDescriptor[] getAggregators(String filterString); @Override DtoMaskDescriptor[] getMasks(); @Override DtoProduction[] getProductions(String filter); @Override DtoProductionRequest getProductionRequest(String productionId); @Override DtoProductionResponse orderProduction(DtoProductionRequest dtoProductionRequest); @Override void saveRequest(DtoProductionRequest dtoProductionRequest); @Override void deleteRequest(String requestId); @Override DtoProductionRequest[] listRequests(); @Override void cancelProductions(String[] productionIds); @Override void deleteProductions(String[] productionIds); @Override void stageProductions(String[] productionIds); @Override void scpProduction(final String productionId, final String remotePath); @Override String[] listUserFiles(String dirPath); @Override String[] listSystemFiles(String dirPath); @Override boolean removeUserFile(String filePath); @Override boolean removeUserFiles(String... filePaths); @Override boolean removeUserDirectory(String filePath); @Override String checkUserRecordSource(String filePath); @Override float[] listUserRecordSource(String filePath); @Override DtoCalvalusConfig getCalvalusConfig(); @Override String[][] calculateL3Periods(String minDate, String maxDate, String steppingPeriodLength, String compositingPeriodLength); @Override DtoRegionDataInfo loadRegionDataInfo(String filePath); static final String VERSION; static final String COPYRIGHT_YEAR; }
@Test public void testGetGroupMemberships() throws Exception { Document doc = parseXml(originalSamlToken); doc = fixRootNode(doc); String[] groupMemberships = BackendServiceImpl.getGroupMemberships(doc).toArray(new String[0]); assertArrayEquals(new String[]{"cdg_user", "cdg_processing", "cdg_user_cat1"}, groupMemberships); }