public static Predicate < Credential > newCredentialSelectionPredicate ( final String selectionCriteria ) { try { if ( StringUtils . isBlank ( selectionCriteria ) ) { return credential -> true ; } if ( selectionCriteria . endsWith ( ".groovy" ) ) { val loader = new DefaultResourceLoader ( ) ; val resource = loader . getResource ( selectionCriteria ) ; val script = IOUtils . toString ( resource . getInputStream ( ) , StandardCharsets . UTF_8 ) ; val clz = AccessController . doPrivileged ( ( PrivilegedAction < Class < Predicate > > ) ( ) -> { val classLoader = new GroovyClassLoader ( Beans . class . getClassLoader ( ) , new CompilerConfiguration ( ) , true ) ; return classLoader . parseClass ( script ) ; } ) ; return clz . getDeclaredConstructor ( ) . newInstance ( ) ; } val predicateClazz = ClassUtils . getClass ( selectionCriteria ) ; return ( Predicate < org . apereo . cas . authentication . Credential > ) predicateClazz . getDeclaredConstructor ( ) . newInstance ( ) ; } catch ( final Exception e ) { val predicate = Pattern . compile ( selectionCriteria ) . asPredicate ( ) ; return credential -> predicate . test ( credential . getId ( ) ) ; } }
Gets credential selection predicate .