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!
 

KSG9|sebastian

Top Contributor
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
 

DreamArtist

Bekanntes Mitglied
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
 

DreamArtist

Bekanntes Mitglied
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]
 

DreamArtist

Bekanntes Mitglied
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.
Ähnliche Java Themen
  Titel Forum Antworten Datum
A JAAS via Wildfly Allgemeines EE 0
N JAAS login() mehrere Parameter an LoginModul übergeben Allgemeines EE 2
S JAAS Verständnisfrage Allgemeines EE 2
S LDAP JAAS oder Servlet Allgemeines EE 0
P JAAS RolesQuery rauskriegen Allgemeines EE 7
P Kriege JAAS einfach nicht zum Laufen Allgemeines EE 3
P JAAS mit jboss 6 Allgemeines EE 2
B GlassFish & JAAS - Konfiguration für AppClient Allgemeines EE 1
O JAAS auf Tomcat - Überblick? Allgemeines EE 2
Y Authorisation (JAAS?) Allgemeines EE 3
D Navigation verhindern unter bestimmten Voraussetzungen Allgemeines EE 3
thor_norsk Glassfish Server unter Windows startet nicht! Allgemeines EE 20
feinperligekohlensaeure JSF Keine Tabelle / Buttons werden unter Windows angezeigt + Apple schon Allgemeines EE 9
M Glassfish Deployment-Problem unter Eclipse Allgemeines EE 0
J Logging und Monitoring unter Tomcat Allgemeines EE 2
H Bean läuft unter GlassFish, aber JBoss nicht Allgemeines EE 5
D HTTPS unter JAX-WS verwenden Allgemeines EE 7
E Servlet unter mehreren Adressen Allgemeines EE 16
ruutaiokwu ejb hot deployment unter jboss 4.2.3 Allgemeines EE 7
M Messwertarchiv unter J2EE Allgemeines EE 4
I Web-Projekt zum Laufen bringen unter Eclipse Allgemeines EE 3
W Speicher-Problem bei WebApp unter Tomcat, Struts, Hibernate Allgemeines EE 3
G JSF 1.2 unter Netbeans 6 mit Tomcat 6.0 ->Navigationsprob Allgemeines EE 6
M embedded jboss unter eclipse 3.3 Allgemeines EE 2
A Wie werden Template Engines unter J2EE umgesetzt? Allgemeines EE 3
G Tomcat unter Eclipse starten Allgemeines EE 9
D JBOSS unter Eclipse Allgemeines EE 2
H Hilfe! Wie erstelle ich einen Interceptor unter jBoss? Allgemeines EE 3
A Tomcat undeploy unter Windows klappt nicht wegen struts.jar Allgemeines EE 2
K war-Archiv unter Tomcat neu entpacken lassen Allgemeines EE 3
S .war Datei erzeugen unter Eclipse Allgemeines EE 2
E J2EE unter Eclipse Allgemeines EE 6
C Grafische Komponenten unter Struts jsp (Liste) Allgemeines EE 4
C JBoss Server unter Eclipse 3.1 Allgemeines EE 2
FsMarine Probleme beim ausführen von JSP dateien unter Tomcat Allgemeines EE 4
T Servlet-Mapping und Welcome-File-List unter Websphere? Allgemeines EE 2
K Anfängerfrage zu JDBC installation unter TOMCAT 5.0 Allgemeines EE 4
daLenz jboss 3.2.5 konfiguration unter eclipse Allgemeines EE 2
M Problem mit Roles unter JBoss 3.2.5 Allgemeines EE 3
Y EJBs und Callbacks (Jboss 7.1) Allgemeines EE 1
J Mit @Schedule annotierte Methode wird nach einer Weile nicht mehr ausgeführt (JBoss AS 7.2) Allgemeines EE 0
P eMail versenden mit JBOSS Allgemeines EE 2
N WS-Security Beispiel mit JBOSS/Wildfly gesucht Allgemeines EE 2
I JBoss unheimlich langsam nach mehreren Deploys Allgemeines EE 2
BuckRogers Jboss 7** und j2ee 1.7 Allgemeines EE 1
D Jboss löscht Archiv nicht beim Redeployed Allgemeines EE 3
J paar Fragen zu JSF2/JEE6 Anwendung mit JBoss 7.1.1 Allgemeines EE 6
D Jboss lernen mit Praxisbeispiel Allgemeines EE 4
Y JBoss 7 - wie kann ich das logging meiner Applikation am JBoss konfigurieren Allgemeines EE 3
O JBoss und die Einbindung eines externen JAR Allgemeines EE 10
E Generelle Frage zu CDI mit JBoss AS 7.1.1 and Jave EE 6 Allgemeines EE 4
B JBoss Libs vs. JBoss Libary Allgemeines EE 12
E CDI mit verschiedenen Jars in EAR klappt auf Jboss AS 7.1.1.Final nicht Allgemeines EE 8
S Webapp in JBoss absichern nur in bestimmten Umgebungen? Allgemeines EE 2
C JBoss Clustering schlägt fehl Allgemeines EE 10
E JBoss 7.1 Datasource Problem Allgemeines EE 2
2 Deployment per EAR [JBOSS] Allgemeines EE 6
E JBoss NameNotFoundException: einloggen not bound Allgemeines EE 4
S Jboss Server Allgemeines EE 5
E JBoss, jsp und Parameter Allgemeines EE 2
S JBoss 7 Authentifizierung: "No principals available" Allgemeines EE 3
S Principal, Authentication, Security und alles im JBoss 7 Allgemeines EE 16
W JBoss 6 - SocketTimeout dynamisch setzen Allgemeines EE 2
S Manueller EJB Lookup im JBoss AS 7.0.1 Allgemeines EE 8
T eXist und JBoss Allgemeines EE 5
J JBoss, Eclipse, Webseite wird nicht angezeigt? Allgemeines EE 4
T erste Anwendung in JBoss deployen Allgemeines EE 3
V JBoss und Classloader Allgemeines EE 6
S Embedded JBoss Problem beim Deployment Allgemeines EE 4
W Anleitung/Tutorial Eclipse/JBoss 6.0 mit Seam 3.0 bzw. jBPM 5.0 Allgemeines EE 3
G JBoss Portal Allgemeines EE 5
E Servlet Wie kann ich ohne Hilfe von Eclipse in JBoss mein servlet aufrufen Allgemeines EE 2
P Kann jemand mit dieser Exception was anfangen? (JBoss) Allgemeines EE 5
ruutaiokwu jboss problem - work-verzeichnis muss manuell gelöscht werden??? Allgemeines EE 5
W JBoss log dependencies aus jbossall-client.jar Allgemeines EE 7
G JBoss Datasource Allgemeines EE 3
fastjack jBoss und externes Nachrichtensystem Allgemeines EE 3
H log4j + JBoss Allgemeines EE 10
X JBoss log4j Konflikt Allgemeines EE 2
reibi JBoss Webinterface Allgemeines EE 3
X JBoss InitialContext problem Allgemeines EE 5
E Properties-File in Jboss-Conf Verzeichnis ansprechen Allgemeines EE 2
S Servlet auf JBoss 5? Allgemeines EE 11
T Hibernate 3 + EJB 3 + JBoss 5 Allgemeines EE 6
M Deployment auf entfernten JBoss Allgemeines EE 4
T JBoss und DB2-Express Allgemeines EE 2
G separate log files in JBoss Allgemeines EE 2
Escorter JBoss AS als Webserver Allgemeines EE 2
N JBoss Problem mit Bibliothek in unterschiedlichen Versionen Allgemeines EE 2
K mehrere Datenbanken mit JBoss 4.2 und EJB3 Allgemeines EE 3
S Oracle DataSource im JBOSS ---> ClassCastException Allgemeines EE 2
S oracle db über jboss in jsp Allgemeines EE 19
F FORM Auth in JBoss für User mit falscher Rolle ? Allgemeines EE 2
E JBoss mit existierendem Tomcat nutzen? Allgemeines EE 4
T POI, Maven, JBoss und ein java.lang.NoClassDefFoundError Allgemeines EE 7
M URL-Programm-Handling mit Jboss Allgemeines EE 2
G Deployen am JBoss Server Allgemeines EE 14
I JBOSS Jsp Files Pfad im Servlet? Allgemeines EE 4
B Problem mit JBoss-4.2.1.GA Allgemeines EE 8
remus JBoss Authentifizierung mit MYSQL-Datenbank Allgemeines EE 4

Ähnliche Java Themen

Neue Themen


Oben