Wicket에서 LDAP 로그인 페이지를 사용하려고합니다.Wicket 용 LDAP 인증
LDAP 서버가 주어진 사용자 자격 증명을 확인한 경우 true/false 문으로 응답하는 작동 LDAP 클래스가 있습니다.
package Tools;
import javax.naming.*;
import javax.naming.directory.*;
import java.io.FileNotFoundException;
import java.util.Hashtable;
public class LDAP {
boolean LDAP_ENABLED;
String LDAPBaseDirectory;
String LDAP_SERVER_ADDRESS;
String LDAP_SERVER_PORT;
String LDAP_USER_DOMAIN;
String LDAP_DN;
String LDAP_StandardUserName;
String LDAP_StandardUserPassword;
public LDAP(){ //depends on Config Class
//Import settings from Config
try{
Config config = new Config();
if(config.getProperty_seLDAP_ENABLED()){
this.LDAP_ENABLED = true;
}else{
this.LDAP_ENABLED = false;
}
if(this.LDAP_ENABLED){
this.LDAPBaseDirectory = config.getProperty_seLDAP_BASE_DIRECTORY();
this.LDAP_SERVER_ADDRESS = config.getProperty_seLDAP_SERVER_ADDRESS();
this.LDAP_SERVER_PORT = config.getProperty_seLDAP_SERVER_PORT();
this.LDAP_USER_DOMAIN = config.getProperty_seLDAP_USER_DOMAIN();
this.LDAP_DN = config.getProperty_seLDAP_DN();
this.LDAP_StandardUserName = config.getProperty_seLDAP_StandardUserName();
this.LDAP_StandardUserPassword = config.getProperty_seLDAP_StandardUserPassword();
}
} catch (FileNotFoundException e){
//todo
}
}
public boolean authentify(String userName, String userPassword){
System.out.println(userPassword);
//LDAP responses with "true" if password == null
if(userPassword.equals("")){
return false;
}
/**
* TODO
* Add availability check for LDAP Server
*
*/
try
{
System.out.println("Trying LDAP");
// Set up the environment for creating the initial context
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
String ldapURL = "ldap://" + this.LDAP_SERVER_ADDRESS + ":" +this.LDAP_SERVER_PORT;
System.out.println("URL: "+ ldapURL);
env.put(Context.PROVIDER_URL, ldapURL);
//
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, this.LDAP_DN +"\\"+ userName); //"domain\\user");
System.out.println("Principal: "+ this.LDAP_DN +"\\"+ userName); //DEBUG
env.put(Context.SECURITY_CREDENTIALS, userPassword);
System.out.println("Password: "+ userPassword); //DEBUG
// Create the initial context
DirContext ctx = new InitialDirContext(env);
boolean result = (ctx != null);
// if(ctx != null)
ctx.close();
System.out.println("Result: " + result);
// return result;
if(result){
return true;
}else{
return false;
}
}
catch (Exception e)
{
System.out.println(e.getStackTrace());
e.printStackTrace();
return false;
}
}
}
위의 클래스는 사용시 꽤 잘 작동합니다. 콘솔을 통해. 다음 단계는 개찰구로 매우 간단한 로그인 페이지를 작성했다 :
내 문제에 대한 지금package haw.Ausleihe;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.PasswordTextField;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.Model;
import org.hibernate.Session;
import Tools.LDAP;
import Database.HibernateHelper;
import Database.Entities.User;
public class Login extends WebPage {
private static final long serialVersionUID = 1L;
public Login(final PageParameters parameters) {
super(parameters);
final TextField<String> hawKennung = new TextField<String>("hawKennung",
Model.of(""));
hawKennung.setRequired(true);
hawKennung.add(new UserValidator());
final PasswordTextField passwort = new PasswordTextField("passwort", Model.of(""));
passwort.setRequired(true);
Form<?> login = new Form<Void> ("login")
{
@Override
protected void onSubmit() {
//HibernateHelper hibernate = new HibernateHelper();
final String usernameValue = hawKennung.getModelObject();
final String passwordValue = passwort.getModelObject();
//hibernate.addUser(usernameValue, passwordValue, "", "", "");
// User tmpUser = hibernate.getUser("abb123");
// System.out.println("Database Entry: " + tmpUser.getKennung() + " ; " + tmpUser.getPassword());
System.out.println(usernameValue);
System.out.println(passwordValue);
System.out.println("NOW TESTING LDAP");
LDAP ldap = new LDAP();
if(ldap.authentify(usernameValue, passwordValue)){
System.out.println("Success");
}else{
System.out.println("Fail");
}
setResponsePage(HomePage.class);
}
};
add(login);
login.add(hawKennung);
login.add(passwort);
}
}
이 ... 그래서이 사용자 이름/암호를 입력 ... 아주 간단되어야 버튼 및 제출을 클릭 ... litterally 아무 반응이 없습니다. No System.out.println이 표시되고 코드가 멈춰있는 것처럼 보입니다 (LDAP 클래스의 디버그 정보도 표시되지 않는 것 같습니다)
내가 뭘 잘못했는지 생각하세요?
인사말, Dwarfex
제공된 답변이 정확합니다. 'wicket-auth-roles'를 사용하는 것이 좋습니다. 무료로 로그인 페이지를 얻고 응용 프로그램 내에서 많은 인증 로직을 처리하는'AuthenticatedWebSession'을 얻을 수 있습니다. – RobAu