Skip to content

Commit

Permalink
Rename masking method method to 'getMaskedValue'.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaura committed Jun 10, 2024
1 parent a44aa0a commit 6e7ae15
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
package org.wso2.carbon.identity.conditional.auth.functions.utils;

/**
* Function to mask the given content if log masking is enabled.
* Function to mask the given value if log masking is enabled.
*/
@FunctionalInterface
public interface GetMaskedContentFunction {
public interface GetMaskedValueFunction {

/**
* Masks the given content if log masking is enabled.
* Masks the given value if log masking is enabled.
*
* @param content The content to be masked.
* @return The masked content.
* @param value The value to be masked.
* @return The masked value.
*/
String getMaskedContent(String content);
String getMaskedValue(String value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import org.wso2.carbon.identity.central.log.mgt.utils.LoggerUtils;

/**
* Implementation of {@link GetMaskedContentFunction}.
* Implementation of {@link GetMaskedValueFunction}.
*/
public class GetMaskedContentFunctionImpl implements GetMaskedContentFunction {
public class GetMaskedValueFunctionImpl implements GetMaskedValueFunction {

@Override
@HostAccess.Export
public String getMaskedContent(String content) {
public String getMaskedValue(String value) {

return LoggerUtils.isLogMaskingEnable ? LoggerUtils.getMaskedContent(content) : content;
return LoggerUtils.isLogMaskingEnable ? LoggerUtils.getMaskedContent(value) : value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import org.wso2.carbon.identity.application.authentication.framework.JsFunctionRegistry;
import org.wso2.carbon.identity.conditional.auth.functions.utils.FilterAuthenticatorsFunction;
import org.wso2.carbon.identity.conditional.auth.functions.utils.FilterAuthenticatorsFunctionImpl;
import org.wso2.carbon.identity.conditional.auth.functions.utils.GetMaskedContentFunction;
import org.wso2.carbon.identity.conditional.auth.functions.utils.GetMaskedContentFunctionImpl;
import org.wso2.carbon.identity.conditional.auth.functions.utils.GetMaskedValueFunction;
import org.wso2.carbon.identity.conditional.auth.functions.utils.GetMaskedValueFunctionImpl;
import org.wso2.carbon.identity.conditional.auth.functions.utils.ResolveMultiAttributeLoginIdentifierFunction;
import org.wso2.carbon.identity.conditional.auth.functions.utils.ResolveMultiAttributeLoginIdentifierFunctionImpl;

Expand All @@ -56,9 +56,9 @@ protected void activate(ComponentContext ctxt) {
jsFunctionRegistry.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER,
"resolveMultiAttributeLoginIdentifier", resolveMultiAttributeLoginIdentifierFunctionImpl);

GetMaskedContentFunction getMaskedContentFunctionImpl = new GetMaskedContentFunctionImpl();
jsFunctionRegistry.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "getMaskedContent",
getMaskedContentFunctionImpl);
GetMaskedValueFunction getMaskedValueFunctionImpl = new GetMaskedValueFunctionImpl();
jsFunctionRegistry.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "getMaskedValue",
getMaskedValueFunctionImpl);
}

@Deactivate
Expand All @@ -69,7 +69,7 @@ protected void deactivate(ComponentContext ctxt) {
jsFunctionRegistry.deRegister(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "filterAuthenticators");
jsFunctionRegistry.deRegister(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER,
"resolveMultiAttributeLoginIdentifier");
jsFunctionRegistry.deRegister(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "getMaskedContent");
jsFunctionRegistry.deRegister(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "getMaskedValue");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,31 @@
import javax.servlet.http.HttpServletResponse;

/**
* Test class for GetMaskedContentFunctionImpl.
* Test class for GetMaskedValueFunctionImplTest.
*/
@WithCarbonHome
@WithH2Database(files = "dbscripts/h2.sql")
@WithRealmService(injectToSingletons = {LoggerUtils.class, FrameworkServiceDataHolder.class})
public class GetMaskedContentFunctionImplTest extends JsSequenceHandlerAbstractTest {
public class GetMaskedValueFunctionImplTest extends JsSequenceHandlerAbstractTest {

@BeforeClass
@Parameters({"scriptEngine"})
public void setUp(String scriptEngine) throws Exception {

super.setUp(scriptEngine);
CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true;
sequenceHandlerRunner.registerJsFunction("getMaskedContent",
new GetMaskedContentFunctionImpl());
sequenceHandlerRunner.registerJsFunction("getMaskedValue",
new GetMaskedValueFunctionImpl());
}

@Test(dataProvider = "maskableContentProvider")
public void testGetMaskedContent(boolean isLogMaskingEnabled, String username, String expectedMaskedContent)
@Test(dataProvider = "maskableValueProvider")
public void testGetMaskedValue(boolean isLogMaskingEnabled, String username, String expectedMaskedValue)
throws JsTestException {

LoggerUtils.isLogMaskingEnable = isLogMaskingEnabled;
sequenceHandlerRunner.addSubjectAuthenticator("BasicMockAuthenticator", username, Collections.emptyMap());

ServiceProvider sp = sequenceHandlerRunner.loadServiceProviderFromResource("get-masked-content-sp.xml", this);
ServiceProvider sp = sequenceHandlerRunner.loadServiceProviderFromResource("get-masked-value-sp.xml", this);
AuthenticationContext context = sequenceHandlerRunner.createAuthenticationContext(sp);
SequenceConfig sequenceConfig = sequenceHandlerRunner.getSequenceConfig(context, sp);
context.setSequenceConfig(sequenceConfig);
Expand All @@ -76,11 +76,11 @@ public void testGetMaskedContent(boolean isLogMaskingEnabled, String username, S

sequenceHandlerRunner.handle(req, resp, context, "test_domain");

Assert.assertEquals(context.getSelectedAcr(), expectedMaskedContent);
Assert.assertEquals(context.getSelectedAcr(), expectedMaskedValue);
}

@DataProvider(name = "maskableContentProvider")
public Object[][] loginIdentifierProvider() {
@DataProvider(name = "maskableValueProvider")
public Object[][] maskableValueProvider() {

return new Object[][]{
{true, "johndoe", "j*****e"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var onLoginRequest = function(context) {
executeStep(1, {
onSuccess: function(context) {
var username = context.currentKnownSubject.username;
var maskedUsername = getMaskedContent(username);
var maskedUsername = getMaskedValue(username);
Log.info("Masked username of the logged user: " + maskedUsername);
context.selectedAcr = maskedUsername;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
<parameter name="scriptEngine" value="nashorn"/>
<classes>
<class name="org.wso2.carbon.identity.conditional.auth.functions.utils.ResolveMultiAttributeLoginIdentifierFunctionImplTest"/>
<class name="org.wso2.carbon.identity.conditional.auth.functions.utils.GetMaskedContentFunctionImplTest"/>
<class name="org.wso2.carbon.identity.conditional.auth.functions.utils.GetMaskedValueFunctionImplTest"/>
</classes>
</test>
<test name="org.wso2.carbon.identity.conditional.auth.functions.utils.test.graaljs" parallel="false">
<parameter name="scriptEngine" value="graaljs"/>
<classes>
<class name="org.wso2.carbon.identity.conditional.auth.functions.utils.ResolveMultiAttributeLoginIdentifierFunctionImplTest"/>
<class name="org.wso2.carbon.identity.conditional.auth.functions.utils.GetMaskedContentFunctionImplTest"/>
<class name="org.wso2.carbon.identity.conditional.auth.functions.utils.GetMaskedValueFunctionImplTest"/>
</classes>
</test>
</suite>

0 comments on commit 6e7ae15

Please sign in to comment.