cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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 !!!!

Former Member
0 Kudos

Hi Tahzeeb,

thx alot for your code snippet. My application isn't working already but that's because of other problems.

Best Regards,

Marcus

Former Member
0 Kudos

Hi Tahzeeb,

i got one more question. The application ist working quite fine at the moment. The only thing i am missing now is that when the user has entered his id and password and is pressing the Enter Button, then the Login Button should be pressed. At the moment he has enter id and password and has to click the button via mouse. I guess this question is pretty easy, but i totally new to web development:)

Former Member
0 Kudos

Marcus,

You would need to lookup some HTML help if you have developed an HTML page or search on help.sap.com if you have developed your form using HTMLB. I too do not have much of an idea as to how this will be achieved.

Tahzeeb.

Answers (0)