IConnectionService conManager = Owl.getConnectionService();
URI feedUrl1 = new URI("http://www.rssowl.org/rssowl2dg/tests/connection/authrequired/feed_rss.xml");
URI feedUrl2 = new URI("http://www.rssowl.org/rssowl2dg/tests/connection/authrequired/feed_rss_copy.xml");
ICredentialsProvider credProvider = conManager.getCredentialsProvider(feedUrl1);
IFeed feed1 = new Feed(feedUrl1);
IFeed feed2 = new Feed(feedUrl2);
AuthenticationRequiredException e = null;
try {
Owl.getConnectionService().getHandler(feed1.getLink()).openStream(feed1.getLink(), null, null);
} catch (AuthenticationRequiredException e1) {
e = e1;
}
assertNotNull(e);
e = null;
ICredentials credentials = new ICredentials() {
public String getDomain() {
return null;
}
public String getPassword() {
return "admin";
}
public String getUsername() {
return "bpasero";
}
};
credProvider.setAuthCredentials(credentials, feedUrl1, null);
InputStream inS = Owl.getConnectionService().getHandler(feed1.getLink()).openStream(feed1.getLink(), null, null);
assertNotNull(inS);
Owl.getInterpreter().interpret(inS, feed1, null);
assertEquals("RSS 2.0", feed1.getFormat());
/* Test authentication by other realm is not working */
credProvider.setAuthCredentials(credentials, URIUtils.normalizeUri(feedUrl2, true), "Other Directory");
try {
Owl.getConnectionService().getHandler(feed2.getLink()).openStream(feed2.getLink(), null, null);
} catch (AuthenticationRequiredException e1) {
e = e1;
}
assertNotNull(e);
/* Test authentication by realm is working */
credProvider.setAuthCredentials(credentials, URIUtils.normalizeUri(feedUrl2, true), "Restricted Directory");
inS = Owl.getConnectionService().getHandler(feed2.getLink()).openStream(feed2.getLink(), null, null);
assertNotNull(inS);
Owl.getInterpreter().interpret(inS, feed2, null);
assertEquals("RSS 2.0", feed2.getFormat());
}