JAAS unter JBoss

Status
Nicht offen für weitere Antworten.

DreamArtist

Bekanntes Mitglied
Hallo,

ich versuchen mittels JAAS über ein HTML-Formular die Anmeldung zu vollziehen.
Das Formular wird mittels Struts validiert.
Die Überprüfung der Benutzerdaten soll über eine Klasse weitergeleitet werden.
Diese soll danach mit den Benutzerdaten mittels Hibernate die Abfrage durchführen.
Als ApplikationsServer wird JBoss verwendet.

Kann mir jemand bitte Starthilfe geben?

Konkrete Fragen wären:

Wie stellt man die Verbindung eines Formulars zu JAAS her?
Wie kann man diese Eingabe an eine Klasse weiterleiten?
Wie kann man danach JAAS über einen Erfolg informieren?
Welche Konfigurationsdateien benötige ich hier und wo?

Vielen Dank für eure Hilfe!
 
mit tomcat gehts über die Server.xml. Dort ein Realm eintragen (eigenes oder eins von Tomcat). In der web.xml dann login-config u.s.w schreiben
 
Hallo,

Was muss ich in der server.xml eintragen?
Was muss ich in die web.xml schreiben?

Neuer Stand ist das ich in der Klasse die den CallbackHandler implementiert nicht weiterkomme.

Klasse:

Code:
public class MyCallbackHandler implements CallbackHandler {

	public void handle(Callback callbacks[]) throws IOException,
			UnsupportedCallbackException {
		String name = "";
                String pwd ="";
		NameCallback nc = null;
		PasswordCallback pc = null;
		
		for (int i = 0; i < callbacks.length; i++) {
			System.out.println("Im Durchgang: " + i);
			System.out.println("Im Durchgang: " + callbacks[i]);
			if (callbacks[i] instanceof NameCallback) {
				System.out.println("------------------------------");
				System.out.println("im Handler-Name");
				System.out.println(callbacks[i].getClass());
				System.out.println(((NameCallback) callbacks[i]).getName());
				System.out.println("------------------------------");
				nc = (NameCallback) callbacks[i];
				name = nc.getName();				
			} 
			if (callbacks[i] instanceof PasswordCallback) {		
				System.out.println("------------------------------");
				System.out.println("im Handler-Password");
				System.out.println("------------------------------");
				pc =(PasswordCallback) callbacks[i];
				pwd = new String(pc.getPassword());
			}
			else {
				throw (new UnsupportedCallbackException(callbacks[i],
						"Callback handler not support"));
			}
		}		
	}

Die Ausgabe:

Code:
2005-09-13 16:04:56,921 INFO  [STDOUT] ------------------------------
2005-09-13 16:04:56,921 INFO  [STDOUT] Im Durchgang: 0
2005-09-13 16:04:56,921 INFO  [STDOUT] Im Durchgang: javax.security.auth.callback.NameCallback@157457b
2005-09-13 16:04:56,921 INFO  [STDOUT] ------------------------------
2005-09-13 16:04:56,921 INFO  [STDOUT] im Handler-Name
2005-09-13 16:04:56,921 INFO  [STDOUT] class javax.security.auth.callback.NameCallback
2005-09-13 16:04:56,921 INFO  [STDOUT] null
2005-09-13 16:04:56,921 INFO  [STDOUT] ------------------------------
2005-09-13 16:04:56,921 INFO  [STDOUT] Authentication failed. CallbackHandler does not support: javax.security.auth.callback.NameCallback@157457b

Und hier noch die login-config.xml die ich beim gestarteten JBoss -Server in dem configOrdner liegen habe:

Code:
<?xml version='1.0'?>
<!DOCTYPE policy PUBLIC
      "-//JBoss//DTD JBOSS Security Config 3.0//EN"
      "http://www.jboss.org/j2ee/dtd/security_config.dtd">

<!-- The XML based JAAS login configuration read by the
org.jboss.security.auth.login.XMLLoginConfig mbean. Add
an application-policy element for each security domain.

<policy>
    <application-policy name = "jave">
       <authentication>
          <login-module code="at.sozvers.svb.jave.jaas.module.JaveLoginModule" flag = "required">
             <module-option name = "applId">EB</module-option>
	     <module-option name = "environment">E</module-option>
	     <module-option name = "cicsRegion">C99ENTW</module-option>
	     <module-option name = "host">hvviae.hvb.sozvers.at</module-option>
	     <module-option name = "port">2006</module-option>
          </login-module>
          <login-module code = "org.jboss.security.ClientLoginModule" flag = "required">
          </login-module>
       </authentication>
    </application-policy>
</policy

Und zu guter letzt die jboss-web.xml

Code:
<jboss-web>
   
   <security-domain>
   		java:/jaas/jave
   	</security-domain>
</jboss-web>

Wo liegt mein Problem :?: :x :?: ???:L
 
Glaube fast an der Lösung zu sein!

-------------------------------------------------
EDIT:

Folgende Warnung wird erzeugt wenn der JBOSS hochfährt:


09:38:59,421 WARN [ConfiguredIdentityLoginModule] Creating LoginModule with no configured password!

-------------------------------------------------

Habe folgendes in die login-config.xml eingetragen:

Code:
Habe folgendes in die login-config.xml eingetragen:
<application-policy name = "jave">
       <authentication>
          <login-module code="at.sozvers.svb.jave.jaas.module.JaveLoginModule" flag = "required">
          </login-module>
          <login-module code = "org.jboss.security.ClientLoginModule" flag = "required">    
          </login-module>     
       </authentication>
    </application-policy>

Jetzt nimmt er aber nicht mein Login-Modul sondern nur das ClientLoginModule.

Kurze erklärung:

Code:
<application-policy name = "jave">

jave ist meine Applikation die ich deploy und die das LoginModul beinhaltet

Wo und wie muss ich JBOSS nun sagen wo er mein LoginModul findet?

Die Klasse LoginModul von der nichteinmal die initialize Methode aufgerufen wird!

Code:
public class JaveLoginModule implements LoginModule {
  private Subject subject;
  private JavePrincipal entity;
  private CallbackHandler callbackhandler;
  private static final int NOT = 0;
  private static final int OK = 1;
  private static final int COMMIT = 2;
  private int status;

  public void initialize(Subject subject, CallbackHandler
   callbackhandler, Map state, Map options) {
		System.out.println("------------------------------");
		System.out.println("vor dem Handler-I");
		System.out.println("------------------------------");
    status = NOT;
    entity = null;
    this.subject = subject;
    this.callbackhandler = callbackhandler;
	System.out.println("Wurde initialisiert");
	Collection v = options.values();
	Iterator it = v.iterator();
	while(it.hasNext()){
		System.out.println(it.next());
	}

	System.out.println("------------------------------");
	System.out.println("nach dem Handeler-I");
	System.out.println("------------------------------");
  }

  public boolean login() throws LoginException {
		System.out.println("Loginversuch");

    if(callbackhandler == null) {
      throw new LoginException("No callback handler is available");
    }
    Callback callbacks[] = new Callback[2];
    callbacks[0] = new NameCallback("What is the weather like today?");
    callbacks[1] = new PasswordCallback("What is the weather like today?", false);
    String name = null;
    try {
		System.out.println("------------------------------");
		System.out.println("vor dem Handelen");
		System.out.println("------------------------------");
      callbackhandler.handle(callbacks);
		System.out.println("------------------------------");
		System.out.println("nach dem Handelen");
		System.out.println("------------------------------");
      name = ((NameCallback)callbacks[0]).getName();
    } catch(java.io.IOException ioe) {
      throw new LoginException(ioe.toString());
    } catch(UnsupportedCallbackException ce) {
      throw new LoginException("Error: "+ce.getCallback().toString());
    }
    if(name.equals("Sunny")) {
      entity = new JavePrincipal("SunnyDay");
      status = OK;
      return true;
    } else {
      return false;
    }
  }

  public boolean commit() throws LoginException {
    if(status == NOT) {
      return false;
    }
    if(subject == null) {
      return false;
    }
    Set entities = subject.getPrincipals();
    if(!entities.contains(entity)) {
      entities.add(entity);
    }
    status = COMMIT;
    return true;
  }

  public boolean abort() throws LoginException {
    if((subject != null) && (entity != null)) {
      Set entities = subject.getPrincipals();
      if(entities.contains(entity)) {
        entities.remove(entity);
      }
    }
    subject = null;
    entity = null;
    status = NOT;
    return true;
  }

  public boolean logout() throws LoginException {
    subject.getPrincipals().remove(entity);
    status = NOT;
    subject = null;
    return true;
  }
}

Vielen Dank[/b]
 
Man glaube es kaum aber es läuft noch immer nicht!

Folgendes Problem:

Benutzer möchte auf eine gesicherte Seite.
--> Loginmodul wird geladen und LoginSeite wird auch angezeigt

Benutzer gibt seine Benutzerdaten ein.
--> login-Methode in meinen Loginmodul wird aufgerufen

Benutzer hat sich richtig angemeldet
--> folgende Meldung wird ausgegeben: HTTP Status 403 - Access to the requested resource has been denied

Hier meine web.xml

Code:
<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">
    <display-name>Verzweigungslogik</display-name>
  
  
  <servlet>
    <servlet-name>controller</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet </servlet-class>
  <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    <security-role-ref>
		<role-name>TEST</role-name>
		<role-link>TEST</role-link>
	</security-role-ref>
  </servlet>
  
  
  <servlet-mapping>
    <servlet-name>controller</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  
	<security-constraint>
		<web-resource-collection>
			<web-resource-name>jave</web-resource-name>
			<url-pattern>/verzweigung.do</url-pattern>
			<http-method>HEAD</http-method>
			<http-method>GET</http-method>
			<http-method>POST</http-method>
			<http-method>PUT</http-method>
			<http-method>DELETE</http-method>
		</web-resource-collection>
		<auth-constraint>
			<role-name>TEST</role-name>
		</auth-constraint>
	</security-constraint>
 <!-- 
 Definiert die Art mit der sich der Benutzer anmelden soll
  -->
	<login-config>
		<auth-method>FORM</auth-method>				
		<realm-name>jave</realm-name>
		<form-login-config>
			<form-login-page>/html/seiten/checkLogin.jsp</form-login-page>
			<form-error-page>/html/seiten/hilfe.jsp</form-error-page>
		</form-login-config>
	</login-config>
	
<!-- 
Definiert die vorhandenen Rollen
 -->
	<security-role>
		<role-name>TEST</role-name>
	</security-role>
	<welcome-file-list>
		<welcome-file>
			html/seiten/verzweigung.jsp
		</welcome-file>
	</welcome-file-list>
</web-app>

Und hier mein LoginModul:

Code:
public class JaveLoginModule implements LoginModule {
	private Subject subject;

	private JavePrincipal entity;

	protected CallbackHandler callbackhandler;

	private static final int NOT = 0;

	private static final int OK = 1;

	private static final int COMMIT = 2;


	private String name = null;
	private String pwd = null;
	
	private int status;

	public JaveLoginModule(){
		System.out.println("LoginModule wurde Instanziert");
	}
	public void initialize(Subject subject, CallbackHandler callbackhandler,
			Map state, Map options) {
		System.out.println("INI");
		status = NOT;
		entity = null;
		System.out.println("Subject1: " + subject);
		this.subject = subject;
		this.callbackhandler = callbackhandler;
	}
	public boolean login() throws LoginException {
		if (callbackhandler == null) {
			System.out.println("im if");
			throw new LoginException("No callback handler is available");
		}
		Callback callbacks[] = new Callback[2];
		callbacks[0] = new NameCallback("j_username");
		callbacks[1] = new PasswordCallback("j_password",false);		
		try {
			callbackhandler.handle(callbacks);
			name = ((NameCallback) callbacks[0]).getName();
			pwd = new String(((PasswordCallback) callbacks[1]).getPassword());
		} catch (java.io.IOException ioe) {
			throw new LoginException(ioe.toString());
		} catch (UnsupportedCallbackException ce) {
			throw new LoginException("Error: " + ce.getCallback().toString());
		}
		DTOAnmelden anm = new DTOAnmelden();
		anm.benutzerID = name;
		anm.pwd = pwd;
		DTOBearbeiter bearbeiter = BCFactory.getBCController().anmelden(anm);

		if(bearbeiter.isOk()){
			status = OK;
			JavePrincipal pr = new JavePrincipal(name);
			pr.setBenutzer(bearbeiter);
			entity = pr;			
			return true;
		}
		System.out.println("Fehler");
		return false;
	}
	public boolean commit() throws LoginException {
		System.out.println("Commit");
		if (status == NOT) {
			return false;
		}
		if (subject == null) {
			return false;
		}

		System.out.println("Subject2: " + subject);
		
		Set entities = subject.getPrincipals();
		
		System.out.println("Leer: " + entities.isEmpty());
		Iterator it = entities.iterator();
		try{					
			if (!entities.contains(entity)) {
				System.out.println("t1");
				subject.getPrincipals().add(entity); 
				subject.getPublicCredentials().add(new String("TEST"));
				System.out.println("t2");
			}
		}
		catch(Exception e2)
		{
			e2.printStackTrace();
		}
		entities = subject.getPrincipals();

		System.out.println("Subject3: " + subject);
		System.out.println("Leer: " + entities.isEmpty());
		
		status = COMMIT;
		System.out.println("Subject3-");
		return true;
	}
	public boolean abort() throws LoginException {
		System.out.println("abort");
		System.out.println("Status: " +status);
		if ((subject != null) && (entity != null)) {
			Set entities = subject.getPrincipals();
			if (entities.contains(entity)) {
				entities.remove(entity);
			}
		}
		subject = null;
		entity = null;
		status = NOT;
		return true;
	}
	public boolean logout() throws LoginException {
		System.out.println("Logout");
		subject.getPrincipals().remove(entity);
		status = NOT;
		subject = null;
		return true;
	}
}

HILFEEEEEEEEEEEEEEE!!!!!!!!!!!!!
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben