Skip to content

Commit

Permalink
ARTEMIS-4273 mask command not using codec props
Browse files Browse the repository at this point in the history
  • Loading branch information
jbertram authored and clebertsuconic committed May 11, 2023
1 parent c9c819a commit 5320bd0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public Object execute(ActionContext context) throws Exception {
codec = PasswordMaskingUtil.getCodec(brokerConfiguration.getPasswordCodec());
} else {
codec = PasswordMaskingUtil.getDefaultCodec();
codec.init(params);
}
codec.init(params);

String masked = codec.encode(password);
context.out.println("result: " + masked);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,9 @@ public void testMaskCommandWithPasswordCodec() throws Exception {
mask.setPasswordCodec(true);
result = (String) mask.execute(context);
assertEquals(TestPasswordCodec.class, mask.getCodec().getClass());
assertEquals(result, result);
assertEquals(((TestPasswordCodec) mask.getCodec()).getPropertyOne(), "1234");
assertEquals(((TestPasswordCodec) mask.getCodec()).getPropertyTwo(), "9876");
assertEquals(password, result);
}

@Test
Expand Down Expand Up @@ -2285,6 +2287,19 @@ private void contains(JsonArray users, String username, String role, boolean con
}

public static class TestPasswordCodec implements SensitiveDataCodec<String> {
public String PROP_NAME_ONE = "propertyNameOne";
public String PROP_NAME_TWO = "propertyNameTwo";

private String propertyOne;
private String propertyTwo;

@Override
public void init(Map<String, String> params) throws Exception {
if (params != null) {
propertyOne = params.get(PROP_NAME_ONE);
propertyTwo = params.get(PROP_NAME_TWO);
}
}

@Override
public String decode(Object mask) throws Exception {
Expand All @@ -2295,6 +2310,14 @@ public String decode(Object mask) throws Exception {
public String encode(Object secret) throws Exception {
return secret.toString();
}

public String getPropertyOne() {
return propertyOne;
}

public String getPropertyTwo() {
return propertyTwo;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ under the License.

<large-messages-directory>./target/large-messages</large-messages-directory>

<password-codec>org.apache.activemq.cli.test.ArtemisTest$TestPasswordCodec</password-codec>
<password-codec>org.apache.activemq.cli.test.ArtemisTest$TestPasswordCodec;propertyNameOne=1234;propertyNameTwo=9876</password-codec>

<connectors>
<!-- Default Connector. Returned to clients during broadcast and distributed around cluster. See broadcast and discovery-groups -->
Expand Down

0 comments on commit 5320bd0

Please sign in to comment.