AuthnApiSupport
provides several methods for writing API responses.
The following example shows how the TemplateRenderAdapter
writes the
response for the USER_ATTRIBUTES_REQUIRED
state.
private void renderApiResponse(HttpServletRequest req, HttpServletResponse resp, Map<String, Object> inParameters) throws AuthnAdapterException
{
UserAttributesRequired model = new UserAttributesRequired();
model.setAttributeNames(new ArrayList<>(extendedAttr));
AuthnState<UserAttributesRequired> authnState = apiSupport.makeAuthnState(req, StateSpec.USER_ATTRIBUTES_REQUIRED, model);
try
{
apiSupport.writeAuthnStateResponse(req, resp, authnState);
}
catch (IOException e)
{
throw new AuthnAdapterException(e);
}
}
The makeAuthnState()
method takes an AuthnStateSpec
and
an instance of the model for that state and builds an AuthnState
object. The AuthnState
object can then be further modified. For
example, you could remove an action that is not currently applicable using the
removeAction()
method. Then you write the
AuthnState
object to the response using the
writeAuthnStateResponse()
method.