cancel
Showing results for 
Search instead for 
Did you mean: 

Force logon

Former Member
0 Kudos

Hi all,

I'm updating some old code today. The requirement is simply that if the user is not logged on to the portal we automagically log them on anonymously.

The force logon code that we're using is

UMFactory.getLogonAuthenticator().logon(req,res,"uidpwdlogon")

req and res are javax.servlet.http.req/res of course.

As such, it would appear that I'll need the HttpServletRequest and HttpServletResponse to call the method... so now you see the problem... it would appear that all previous routes to these objects are being blocked...

Originally this code was used (I didn't write it )

HttpServletRequest req = ((IWebContextAdapter) WDWebContextAdapter.getWebContextAdapter()).getHttpServletRequest();
HttpServletResponse res = ((IWebContextAdapter) WDWebContextAdapter.getWebContextAdapter()).getHttpServletResponse();
req.setAttribute(ILoginConstants.LOGON_UID_ALIAS, Const.ANONYMOUS_USER);
req.setAttribute(ILoginConstants.LOGON_PWD_ALIAS, Const.ANONYMOUS_PASSWORD);

OK, don't use IWebContextAdapter... noted.

So this code was written

HttpServletRequest req= (HttpServletRequest)WDProtocolAdapter.getProtocolAdapter().getRequestObject();
HttpServletResponse res= (HttpServletResponse)WDProtocolAdapter.getProtocolAdapter().getResponseObject();
WDScopeUtil.put(WDScopeType.CLIENTSESSION_SCOPE, ILoginConstants.LOGON_UID_ALIAS, Const.ANONYMOUS_USER);
WDScopeUtil.put(WDScopeType.CLIENTSESSION_SCOPE, ILoginConstants.LOGON_PWD_ALIAS, Const.ANONYMOUS_PASSWORD);

But now the cast from IWDRequest to HttpServletRequest throws a class cast exception... I'm told that it was previously possible to do it though.

So the question is; if all routes to HttpServletRequest and Response are blocked how can I call UMFactory.getLogonAuthenticator().logon(...)? Or put another way... what can I call to log the user on?

Thanks in advance,

Patrick.

Accepted Solutions (1)

Accepted Solutions (1)

former_member182374
Active Contributor
0 Kudos

Hi Patrick,

You can write a simple servlet which authenticate the user and then redirects to the WD application:

public class TestServlet extends HttpServlet{
	protected void doGet(HttpServletRequest request, HttpServletResponse response) {
		PrintWriter out = null;
		
		String username = "omric";
		String password = "WDisTheBestUIframeworkEver)-:";
		try {
	            out = response.getWriter();
                    request.setAttribute("j_user", username);
		    request.setAttribute("j_password", password);
		    UMFactory.getLogonAuthenticator().logon(request,response,"uidpwdlogon");
 
		    
		    response.sendRedirect("/webdynpro/dispatcher/<namespace>/<project>/<application>");
		} catch (Exception ex) {
			out.write("UME Exception --> " + ex.getMessage());
		}
		
	}
}

Omri

Former Member
0 Kudos

Thanks Omri,

And we can just check in the code if the user is already authenticated and only force the anono log on if required...

Cheers,

Patrick.

Answers (1)

Answers (1)

Former Member
0 Kudos

Seriously though

Patrick.

younghwan_kim
Active Participant
0 Kudos

I'm not sure this might help.

WDClientUser.forceLoggedInClientUser();

This method checks whether the user is logged on, if not, show the logon page.

Check the api.

https://help.sap.com/javadocs/NW04S/current/wd/index.html

Former Member
0 Kudos

Hi,

Actually (if the user is not already logged on) we don't want the user to see the log on page... that's the behaviour we're trying to get rid of.

What happens is that we check to see if the user is logged on already... if so... great... if not (it'll mean that they're an external user and have no portal user)... we want to log them on to the portal anonymously; just so that they can use certain services.

Thanks for your time,

Patrick.