Skip to main content
1-Visitor
October 9, 2018
Solved

Custom Authenticator is not redirecting correctly.

  • October 9, 2018
  • 1 reply
  • 1896 views

Hi,

 

I have created custom authenticator to redirect user on organization page if session expires. But it doesn't redirect it. however if I do page refresh then it is redirecting to desire page.  

it seems page refresh issue. but i have no clue to resolve this.

 

please find below code for reference. Any help would be appreciated.

 

Thanks,

Lalit

 

import java.io.IOException;

import com.thingworx.security.authentication.AuthenticatorException;
import com.thingworx.security.authentication.CustomAuthenticator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class LoginAuthenticator extends CustomAuthenticator {

	private String user;
	private String requestUrl;
	private String password;
	private boolean isFormLogin;
	private boolean isRedirect;
	public LoginAuthenticator() {
 user = null;
 requestUrl = null;
 password = null;
 isFormLogin = true;
 isRedirect = false;
	}

 public boolean matchesAuthRequest(HttpServletRequest httpRequest)
		 throws AuthenticatorException
 {
 requestUrl = httpRequest.getRequestURL().toString();
 if((!requestUrl.contains("action-login")) & (!requestUrl.contains("FormLogin")))
 {
 isFormLogin = false;
 isRedirect = true;
 setRequiresChallenge(true);
 } else
 if(requestUrl.contains("action-login"))
 {
 user = httpRequest.getParameter("thingworx-form-userid");
 password = httpRequest.getParameter("thingworx-form-password");
 }
 return true;
 }

 

 public void authenticate(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
		 throws AuthenticatorException
 {
 setCredentials(user, password);
 }

 

 public void issueAuthenticationChallenge(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
		 throws AuthenticatorException
 {
 if(isRedirect)
 {
 String urlString = "/Thingworx/FormLogin/Industrial_Solutions";//replace with your own organization
 try
 {
 httpResponse.sendRedirect(urlString);
 return;
 }
 catch(IOException e)
 {
 e.printStackTrace();

 }
 }
 }

}
Best answer by MarekP.Nowaczyk

Lalit,

 

To answer your question: there is nothing in the page to request re-authentication unless the page is refreshed. You may have to add some element/widget to ThingWorx page header to refresh it once certain condition occurs.

 

Hope this helps,

Marek

 

 

1 reply

15-Moonstone
October 10, 2018

Lalit,

 

To answer your question: there is nothing in the page to request re-authentication unless the page is refreshed. You may have to add some element/widget to ThingWorx page header to refresh it once certain condition occurs.

 

Hope this helps,

Marek

 

 

Support
October 15, 2018

Hi @lprajapati.

 

If you are satisfied with the response provided by Marek, please mark his reply as the Accepted Solution for the benefit of others who may have the same question.

 

Regards.

 

--Sharon