forked from apache/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for PasswordProvider interface to enable writing druid extens…
…ion which can get metadata store password from secured location or anywhere instead of plain text properties file
- Loading branch information
Himanshu Gupta
committed
Feb 25, 2015
1 parent
7c02212
commit 126262e
Showing
8 changed files
with
319 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
common/src/main/java/io/druid/metadata/DefaultPasswordProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.druid.metadata; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class DefaultPasswordProvider implements PasswordProvider | ||
{ | ||
private final String password; | ||
|
||
@JsonCreator | ||
public static DefaultPasswordProvider fromString(String str) | ||
{ | ||
return new DefaultPasswordProvider(str); | ||
} | ||
|
||
@JsonCreator | ||
public DefaultPasswordProvider(@JsonProperty("password") String password) | ||
{ | ||
this.password = password; | ||
} | ||
|
||
@Override | ||
@JsonProperty | ||
public String getPassword() | ||
{ | ||
return password; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.getClass().getCanonicalName(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
common/src/main/java/io/druid/metadata/PasswordProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.druid.metadata; | ||
|
||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
|
||
|
||
/** | ||
* Implement this for different ways to (optionally securely) access db passwords. | ||
*/ | ||
@JsonTypeInfo(use= JsonTypeInfo.Id.NAME, property="type", defaultImpl = DefaultPasswordProvider.class) | ||
@JsonSubTypes(value={ | ||
@JsonSubTypes.Type(name="default", value=DefaultPasswordProvider.class), | ||
}) | ||
public interface PasswordProvider | ||
{ | ||
public String getPassword(); | ||
} |
58 changes: 58 additions & 0 deletions
58
common/src/test/java/io/druid/metadata/DefaultPasswordProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.druid.metadata; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public class DefaultPasswordProviderTest | ||
{ | ||
private static final String pwd = "nothing"; | ||
private static final ObjectMapper jsonMapper = new ObjectMapper(); | ||
|
||
@Test | ||
public void testExplicitConstruction() { | ||
DefaultPasswordProvider pp = new DefaultPasswordProvider(pwd); | ||
Assert.assertEquals(pwd, pp.getPassword()); | ||
} | ||
|
||
@Test | ||
public void testFromStringConstruction() { | ||
DefaultPasswordProvider pp = DefaultPasswordProvider.fromString(pwd); | ||
Assert.assertEquals(pwd, pp.getPassword()); | ||
} | ||
|
||
@Test | ||
public void testDeserializationFromJsonString() throws Exception { | ||
PasswordProvider pp = jsonMapper.readValue("\"" + pwd + "\"", | ||
PasswordProvider.class); | ||
Assert.assertEquals(pwd, pp.getPassword()); | ||
} | ||
|
||
@Test | ||
public void testDeserializationFromJson() throws Exception { | ||
PasswordProvider pp = jsonMapper.readValue( | ||
"{\"type\": \"default\", \"password\": \"" + pwd + "\"}", | ||
PasswordProvider.class); | ||
Assert.assertEquals(pwd, pp.getPassword()); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
common/src/test/java/io/druid/metadata/MetadataStorageConnectorConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.druid.metadata; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public class MetadataStorageConnectorConfigTest { | ||
|
||
private static final ObjectMapper jsonMapper = new ObjectMapper(); | ||
|
||
@Test | ||
public void testMetadaStorageConnectionConfigSimplePassword() throws Exception | ||
{ | ||
testMetadataStorageConnectionConfig( | ||
true, | ||
"host", | ||
1234, | ||
"connectURI", | ||
"user", | ||
"\"nothing\"", | ||
"nothing"); | ||
} | ||
|
||
@Test | ||
public void testMetadaStorageConnectionConfigWithDefaultProviderPassword() throws Exception | ||
{ | ||
testMetadataStorageConnectionConfig( | ||
true, | ||
"host", | ||
1234, | ||
"connectURI", | ||
"user", | ||
"{\"type\":\"default\",\"password\":\"nothing\"}", | ||
"nothing"); | ||
} | ||
|
||
private void testMetadataStorageConnectionConfig( | ||
boolean createTables, | ||
String host, | ||
int port, | ||
String connectURI, | ||
String user, | ||
String pwdString, | ||
String pwd | ||
) throws Exception | ||
{ | ||
MetadataStorageConnectorConfig config = jsonMapper.readValue( | ||
"{" + | ||
"\"createTables\": \"" + createTables + "\"," + | ||
"\"host\": \"" + host + "\"," + | ||
"\"port\": \"" + port + "\"," + | ||
"\"connectURI\": \"" + connectURI + "\"," + | ||
"\"user\": \"" + user + "\"," + | ||
"\"password\": " + pwdString + | ||
"}", | ||
MetadataStorageConnectorConfig.class); | ||
|
||
Assert.assertEquals(host, config.getHost()); | ||
Assert.assertEquals(port, config.getPort()); | ||
Assert.assertEquals(connectURI, config.getConnectURI()); | ||
Assert.assertEquals(user, config.getUser()); | ||
Assert.assertEquals(pwd, config.getPassword()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...xing-hadoop/src/test/java/io/druid/indexer/updater/MetadataStorageUpdaterJobSpecTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.druid.indexer.updater; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public class MetadataStorageUpdaterJobSpecTest | ||
{ | ||
private static final ObjectMapper jsonMapper = new ObjectMapper(); | ||
|
||
@Test | ||
public void testMetadaStorageConnectionConfigSimplePassword() throws Exception | ||
{ | ||
testMetadataStorageUpdaterJobSpec( | ||
"segments_table", | ||
"db", | ||
"jdbc:mysql://localhost/druid", | ||
"druid", | ||
"\"nothing\"", | ||
"nothing"); | ||
} | ||
|
||
@Test | ||
public void testMetadaStorageConnectionConfigWithDefaultProviderPassword() throws Exception | ||
{ | ||
testMetadataStorageUpdaterJobSpec( | ||
"segments_table", | ||
"db", | ||
"jdbc:mysql://localhost/druid", | ||
"druid", | ||
"{\"type\":\"default\",\"password\":\"nothing\"}", | ||
"nothing"); | ||
} | ||
|
||
private void testMetadataStorageUpdaterJobSpec( | ||
String segmentTable, | ||
String type, | ||
String connectURI, | ||
String user, | ||
String pwdString, | ||
String pwd | ||
) throws Exception | ||
{ | ||
MetadataStorageUpdaterJobSpec spec = jsonMapper.readValue( | ||
"{" + | ||
"\"type\": \"" + type + "\",\n" + | ||
"\"connectURI\": \"" + connectURI + "\",\n" + | ||
"\"user\": \"" + user + "\",\n" + | ||
"\"password\": " + pwdString + ",\n" + | ||
"\"segmentTable\": \"" + segmentTable + "\"\n" + | ||
"}", | ||
MetadataStorageUpdaterJobSpec.class); | ||
|
||
Assert.assertEquals(segmentTable, spec.getSegmentTable()); | ||
Assert.assertEquals(type, spec.getType()); | ||
Assert.assertEquals("jdbc:mysql://localhost/druid", spec.get().getConnectURI()); | ||
Assert.assertEquals(user, spec.get().getUser()); | ||
Assert.assertEquals(pwd, spec.get().getPassword()); | ||
} | ||
} |