The JOID OpenID extensions package. This package contains code for OpenID extensions, and provides a convenient base class to derive extensions from.

To make use of the extensions classes, use the getExtensions and addExtension methods in the AuthenticationRequest and AuthenticationResponse classes. Validate that the extension exists using the Extension.isValid method.

Example of parsing incoming requests or responses:

Request req = RequestFactory.parse(s);
if (req instanceof AuthenticationRequest) {
    AuthenticationRequest ar = (AuthenticationRequest) req;
    PapeRequest pr = new PapeRequest(ar.getExtensions());
    if (pr.isValid()) {
        ...
    }
}
and
Response resp = ResponseFactory.parse(s);
if (resp instanceof AuthenticationResponse) {
    AuthenticationResponse ar = (AuthenticationResponse) resp;
    PapeResponse pr = new PapeResponse(ar.getExtensions());
    if (pr.isValid()) {
        ...
    }
}

Example of submitting extensions to outgoing requests or responses:

AuthenticationRequest ar = AuthenticationRequest.create(identity,
                                                        returnTo,
                                                        trustRoot,
                                                        assocHandle);
PapeRequest pr = new PapeRequest();
pr.setMaxAuthAge(3600);
ar.addExtension(pr);
and
Response resp = request.processUsing(serverInfo);
if (resp instanceof AuthenticationResponse) {
    AuthenticationResponse ar = (AuthenticationResponse)resp;
    PapeResponse pr = new PapeResponse();
    pr.setAuthAge(3600);
    pr.setAuthPolicies(new String[] 
        { "http://schemas.openid.net/pape/policies/2007/06/phishing-resistant",
          "http://schemas.openid.net/pape/policies/2007/06/multi-factor",
          "http://schemas.openid.net/pape/policies/2007/06/multi-factor-physical" });
    pr.setNistAuthLevel(4);
    ar.addExtension(pr);
}