SAMLUtil { public static String getNCNameString(String value) { if (value == null) { return null; } String cleanValue = value.replaceAll("[^a-zA-Z0-9-_.]", "_"); if (cleanValue.startsWith("-")) { cleanValue = "_" + cleanValue.substring(1); } return cleanValue; }  static String getBindingForEndpoint(Endpoint endpoint); static SingleLogoutService getLogoutServiceForBinding(SSODescriptor descriptor, String binding); static String getLogoutBinding(IDPSSODescriptor idp, SPSSODescriptor sp); static IDPSSODescriptor getIDPSSODescriptor(EntityDescriptor idpEntityDescriptor); static AssertionConsumerService getConsumerService(SPSSODescriptor ssoDescriptor, Integer index); static ArtifactResolutionService getArtifactResolutionService(IDPSSODescriptor idpssoDescriptor, int endpointIndex); static boolean processFilter(String filterName, HttpServletRequest request); static boolean compare(byte[] hashID, String entityId); static void verifyAlias(String alias, String entityId); static List<String> getBase64EncodeCertificates(KeyInfo keyInfo); static List<String> getBase64EncodedCertificates(X509Data x509Data); static boolean isECPRequest(HttpServletRequest request); static T getEndpoint(List<T> endpoints, String messageBinding, InTransport inTransport); static T getEndpoint(List<T> endpoints, String messageBinding, InTransport inTransport, URIComparator uriComparator); static IDPSSODescriptor getIDPDescriptor(MetadataManager metadata, String idpId); static Element marshallMessage(XMLObject message); @SuppressWarnings("unchecked") static Element marshallAndSignMessage(SignableXMLObject signableMessage, Credential signingCredential, String signingAlgorithm, String digestMethodAlgorithm, String keyInfoGenerator); static boolean isDateTimeSkewValid(int skewInSeconds, DateTime time); static boolean isDateTimeSkewValid(int skewInSeconds, long expiryInSeconds, DateTime time); static String getNCNameString(String value); static HostnameVerifier getHostnameVerifier(String hostnameVerificationType); static String getMetadataAsString(MetadataManager metadataManager, KeyManager keyManager, EntityDescriptor descriptor, ExtendedMetadata extendedMetadata);  }
@Test public void testNCNameClean() { assertNull(SAMLUtil.getNCNameString(null)); assertEquals("", SAMLUtil.getNCNameString("")); assertEquals("_", SAMLUtil.getNCNameString("-")); assertEquals("_http___test_8080_context_xyz__3", SAMLUtil.getNCNameString("-http: assertEquals("urn_xyz_test", SAMLUtil.getNCNameString("urn:xyz:test")); assertEquals("test.user", SAMLUtil.getNCNameString("test.user")); assertEquals("test___2", SAMLUtil.getNCNameString("test&^%2")); }