Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to implement a SDN-like Login Form? What API do i have to use?

Dear development experts:)

currently i am trying to develop my own form, with which users can login. (like the form on the starting page of the sdn on the right hand side)

I browsed through the portal API but haven't found the right one until now. I thought i would have to utilize some kind of method where i would pass the user-id and the password as parameters. The only API i have found so far, that looks like i could do this job for me, is this [one|http://help.sap.com/javadocs/NW04S/current/se/com/sap/security/api/logon/ILogonAuthentication.html].

So can you help me on this one? Am i searching completely at the wrong place?

Best Regards,

Marcus

Former Member
Former Member replied

Hi Marcus,

You would need the following code to execute on click of your button to log the user into the portal :

public boolean validateUser(IPortalComponentRequest request, IPortalComponentResponse response, String strUserName, String strPassword)

{

IUserAccount objUserAccount = null;

boolean blnExecuteState = true;

String strNewUserID = "";

objBean = this.checkBeanInstance(objContext);

try

{

int intSize = 0;

objUserAccount = null;

if(strUserName!=null)

{

objUserAccount = UMFactory.getUserAccountFactory().getUserAccountByLogonId(strUserName);

}

else

{

blnExecuteState = false;

}

if(objUserAccount!=null)

{

if(objUserAccount.isUserAccountLocked())

{

blnExecuteState = false;

}

else

{

if(!(objUserAccount.checkPassword(strPassword)))

{

blnExecuteState = false;

}

}

}

else

{

blnExecuteState = false;

}

}

catch(Exception e)

{

blnExecuteState = false;

}

finally

{

objUserAccount = null;

strNewUserID = null;

}

return blnExecuteState;

}

public boolean logonUser(IPortalComponentRequest request, IPortalComponentResponse response, String strUserName, String strPassword)

{

IUser objValidUser = null;

HttpServletRequest objServletRequest = null;

HttpServletResponse objServletResponse = null;

Set objPrincipals = null;

Iterator objIterator = null;

boolean blnLoggedIn = false;

objBean = this.checkBeanInstance(objContext);

try

{

objServletRequest = request.getServletRequest();

objServletResponse = request.getServletResponse(false);

objServletRequest.setAttribute(ILoginConstants.LOGON_UID_ALIAS,strUserName);

objServletRequest.setAttribute(ILoginConstants.LOGON_PWD_ALIAS,strPassword);

objPrincipals = UMFactory.getLogonAuthenticator().logon(objServletRequest,objServletResponse,AUTH_SCHEME).getPrincipals();

objIterator = objPrincipals.iterator();

while (objIterator.hasNext())

{

Object obj = objIterator.next();

if (obj instanceof IUser)

{

objValidUser = (IUser) obj;

}

}

blnLoggedIn = UMFactory.getLogonAuthenticator().isAuthenticated(objValidUser);

}

catch(Exception e)

{

}

finally

{

objValidUser = null;

objServletRequest = null;

objServletResponse = null;

objPrincipals = null;

objIterator = null;

}

return blnLoggedIn;

}

IPortalComponentURI objComponentURI.setContextName("com.sap.portal.navigation.portallauncher.default");

String strPostUrl = objComponentURI.toString();

objServletResponse.sendRedirect(strPostUrl);

You are looking in the exact right place !!!!

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question