I create a separate jar which I make part of cas overlay through maven dependency, which in turn is detected through src/webapp/META-INF/spring.factories put in overlay with content:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=my.domain.apps.cas.MyAuthenticationEventExecutionPlanConfiguration Following is the pom for that jar: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd "> <modelVersion>4.0.0</modelVersion> <groupId>my.domain.libs</groupId> <artifactId>cas-server-my-support-jdbc</artifactId> <name>support-jdbc</name> <packaging>jar</packaging> <properties> <cas.version>5.1.0</cas.version> <springboot.version>1.5.3.RELEASE</springboot.version> <!-- app.server could be -jetty, -undertow, -tomcat, or blank if you plan to provide appserver --> <app.server></app.server> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.apereo.cas</groupId> <artifactId>cas-server-core-authentication</artifactId> </dependency> <dependency> <groupId>org.apereo.cas</groupId> <artifactId>cas-server-core-configuration</artifactId> </dependency> <dependency> <groupId>org.apereo.cas</groupId> <artifactId>cas-server-core-webflow</artifactId> <version>${cas.version}</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>com.rimerosolutions.maven.plugins</groupId> <artifactId>wrapper-maven-plugin</artifactId> <version>0.0.4</version> <configuration> <verifyDownload>true</verifyDownload> <checksumAlgorithm>MD5</checksumAlgorithm> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${springboot.version}</version> <configuration> <mainClass>org.springframework.boot.loader.WarLauncher</mainClass> <addResources>true</addResources> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <warName>cas</warName> <failOnMissingWebXml>false</failOnMissingWebXml> <recompressZippedFiles>false</recompressZippedFiles> <archive> <compress>false</compress> <manifestFile>${project.build.directory}/war/work/org.apereo.cas/cas-server-webapp/META-INF/MANIFEST.MF </manifestFile> </archive> <overlays> <overlay> <groupId>org.apereo.cas</groupId> <artifactId>cas-server-webapp</artifactId> </overlay> </overlays> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> </plugin> </plugins> <finalName>cas-server-support-jdbc-conicet</finalName> </build> <repositories> <repository> <id>sonatype-releases</id> <url>http://oss.sonatype.org/content/repositories/releases/ </url> <snapshots> <enabled>false</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </repository> <repository> <id>sonatype-snapshots</id> <url>https://oss.sonatype.org/content/repositories/snapshots/ </url> <snapshots> <enabled>true</enabled> </snapshots> <releases> <enabled>false</enabled> </releases> </repository> <repository> <id>shibboleth-releases</id> <url> https://build.shibboleth.net/nexus/content/repositories/releases</url> </repository> <repository> <id>spring-milestones</id> <url>https://repo.spring.io/milestone</url> </repository> </repositories> <profiles> <profile> <activation> <activeByDefault>false</activeByDefault> </activation> <id>pgp</id> <build> <plugins> <plugin> <groupId>com.github.s4u.plugins</groupId> <artifactId>pgpverify-maven-plugin</artifactId> <version>1.1.0</version> <executions> <execution> <goals> <goal>check</goal> </goals> </execution> </executions> <configuration> <pgpKeyServer>hkp://pool.sks-keyservers.net </pgpKeyServer> <pgpKeysCachePath>${settings.localRepository}/pgpkeys-cache</pgpKeysCachePath> <scope>test</scope> <verifyPomFiles>true</verifyPomFiles> <failNoSignature>false</failNoSignature> </configuration> </plugin> </plugins> </build> </profile> </profiles> </project> 2017-12-11 11:51 GMT-03:00 noumann.f <[email protected]>: > Thanks again for your patience, > > My real problem is that the custom code I put in the *src/main/java* is > being compiled but not executed! > > In other word the server didn't reach the customization code I'm making > even when I add these to the properties file: > > cas.authn.policy.requiredHandlerAuthenticationPolicyEnabled=true > cas.authn.policy.req.tryAll=false > cas.authn.policy.req.handlerName=FileAuthenticationHandler > cas.authn.policy.req.enabled=true > > I gave up the JDBC handler for now, and trying to make a simpler one like > customizing the *FileAuthenticationHandler*, just copying the structure > and the code into custom ones and trying to operate it. > > And still facing the same problem, it isn't running my custom registration > and handler, it runs the generic file ones!!! > > Authentication Handler: > package org.custom; > > // imports are copied from the original files > > public class CustomFileAuthenticationHandler extends > AbstractUsernamePasswordAuthenticationHandler { > /** The default separator in the file. */ > public static final String DEFAULT_SEPARATOR = "::"; > > /** The separator to use. */ > private final String separator; > > /** The filename to read the list of usernames from. */ > private final Resource fileName; > > public CustomFileAuthenticationHandler(final String name, final > ServicesManager servicesManager, final PrincipalFactory principalFactory, > final Resource fileName, final String > separator) { > super(name, servicesManager, principalFactory, null); > this.fileName = fileName; > this.separator = separator; > } > > @Override > protected HandlerResult authenticateUsernamePasswordInternal(final > UsernamePasswordCredential transformedCredential, > final > String originalPassword) > throws GeneralSecurityException, PreventedException { > try { > if (this.fileName == null) { > throw new FileNotFoundException("Filename does not exist" > ); > } > final String username = transformedCredential.getUsername(); > final String passwordOnRecord = getPasswordOnRecord(username); > if (StringUtils.isBlank(passwordOnRecord)) { > throw new AccountNotFoundException(username + " not found > in backing file."); > } > if (matches(originalPassword, passwordOnRecord)) { > return createHandlerResult(transformedCredential, this. > principalFactory.createPrincipal(username), null); > } > } catch (final IOException e) { > throw new PreventedException("IO error reading backing file", > e); > } > throw new FailedLoginException(); > } > > /** > * Gets the password on record. > * > * @param username the username > * @return the password on record > * @throws IOException Signals that an I/O exception has occurred. > */ > private String getPasswordOnRecord(final String username) throws > IOException { > return Files.lines(fileName.getFile().toPath()) > .map(line -> line.split(this.separator)) > .filter(lineFields -> { > final String userOnRecord = lineFields[0]; > return username.equals(userOnRecord); > }) > .map(lineFields -> lineFields[1]) > .findFirst() > .orElse(null); > } > } > > > Registration class: > > > package org.custom; > > // imports are copied from the original > > @Configuration("customFileAuthenticationEventExecutionPlanConfiguration") > @EnableConfigurationProperties(CasConfigurationProperties.class) > public class CustomFileAuthenticationEventExecutionPlanConfiguration > implements AuthenticationEventExecutionPlanConfigurer { > private static final Logger LOGGER = LoggerFactory.getLogger(Custom > FileAuthenticationEventExecutionPlanConfiguration.class); > > @Autowired(required = false) > @Qualifier("customFilePasswordPolicyConfiguration") > private PasswordPolicyConfiguration customFilePasswordPolicyConfig > uration; > > @Autowired > @Qualifier("servicesManager") > private ServicesManager servicesManager; > > @Autowired > private CasConfigurationProperties casProperties; > > @Autowired > @Qualifier("personDirectoryPrincipalResolver") > private PrincipalResolver personDirectoryPrincipalResolver; > > @ConditionalOnMissingBean(name = "filePrincipalFactory") > @Bean > public PrincipalFactory filePrincipalFactory() { > return new DefaultPrincipalFactory(); > } > > @RefreshScope > @Bean > public AuthenticationHandler customFileAuthenticationHandler() { > final FileAuthenticationProperties fileProperties = casProperties. > getAuthn().getFile(); > final FileAuthenticationHandler h = new FileAuthenticationHandler( > fileProperties.getName(), servicesManager, filePrincipalFactory(), > fileProperties.getFilename(), fileProperties.getSeparator > ()); > > > h.setPasswordEncoder(Beans.newPasswordEncoder(fileProperties. > getPasswordEncoder())); > if (customFilePasswordPolicyConfiguration != null) { > h.setPasswordPolicyConfiguration(customFilePasswordPolicyCon > figuration); > } > h.setPrincipalNameTransformer(Beans.newPrincipalNameTransformer( > fileProperties.getPrincipalTransformation())); > > return h; > } > > @Override > public void configureAuthenticationExecutionPlan(final > AuthenticationEventExecutionPlan plan) { > if (casProperties.getAuthn().getFile().getFilename() != null) { > LOGGER.debug("zzz Added file-based authentication handler"); > plan.registerAuthenticationHandlerWithPrincipalResolver(cust > omFileAuthenticationHandler(), personDirectoryPrincipalResolver); > } > } > } > > > CAS Properties: > cas.authn.file.separator=:: > cas.authn.file.filename=file:///etc/cas/usersfile > cas.authn.file.name=usersfile > > .... > > cas.authn.policy.requiredHandlerAuthenticationPolicyEnabled=true > cas.authn.policy.req.tryAll=false > cas.authn.policy.req.handlerName=CustomFileAuthenticationHandler > cas.authn.policy.req.enabled=true > > > On Wednesday, December 6, 2017 at 11:18:28 PM UTC+2, noumann.f wrote: >> >> Hi, >> >> I need to create a custom JDBC authentication handler, I'd done this >> previously with version 4.x but with new version 5.1.x things have changed >> !! >> >> I'm following the guide in here: https://apereo.github.io >> /2017/02/02/cas51-authn-handlers >> but I need more details about registering the new handler and how to >> create special properties for it in the cas.properties and then reach them >> in the code! >> >> Best regards, >> > -- > - Website: https://apereo.github.io/cas > - Gitter Chatroom: https://gitter.im/apereo/cas > - List Guidelines: https://goo.gl/1VRrw7 > - Contributions: https://goo.gl/mh7qDG > --- > You received this message because you are subscribed to the Google Groups > "CAS Community" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit https://groups.google.com/a/ > apereo.org/d/msgid/cas-user/d9bf60e4-910c-4518-987d- > a3547bc18bb5%40apereo.org > <https://groups.google.com/a/apereo.org/d/msgid/cas-user/d9bf60e4-910c-4518-987d-a3547bc18bb5%40apereo.org?utm_medium=email&utm_source=footer> > . > -- - Website: https://apereo.github.io/cas - Gitter Chatroom: https://gitter.im/apereo/cas - List Guidelines: https://goo.gl/1VRrw7 - Contributions: https://goo.gl/mh7qDG --- You received this message because you are subscribed to the Google Groups "CAS Community" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/a/apereo.org/d/msgid/cas-user/CAMY5midTUH_x%3DsJwgw9B_19RM-4mnmV92Mo7eKObBAh2SiAogg%40mail.gmail.com.
