Skip to content

Commit

Permalink
Improve authentication mgt
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Jan 23, 2025
1 parent 71a366f commit ba0015d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>action-mgt</artifactId>
<version>7.7.111-SNAPSHOT</version>
<version>7.7.95-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -173,8 +173,8 @@
<limit implementation="org.jacoco.report.check.Limit">
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<!-- temp decreasing the coverage, to get the codecov results -->
<minimum>0.77</minimum>
<!-- temp decreasing the coverage -->
<minimum>0.78</minimum>
</limit>
<limit implementation="org.jacoco.report.check.Limit">
<counter>COMPLEXITY</counter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.wso2.carbon.identity.action.execution.impl;

import org.wso2.carbon.identity.action.execution.exception.ActionExecutionRuntimeException;
import org.wso2.carbon.identity.action.execution.model.ActionType;
import org.wso2.carbon.identity.action.execution.model.Context;

Expand Down Expand Up @@ -51,28 +52,36 @@ public static Class<? extends Context> getInvocationSuccessResponseContextClass(
/**
* Register the Context class for the given action type.
*
* @param invocationSuccessResponse Context class.
* @throws NoSuchFieldException If ACTION_TYPE is not defined in the extended Context class.
* @throws IllegalAccessException If any error occurred while accessing the field in the extended Context class.
* @param extendedClass Context class.
* @throws ActionExecutionRuntimeException If any error occurs when registering extended context class.
*/
public static void registerInvocationSuccessResponseContextClass(
Class<? extends Context> invocationSuccessResponse) throws NoSuchFieldException, IllegalAccessException {
Class<? extends Context> extendedClass) throws ActionExecutionRuntimeException {

ActionType type = (ActionType) invocationSuccessResponse.getDeclaredField("ACTION_TYPE").get(null);
contextClassMap.put(type, invocationSuccessResponse);
try {
ActionType type = (ActionType) extendedClass.getDeclaredField("ACTION_TYPE").get(null);
contextClassMap.put(type, extendedClass);
} catch (IllegalAccessException | NoSuchFieldException e) {
throw new ActionExecutionRuntimeException(String.format("An error occurred while registering extended " +
"context class: %s", extendedClass), e);
}
}

/**
* Unregister the Context class for the given action type.
*
* @param invocationSuccessResponse Context class.
* @throws NoSuchFieldException If ACTION_TYPE is not defined in the extended Context class.
* @throws IllegalAccessException If any error occurred while accessing the field in the extended Context class.
* @param extendedClass Context class.
* @throws ActionExecutionRuntimeException If any error occurs when unregistering extended context class.
*/
public static void unregisterInvocationSuccessResponse(Class<? extends Context> invocationSuccessResponse)
throws NoSuchFieldException, IllegalAccessException {
public static void unregisterInvocationSuccessResponse(Class<? extends Context> extendedClass)
throws ActionExecutionRuntimeException {

ActionType type = (ActionType) invocationSuccessResponse.getDeclaredField("ACTION_TYPE").get(null);
contextClassMap.remove(type);
try {
ActionType type = (ActionType) extendedClass.getDeclaredField("ACTION_TYPE").get(null);
contextClassMap.remove(type);
} catch (IllegalAccessException | NoSuchFieldException e) {
throw new ActionExecutionRuntimeException(String.format("An error occurred while registering extended " +
"context class: %s", extendedClass), e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,25 +164,23 @@ protected void unsetActionExecutionResponseProcessor(
policy = ReferencePolicy.DYNAMIC,
unbind = "unsetInvocationSuccessResponseContextClass"
)
protected void setInvocationSuccessResponseContextClass(Class<? extends Context> invocationSuccessResponse)
throws NoSuchFieldException, IllegalAccessException {
protected void setInvocationSuccessResponseContextClass(Class<? extends Context> extendedContextClass) {


if (LOG.isDebugEnabled()) {
LOG.debug("Registering extended Context class: " +
invocationSuccessResponse.getName() + " in the ActionExecutionServiceComponent.");
extendedContextClass.getName() + " in the ActionExecutionServiceComponent.");
}
InvocationSuccessResponseContextFactory.registerInvocationSuccessResponseContextClass(
invocationSuccessResponse);
extendedContextClass);
}

protected void unsetInvocationSuccessResponseContextClass(Class<? extends Context> invocationSuccessResponse)
throws NoSuchFieldException, IllegalAccessException {
protected void unsetInvocationSuccessResponseContextClass(Class<? extends Context> extendedContextClass) {

if (LOG.isDebugEnabled()) {
LOG.debug("Unregistering extended Context class: " +
invocationSuccessResponse.getName() + " in the ActionExecutionServiceComponent.");
extendedContextClass.getName() + " in the ActionExecutionServiceComponent.");
}
InvocationSuccessResponseContextFactory.unregisterInvocationSuccessResponse(invocationSuccessResponse);
InvocationSuccessResponseContextFactory.unregisterInvocationSuccessResponse(extendedContextClass);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<classes>
<class name="org.wso2.carbon.identity.action.execution.impl.ActionExecutionRequestBuilderFactoryTest"/>
<class name="org.wso2.carbon.identity.action.execution.impl.ActionExecutionResponseProcessorFactoryTest"/>
<class name="org.wso2.carbon.identity.action.execution.impl.InvocationSuccessResponseContextFactory"/>
<class name="org.wso2.carbon.identity.action.execution.impl.InvocationSuccessResponseContextFactoryTest"/>
</classes>
</test>
<test name="action-execution-service-test">
Expand Down

0 comments on commit ba0015d

Please sign in to comment.