on 07-29-2011 12:52 PM
Hi Experst,
I want to create a new Loginpage with userID and password, but now I'm stuck.
Maybe you can help me.
This is my JSP:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<body bgcolor="ghostwhite">
<!-- Text -->
<br><br>
Geben Sie Ihre Benutzernummer und Passwort ein!
<br><br><br>
<form action="/irj/servlet/prt/portal/prtroot/myPortalProject.myPortalComp" method="post">
<table id="login" border="0" width="35%" cellpadding="4" cellspacing="0" >
<!-- Eingabefelder in Tabellenform -->
<colgroup width="100" span="1"></colgroup>
<tr bgcolor="lightsteelblue">
<td>
Anmeldung
</td>
<td width="100">
</td>
</tr>
<tr>
<td bgcolor="lavender">
Benutzernummer:
</td>
<td bgcolor="lavender">
<input type="text" name="j_user" >
</td>
<td width="440">
</td>
</tr>
<tr>
<td bgcolor="lavender">
Passwort:
</td>
<td bgcolor="lavender">
<input type="password" name="j_password" >
</td>
<td width="440">
</td>
</tr>
</table>
<br>
<!-- Button -->
<input type="submit" value=" Login ">
</form>
<%//if(request.getParameter("message"))
//=request.getParameter("message")
System.out.println("messagge");
%>
</body>
</html>
Javaclass:
import com.sap.security.api.IUserAccount;
import com.sap.security.api.UMException;
import com.sap.security.api.UMFactory;
import com.sapportals.portal.prt.component.*;
import com.sap.security.api.logon.*;
import javax.security.auth.*;
import java.io.IOException;
import java.net.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class myPortalComp extends AbstractPortalComponent
{
public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
{
//response.write("HelloWorld");
String passW = request.getParameter("password");
String userN = request.getParameter("userName");
String Fehler = "Kein Fehler";
int ValidPwd;
URL seite = null;
HttpServletRequest req = request.getServletRequest();
HttpServletResponse res = request.getServletResponse(true);
try {
seite =
new URL("/irj/servlet/prt/portal/prtroot/com.sap.portal.navigation.portallauncher.default");
} catch (MalformedURLException e) {
e.printStackTrace();
}
try{
IUserAccount userA = UMFactory.getUserAccountFactory().getUserAccountByLogonId(userN);
ValidPwd = userA.checkPasswordExtended(passW);
if(ValidPwd == ILoginConstants.CHECKPWD_OK){
//Erster User wird vom Portal ausgeloggt
ILogonAuthentication su = UMFactory.getLogonAuthenticator();
su.logout(request.getServletRequest(), request.getServletResponse(false));
//In das Portal einloggen
req.setAttribute(ILoginConstants.LOGON_UID_ALIAS,userN);
req.setAttribute(ILoginConstants.LOGON_PRINCIPAL_ID_ALIAS,passW);
try{
//Funktion für die Anmeldung
Subject sub = UMFactory.getLogonAuthenticator().logon(req,res,"uidpwdlogon");
//response.sendRedirect("/irj/servlet/prt/portal/prtroot/com.sap.portal.navigation.portallauncher.default");
res.sendRedirect(seite.toString());
}
catch(Exception ex){
//Login Fehler
ex.getStackTrace();
}
}//END_if
else{
if(ValidPwd == ILoginConstants.CHECKPWD_PWDEXPIRED){
//throwNewLoginException("Passwort ist abgelaufen");
Fehler = "Passwort ist abgelaufen!";
}
else if(ValidPwd == ILoginConstants.CHECKPWD_PWDLOCKED){
//throwNewLoginException("Account ist gelockt");
Fehler = "Account ist gelockt!";
}
else if(ValidPwd == ILoginConstants.CHECKPWD_WRONGPWD){
//throwNewLoginException("Das eingegebene Passwort ist falsch");
Fehler = "Das eingegebene Passwort ist falsch!";
}
else if(ValidPwd == ILoginConstants.CHECKPWD_NOPWD){
//throwNewLoginException("Es wurde kein Passwort eingegeben");
Fehler = "Es wurde kein Passwort eingegeben!";
}
try {
res.sendRedirect("/irj/servlet/prt/portal/prtroot/myPortalProject.jsp/test.jsp?message=" + Fehler);
} catch (IOException e2) {
e2.printStackTrace();
}
}//END_else
}
catch (UMException e1) {
e1.printStackTrace();
}
}//END_doContent
}//END_myPortalComp
it will be very helpfull, if anybody can help me.
Thanx Cilvaring
Edited by: Cilvaring on Jul 29, 2011 1:53 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.