Jump to content
Changes to the Jaspersoft community edition download ×
  • Authentication failure raised when executing a report via visualize.js



    A customer has reported that when they use TIBCO JasperReports® Server v6.3.0 to run reports, it occasionally “Failed to authenticate” and error code is "authentication.error".

    Their code is here: 

    function execVisualize(config) {
       if (window.visualize) {
          if (config && config.auth) {
             log('Detecting the local time zone ...');
             var timezone = jstz.determine().name();
             if (timezone) {
                config.auth.timezone = timezone;
                log('Set the timezone as [' + config.auth.timezone + '] to JasperServer');
             else {
                log('Fail to detect the local timezone, skip setting');
          window.visualize(authSuccess, authError);

    The first time it is run everything is ok, but occasionally, on subsequent runs, it returns the error, "authentication.error".

    The xmlHttpRequest message is "SyntaxError: Unexpected token < in JSON at position 0(…)". 


    The customer is using the token as the authentication method to execute the visualize.js for the report execution. However, this method of authentication has the cache/session cookie embedded and will raise an authentication exception if you try to re-authenticate within the same session. This is why the first time they ran the report with the authentication, which is successful, while the next run will occasionally raise authentication exception. 

    There are some solutions that implements some special programming logic to force clean up of the existing cookie and terminate the session before trying to authenticate again.

    Some of our customers have also tried to implement logic to check if the current session has already authenticated or not. If already authenticated, it would not send the authentication request.

    However, the customer has found one minor problem with the visualize.js function,  "var visualize = function (param, param2, param3, param4)" . In this function , they found that every time they call this , they have an authenticate. 

    Jaspersoft code is here: 


    var auth    = visualizeData.auths.find( properties.server, properties.auth ),
        factory = visualizeData.facts[ properties.server ];
    if (!auth) {
        auth = new Authentication(_.extend({url: properties.server}, properties.auth));
    if (!factory) {
        factory = new BiComponentFactory({server: properties.server});
        visualizeData.facts[properties.server] = factory;
    auth._result || (auth._result = auth.run());
    auth._result .fail(errback) .always(function(result) {
       if (auth._result.state() === "resolved") {
          var v = createV(factory, auth);
          callback && callback(v);
          always && always(null, v);
       else {
          always && always(result);

    Finally, they found a solution .

    They add one token-timeout configuration to jboss which is "analytics.js.timeout".And the value is "3600".So this issue has gone. Hope this will help for others.

    User Feedback

    Recommended Comments

    There are no comments to display.

    This is now closed for further comments

  • Create New...