So I have managed to solve this problem and this is how I did it.
First of all, I already had a custom flow, so it turned out that all I needed to do is to add another step to it. So in my flow definition file (myflow-flow.xml) I added the following:
<action-state id="ReadParametersFromAuthnrequest">
<evaluate expression="AuthnRequestParametersReader" />
<evaluate expression="'proceed'" />
<transition on="proceed" to="YourNextStep" />
</action-state>
and then I added the following bean definition to the corresponding bean definitions file
<bean id="AuthnRequestParametersReader"
class="com.example.AuthnRequestParametersReader"
scope="prototype" />
Secondly I created com.example.AuthnRequestParametersReader bean. This bean extends AbstractProfileAction bean. The contents of this bean is very similar to InitializeAuthenticationContext
http://svn.shibboleth.net/view/java-identity-provider/tags/3.1.2/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/profile/impl/InitializeAuthenticationContext.java?view=markup. I basically just copy and pasted logic for initializing of authnRequest property, and then I implemented doExecute to read the Extensions element from authnRequest and then the properties I was interested in.
final Extensions extensions = authnRequest.getExtensions();
...
List<XMLObject> xmlObjectList = extensions.getUnknownXMLObjects();
...
for (XMLObject xmlObject : xmlObjectList) {
Element element = xmlObject.getDOM();
String localName = element.getLocalName();
String textContent = element.getTextContent();
...
}
There was just one catch. The extensions part of the authn request xml needs to be like the following:
<saml2p:Extensions>
...
</saml2p:Extensions>
The prefix of the QName should be "saml2p", not "md" as in my original example. If it is "md" then the saml library will fail to read this element (maybe this could be fixed from settings, but I did not find the way to do it).
Then I rebuilt the *.war file, redeployed and it was able to read the params.