Skip to content

Commit

Permalink
Add support for Basic Authentication to XMLA driver (contributed by L…
Browse files Browse the repository at this point in the history
…uc Boudreau); add Base64 utilities (needed for Basic Authentication); fix MetadataTest for additional functions just added to mondrian.

git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@65 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Jan 24, 2008
1 parent 16524c8 commit aeffdfb
Show file tree
Hide file tree
Showing 5 changed files with 1,595 additions and 5 deletions.
25 changes: 21 additions & 4 deletions src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ abstract class XmlaOlap4jConnection implements OlapConnection {
+ XmlaOlap4jDriver.Property.Server.name()
+ "' must be specified");
}

// Basic authentication. Make sure the credentials passed as standard
// JDBC parameters override any credentials already included in the URL
// as part of the standard URL scheme.
if (map.containsKey("user") && map.containsKey("password")) {
serverUrl = serverUrl.replaceFirst(
":\\/\\/(.*\\@){0,1}",
"://"
.concat(map.get("user"))
.concat(":")
.concat(map.get("password")
.concat("@")));
}

try {
this.serverUrl = new URL(serverUrl);
} catch (MalformedURLException e) {
Expand Down Expand Up @@ -641,7 +655,10 @@ public void handle(Element row, Context context, List<XmlaOlap4jDimension> list)
}

static class HierarchyHandler extends HandlerImpl<XmlaOlap4jHierarchy> {
public void handle(Element row, Context context, List<XmlaOlap4jHierarchy> list) {
public void handle(
Element row, Context context, List<XmlaOlap4jHierarchy> list)
throws OlapException
{
/*
Example:
Expand Down Expand Up @@ -687,9 +704,9 @@ public void handle(Element row, Context context, List<XmlaOlap4jHierarchy> list)
stringElement(row, "DEFAULT_MEMBER");
list.add(
new XmlaOlap4jHierarchy(
context.getDimension(row), hierarchyUniqueName, hierarchyName,
hierarchyCaption, description, allMember != null,
defaultMemberUniqueName));
context.getDimension(row), hierarchyUniqueName,
hierarchyName, hierarchyCaption, description,
allMember != null, defaultMemberUniqueName));
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/org/olap4j/driver/xmla/XmlaOlap4jDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
package org.olap4j.driver.xmla;

import org.olap4j.impl.Base64;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;
Expand Down Expand Up @@ -214,6 +216,14 @@ public byte[] get(URL url, String request) throws IOException {
urlConnection.setDoOutput(true);
urlConnection.setRequestProperty("content-type", "text/xml");

// Encode credentials for basic authentication
if (url.getUserInfo() != null) {
String encoding =
Base64.encodeBytes(url.getUserInfo().getBytes(), 0);
urlConnection.setRequestProperty(
"Authorization", "Basic " + encoding);
}

// Send data (i.e. POST). Assume default encoding.
urlConnection.getOutputStream().write(request.getBytes());

Expand Down
Loading

0 comments on commit aeffdfb

Please sign in to comment.