Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Radicale Support? #59

Open
DasSharkk opened this issue Mar 15, 2024 · 7 comments
Open

Radicale Support? #59

DasSharkk opened this issue Mar 15, 2024 · 7 comments

Comments

@DasSharkk
Copy link

Brief Description

I was trying to connect to a Radicale CalDAV Server using ical4j-connector but I wasn't able to.

Context

iCal4j Version: 4.0.0-rc3
iCal4j-connector Version: 2.0.0-alpha5
Docker-Radicale Version: 3.1.8

Action

I was trying to connect to a Radicale server with ical4j-connector using this code:

CalDavCalendarStore store = new CalDavCalendarStore(
    "-//Name//iCal4j 1.0//EN",
    URI.create("12.34.567.89:5232").toURL(),
    PathResolver.Defaults.RADICALE);
DavSessionConfiguration davSessionConfiguration = new DavSessionConfiguration().withUser("user").withPassword("password".toCharArray());
store.connect(davSessionConfiguration);
store.getCollections().forEach(System.out::println);

Result

When I run the code I get an 401 Unauthorized Error even though the user and password is correct.

Exception in thread "main" java.lang.RuntimeException: Method failed: HTTP/1.0 401 Unauthorized
	at org.ical4j.connector.dav.response.GetSupportedFeatures.handleResponse(GetSupportedFeatures.java:14)
	at org.ical4j.connector.dav.response.GetSupportedFeatures.handleResponse(GetSupportedFeatures.java:9)
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:223)
	at org.ical4j.connector.dav.DefaultDavClient.execute(DefaultDavClient.java:408)
	at org.ical4j.connector.dav.DefaultDavClient.getSupportedFeatures(DefaultDavClient.java:202)
	at org.ical4j.connector.dav.AbstractDavObjectStore.connect(AbstractDavObjectStore.java:131)
	at software.julius.Main.main(Main.java:36)

If I disable the entire authentication in the Radicale config I'm able to connect because it's not possible to get an Error 401 but it can't find and print out any collections which it should. If I try to access a specific collection I get an Error 404 Not Found.

I know there is a issue from 2018 that already states that Radicale doesn't work but I thought I would ask again because Radicale now exists in the PathResolver Defaults so I think this is unwanted behavior.

@benfortuna
Copy link
Member

benfortuna commented Mar 16, 2024

Hi, thanks for trying out the latest version of ical4j-connector.

We do have an integration test for Radicale, in which we use a credentials provider rather than user/password:

        store.connect(new DavSessionConfiguration().withCredentialsProvider(getCredentialsProvider())
                .withUser(getUser()).withWorkspace(getWorkspace()))

        ....

        default CredentialsProvider getCredentialsProvider() {
          Credentials credentials = new UsernamePasswordCredentials(getUser(), 'test');
          CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
          credentialsProvider.setCredentials(AuthScope.ANY, credentials);
          credentialsProvider
      }

I will need to check why user/password doesn't work, but for now I would suggest using credentials provider with your session configuration.

@DasSharkk
Copy link
Author

Hi, thanks for the quick response.
I think the authentication works now because I don't get an 401 Error anymore.
But when I try to get all the Collections with store.getCollections() I now get an Error 403:

Exception in thread "main" java.lang.RuntimeException: Unexpected status code: 403
	at org.ical4j.connector.dav.response.AbstractResponseHandler.getMultiStatus(AbstractResponseHandler.java:76)
	at org.ical4j.connector.dav.response.GetResourceProperties.handleResponse(GetResourceProperties.java:15)
	at org.ical4j.connector.dav.response.GetResourceProperties.handleResponse(GetResourceProperties.java:10)
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:223)
	at org.ical4j.connector.dav.DefaultDavClient.execute(DefaultDavClient.java:408)
	at org.ical4j.connector.dav.DefaultDavClient.propFind(DefaultDavClient.java:233)
	at org.ical4j.connector.dav.CalDavCalendarStore.findCalendarHomeSet(CalDavCalendarStore.java:205)
	at org.ical4j.connector.dav.CalDavCalendarStore.findCalendarHomeSet(CalDavCalendarStore.java:187)
	at org.ical4j.connector.dav.CalDavCalendarStore.getCollections(CalDavCalendarStore.java:226)
	at software.julius.CalendarUtils.createICSFromTimetable(CalendarUtils.java:80)
	at software.julius.Main.main(Main.java:36)

My code:

CalDavCalendarStore store = new CalDavCalendarStore(
    "-//Name//iCal4j 1.0//EN",
    URI.create(Main.configUtils.getCalDAVDomain()).toURL(),
    PathResolver.Defaults.RADICALE);

Credentials credentials = new UsernamePasswordCredentials(Main.configUtils.getCalDAVUser(), Main.configUtils.getCalDAVPassword());
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, credentials);

DavSessionConfiguration davSessionConfiguration = new DavSessionConfiguration().withCredentialsProvider(credentialsProvider);
store.connect(davSessionConfiguration);

System.out.println("Collections");
System.out.println(store.getCollections());

@DasSharkk
Copy link
Author

@benfortuna Any updates?

@benfortuna
Copy link
Member

benfortuna commented Mar 29, 2024

Actually I just had another look at your stacktrace and I can see in my testing this is working for me.

Note this is how I configure the DAVSessionConfiguration:

new DavSessionConfiguration().withCredentialsProvider(getCredentialsProvider())
                .withUser(getUser()).withWorkspace(getWorkspace())

It looks like you may be missing the "user" in addition to credentials provider. This obviously is a bit confusing and probably needs to be fixed, but for now I would put both user and credentials provider.

@DasSharkk
Copy link
Author

DasSharkk commented Mar 30, 2024

Thanks! It works with user set in the DAVSessionConfiguration. It didn't work at first because my user contained a number ig.

But I still have a problem with getting the collections.
When I run

CalDavCalendarStore store = new CalDavCalendarStore(
    "-//Name//iCal4j 1.0//EN",
    URI.create("mycaldavurl").toURL(),
    PathResolver.Defaults.RADICALE);

Credentials credentials = new UsernamePasswordCredentials("test", "someverysafepassword");
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, credentials);

DavSessionConfiguration davSessionConfiguration = new DavSessionConfiguration().withUser("test").withCredentialsProvider(credentialsProvider);
store.connect(davSessionConfiguration);

System.out.println("Collections");
System.out.println(store.getCollections());

the output is just

Collections
[]

even though a collection exists for the user:
image

Any idea why this is?

@benfortuna
Copy link
Member

Yeah so I'm looking into that as I am seeing the same. It appears the PROPFIND /user call is not returning the collections, so it may be the wrong properties, etc. being requested.

Maybe keep this ticket open and I'll update when I have done more testing.

@DasSharkk
Copy link
Author

Okay, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants