5

Continuation of my earlier question. I'm working on CAS 5 to modify according to my needs. With help of CAS tutorial now I've done customized authentication. Now I've added below dependency to pom.xml to connect to database by following link.

<dependency>
    <groupId>org.apereo.cas</groupId>
    <artifactId>cas-server-support-jdbc</artifactId>
    <version>${cas.version}</version>
</dependency>

And added database authentication properties in application.properties

cas.authn.jdbc.query[0].sql=some query
cas.authn.jdbc.query[0].url=jdbc:postgresql://127.0.0.1/dbcas
cas.authn.jdbc.query[0].dialect=org.hibernate.dialect.PostgreSQLDialect
cas.authn.jdbc.query[0].user=readonly
cas.authn.jdbc.query[0].password=readonly
cas.authn.jdbc.query[0].ddlAuto=none
cas.authn.jdbc.query[0].driverClass=org.postgresql.Driver

But it's not working means getting

Type 'org.apereo.cas.configuration.model.support.jdbc.QueryJdbcAuthenticationProperties' has no property 'url'

Am I missing anything here. Any one please help me in this.

Update:

I've checked the source of QueryJdbcAuthenticationProperties

@RequiredProperty
private String sql;

And AbstractJpaProperties

private String dialect;
private String ddlAuto;
@RequiredProperty
private String driverClass;
@RequiredProperty
private String url;
@RequiredProperty
private String user;
@RequiredProperty
private String password;

I found same two classes in cas-server-core-api-configuration-model-5.3.2.jar file and these two are not found in any other package and jar file.

What's the issue here. I'm unable to identified it.

How to know where these properties (cas.authn.jdbc.query) has been defined?

I thought that object has been created w.r.t child class QueryJdbcAuthenticationProperties while defining these database properties.

nay
  • 95
  • 12

2 Answers2

1

When you look into the classes you describe, i. e. AbstractJpaProperties and QueryJdbcAuthenticationProperties, you will see something like this at their beginning:

// ...
import lombok.Getter;
import lombok.Setter;

// ...
@Getter
@Setter
public abstract class AbstractJpaProperties implements Serializable {

    // ...
    @RequiredProperty
    private String url = "jdbc:hsqldb:mem:cas-hsql-database";

And no getters and setters for the fields. That means that Lombok takes care of generating them at compile time. If you open the class directly from cas-server-core-api-configuration-model-5.3.2.jar, your IDE should show you the getters and setters in the class outline (in the compiled class only).

So maybe you try to build those classes (or the whole CAS?) yourself without having the Lombok library in the build path? Therefore, you get the error:

Type 'org.apereo.cas.configuration.model.support.jdbc.QueryJdbcAuthenticationProperties' has no property 'url'

If so, I would recommend you to rather use the CAS WAR Overlay Installation instead - it's generally easier for common CAS usage. If you still do need to touch those classes, you need to setup the Lombok as I mentioned above.

Finally, as Karan writes, you will also probably need to add an appropriate dependency on the PostgreSQL driver, so that you don't get NoClassDefFoundError or similar when your application gets further in the execution.

Petr Bodnár
  • 496
  • 3
  • 14
  • I've added lombok dependency to `pom.xml` and build war again even though showing same error. – nay Dec 13 '19 at 12:27
  • Do you use up-to-date Lombok version then? See https://stackoverflow.com/questions/53866929/unable-to-use-lombok-with-java-11. And do you still need to build from source? – Petr Bodnár Dec 13 '19 at 12:41
  • I thought that it's due to object creation not because of lombok. I've changed all properties from `private` to `public` in `AbstractJpaProperties` even though it's not working. – nay Dec 13 '19 at 12:50
  • Well, my guess is that it really is an error during object creation - that the error appears after creating an instance of `QueryJdbcAuthenticationProperties` and trying to call a corresponding setter - I think that making the field `public` is not enough - try to define getter and setter as well and see what happens... – Petr Bodnár Dec 13 '19 at 13:02
  • Defined getter and setter as well still not working. I want to know where these properties (`cas.authn.jdbc.query`) has been defined? We don't have the rights to create object of `QueryJdbcAuthenticationProperties`. – nay Dec 13 '19 at 13:11
  • So 1) It would be great if you could say when and where exactly you get an error. 2) Of course you don't need to create instances of `QueryJdbcAuthenticationProperties`, it's the job of the CAS and the jdbc module on the classpath, they should also take care of using all the `cas.authn.jdbc.*` settings "automagically". 3) Don't you really want just to use the overlay? :) – Petr Bodnár Dec 13 '19 at 16:08
  • The same error showing in eclipse not even on console. I'm not creating any object here everything is comes by default. I'm just using CAS overlay even though getting error. – nay Dec 14 '19 at 06:09
  • Looks like we don't understand each other, a language barrier maybe. I would start a new chat, but it seems like it's not working / available... – Petr Bodnár Dec 14 '19 at 11:30
-1

your properties are setup correctly. But CAS 5.x additionally needs drivers (not always) for some databases. If you could include the following in your pom as dependency, it should provide the necessary drivers are specified in postgres driver support

Update your pom to include:

<dependency>
     <groupId>org.apereo.cas</groupId>
     <artifactId>cas-server-support-jdbc-drivers</artifactId>
     <version>${cas.version}</version>
</dependency>
Karan M
  • 97
  • 1
  • 1
  • If you look [closer](https://mvnrepository.com/artifact/org.apereo.cas/cas-server-support-jdbc/5.0.4), you will see that `cas-server-support-jdbc-drivers` is a transitive dependency of `cas-server-support-jdbc`. So the problem shouldn't be here. – Petr Bodnár Dec 12 '19 at 17:18
  • Sorry, that was true for version 5.0.4, but is no longer true for 5.3 - drivers are no longer transitive, it seems... – Petr Bodnár Dec 12 '19 at 17:32