Hello,

I am having difficulties understand why the followinf piece of code gives me
the error "Parameter value was null or contained only whitespace". If I
remove <t:actionlink> from the <t:if> or replace it with for example
<t:pagelink>, then the error does not appear. If I move <t:actionlink>
outside <t:if> it works also, but I need to have <t:actionlink> in <t:if>
obviously.

Please advise.

Index.tml
===============================================
<html t:type="layout" title="OpenID Relaying Party"
      t:sidebarTitle="OpenID response"
      xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";
      xmlns:p="tapestry:parameter">

    <p>${message:greeting}</p>

    <t:if test="user">
        Welcome, ${user.firstName} | <t:actionlink
t:id="logout">logout</t:actionlink>
        <p:else>
            <t:form>
                <t:errors />
                <t:label for="openid"/>:
                <t:textfield t:id="openid" value="openid" size="30"/>
                <t:submit t:id="login" value="Login"/>
            </t:form>
       </p:else>
    </t:if>

    <p:sidebar>
        <p>${message}</p>
    </p:sidebar>

</html>

Index.java
=================================================
public class Index {

    @Inject
    private Logger logger;

    @Inject
    private Request request;

    @Property
    @Persist(PersistenceConstants.FLASH)
    private String openid;

    @Inject
    private Consumer consumer;

    @SessionState
    private Visit visit;

    @SessionState(create = false)
    @Property
    private User user;
    private boolean userExists;

    private String message;

    @Log
    void onValidateFromOpenid(String openidurl) throws ValidationException {
        try {
            URL url = new URL(openidurl);
        } catch (MalformedURLException e) {
            throw new ValidationException("Nepravilen URL!");
        }
    }

    @Log
    URL onSuccess() throws DiscoveryException, MessageException,
ConsumerException, MalformedURLException  {
        ConsumerManager manager = consumer.getManager();

        // perform discovery on the user-supplied identifier
        List discoveries = manager.discover(openid);

        // attempt to associate with the OpenID provider
        // and retrieve one service endpoint for authentication
        DiscoveryInformation discovered = manager.associate(discoveries);

        // store the discovery information in the user's session for later
use
        // leave out for stateless operation / if there is no session
        visit.setDiscoveryInformation(discovered);

        // obtain a AuthRequest message to be sent to the OpenID provider
        AuthRequest authReq = manager.authenticate(discovered, "
http://localhost:8080/rp/verify";);

        // Redirect the User to Their OpenID Provider
        return new URL(authReq.getDestinationUrl(true));
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getMessage() {
        return this.message;
    }

    @Log
    void onActionFromLogout() {
        Session s = request.getSession(false);
        if (s != null) {
            s.invalidate();
        }
    }

}


I get to this page from Verify page which is called by some openid server (
myopenid.com for example)

Verify.java
==============================================
public class Verify {

    @Inject
    private Logger logger;

    @Inject
    private Consumer consumer;

    @Inject
    private RequestGlobals requestGlobals;

    @SessionState
    private Visit visit;

    @SessionState(create = false)
    private User user;
    private boolean userExists;

    @InjectPage
    private Index indexPage;

    @Log
    Object setupRender() throws MessageException, DiscoveryException,
AssociationException {
        // extract the parameters from the authentication response
        // (which comes in as a HTTP request from the OpenID provider)
        HttpServletRequest httpServletRequest =
requestGlobals.getHTTPServletRequest();
        ParameterList openidResp = new
ParameterList(httpServletRequest.getParameterMap());

        // retrieve the previously stored discovery information
        DiscoveryInformation discovered = visit.getDiscoveryInformation();

        // extract the receiving URL from the HTTP request
        StringBuffer receivingURL = httpServletRequest.getRequestURL();
        String queryString = httpServletRequest.getQueryString();
        if (queryString != null && queryString.length() > 0) {

receivingURL.append("?").append(httpServletRequest.getQueryString());
        }

        // verify the response
        ConsumerManager manager = consumer.getManager();
        VerificationResult verification =
manager.verify(receivingURL.toString(), openidResp, discovered);

        // examine the verification result and extract the verified
identifier
        Identifier verified = verification.getVerifiedId();

        if (verified != null) {
            // success, use the verified identifier to identify the user
            logger.info("Success");
            user = new User();
            user.setFirstName((String)
verification.getAuthResponse().getParameterMap().get("openid.identity"));
            indexPage.setMessage("Success");

        } else {
            // OpenID authentication failed
            logger.info("OpenID authentication failed");
            indexPage.setMessage("Failed");
        }
        return indexPage;
    }
}

Cheers,
Borut

Reply via email to