You don’t need to change the rule. Just pass the identityName into the workflow context arguments from the task/workflow side. For example, in the TaskDefinition XML add it under <Attributes> (e.g. <entry key="identityName" value="test.user"/>). That way, when the task runs, the workflow context will already have identityName and the rule can read it with wfcontext.getArguments().get("identityName").
You don’t need to do anything special—wfcontext is automatically created when the workflow is triggered. Just make sure to pass your arguments via the workflow’s input mapping or in the TaskDefinition <Attributes>. Then wfcontext.getArguments() will contain the values, like "identityName", for your rule to read.
There is no workflow. Normally, the rule is called from a workflow, but now I’m calling it from a task. Do i need to create a workflowcontext? Inside the rule, it says wfcontext is of type void.