-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26eb2d9
commit 03667aa
Showing
4 changed files
with
147 additions
and
12 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...g/wso2/carbon/identity/action/execution/impl/InvocationSuccessResponseContextFactory.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,51 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). | ||
* | ||
* WSO2 LLC. 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 org.wso2.carbon.identity.action.execution.impl; | ||
|
||
import org.wso2.carbon.identity.action.execution.model.Context; | ||
import org.wso2.carbon.identity.action.execution.model.ActionType; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class InvocationSuccessResponseContextFactory { | ||
|
||
private static final Map<ActionType, Class<? extends Context>> contextClassMap = new HashMap<>(); | ||
|
||
public static Class<? extends Context> getInvocationSuccessResponseContextClass(ActionType actionType) { | ||
|
||
Class<? extends Context> responseClass = contextClassMap.get(actionType); | ||
if (responseClass != null) { | ||
return responseClass; | ||
} | ||
return Context.class; | ||
} | ||
|
||
public static void registerInvocationSuccessResponseContextClass( | ||
Class<? extends Context> invocationSuccessResponse) throws NoSuchFieldException, IllegalAccessException { | ||
|
||
ActionType type = (ActionType) invocationSuccessResponse.getDeclaredField("ACTION_TYPE").get(null); | ||
contextClassMap.put(type, invocationSuccessResponse); | ||
} | ||
|
||
public static void unregisterInvocationSuccessResponse(Class<? extends Context> invocationSuccessResponse) { | ||
|
||
contextClassMap.remove(ActionType.AUTHENTICATION); | ||
} | ||
} |
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
60 changes: 60 additions & 0 deletions
60
...tion.execution/src/main/java/org/wso2/carbon/identity/action/execution/model/Context.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,60 @@ | ||
/* | ||
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). | ||
* | ||
* WSO2 LLC. 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 org.wso2.carbon.identity.action.execution.model; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.wso2.carbon.identity.action.execution.impl.InvocationSuccessResponseContextFactory.getInvocationSuccessResponseContextClass; | ||
|
||
public interface Context { | ||
|
||
public static final ActionType ACTION_TYPE = null; | ||
|
||
public static ActionType getActionType() { | ||
return ACTION_TYPE; | ||
} | ||
|
||
public static class DefaultContext implements Context { | ||
} | ||
|
||
public static class ContextDeserializer extends StdDeserializer<Context> { | ||
|
||
private final ActionType actionType; | ||
|
||
public ContextDeserializer(ActionType actionType) { | ||
|
||
super(Context.class); | ||
this.actionType = actionType; | ||
} | ||
|
||
@Override | ||
public Context deserialize(JsonParser p, com.fasterxml.jackson.databind.DeserializationContext ctxt) | ||
throws IOException { | ||
|
||
JsonNode node = p.getCodec().readTree(p); | ||
ObjectMapper mapper = (ObjectMapper) p.getCodec(); | ||
return mapper.treeToValue(node, getInvocationSuccessResponseContextClass(actionType)); | ||
} | ||
} | ||
} |
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