6 Replies - 1662 Views - Last Post: 22 February 2012 - 08:52 AM

#1 zakhussain299  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 25-February 11

Integrating LDAP with JBoss AS

Posted 20 February 2012 - 11:44 AM

I am trying to write a web application that will authenticate and authorize the user by making use of the LDAP. However I followed the tutorial over here but still I was not able to make a connection with the LDAP server.

My web.xml is

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5">
	<display-name>AAJboss</display-name>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>

	<security-constraint>
		<web-resource-collection>
			<web-resource-name>Secure Resource</web-resource-name>
			<url-pattern>/secured/*</url-pattern>
			<http-method>POST</http-method>
			<http-method>GET</http-method>
		</web-resource-collection>
		<auth-constraint>
			<role-name>uv_admin</role-name>
		</auth-constraint>
	</security-constraint>
	<login-config>
		<auth-method>FORM</auth-method>
		<form-login-config>
			<form-login-page>/login.html</form-login-page>
			<form-error-page>/error.html</form-error-page>
		</form-login-config>
	</login-config>
	<security-role>
		<role-name>uv_admin</role-name>
	</security-role>
</web-app>



jboss-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
	<security-domain>java:/jaas/example</security-domain>
</jboss-web>  




login-config.xml

<application-policy name="example">
	<authentication>
		<login-module code="LdapExtended" flag="required">
			<module-option name="java.naming.factory.initial" value="com.sun.jndi.ldap.LdapCtxFactory"/>
			<module-option name="java.naming.provider.url" value="ldap://localhost:10389"/>
			<module-option name="java.naming.security.authentication" value="simple"/>
			<module-option name="bindDN" value="uid=admin,ou=system"/>
			<module-option name="bindCredential" value="secret"/>
			<module-option name="baseCtxDN" value="ou=people,o=xxx"/>
			<module-option name="baseFilter" value="(uid={0})"/>
			<module-option name="rolesCtxDN" value="ou=Roles,o=mouser"/>
			<module-option name="roleFilter" value="(member={1})"/>
			<module-option name="roleAttributeID" value="cn"/>
			<module-option name="searchScope" value="SUBTREE_SCOPE"/>
			<module-option name="allowEmptyPasswords" value="false"/>
		</login-module>
	</authentication>
  </application-policy>


Is This A Good Question/Topic? 0
  • +

Replies To: Integrating LDAP with JBoss AS

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 9150
  • View blog
  • Posts: 33,954
  • Joined: 27-December 08

Re: Integrating LDAP with JBoss AS

Posted 20 February 2012 - 11:47 AM

I already deleted the other thread while you were closing this one, blackcompe. Sorry to step on your toes! I'll reopen this one. :)
Was This Post Helpful? 0
  • +
  • -

#3 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1009
  • View blog
  • Posts: 2,186
  • Joined: 05-May 05

Re: Integrating LDAP with JBoss AS

Posted 20 February 2012 - 04:15 PM

You should ask this in the JBoss forums.
Was This Post Helpful? 0
  • +
  • -

#4 zakhussain299  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 25-February 11

Re: Integrating LDAP with JBoss AS

Posted 20 February 2012 - 04:18 PM

I posted the question over there but I was not able to get any response.
Was This Post Helpful? 0
  • +
  • -

#5 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1009
  • View blog
  • Posts: 2,186
  • Joined: 05-May 05

Re: Integrating LDAP with JBoss AS

Posted 20 February 2012 - 04:31 PM

I'd try StackOverflow then. Your more likely to get an answer at any one of those two places than here.

(1) You haven't included any error messages and (2) we can't test your code and configuration without having an LDAP server deployed. At a more specialized forum, someone might be able to quickly look and spot any errors in your code or configurations.
Was This Post Helpful? 0
  • +
  • -

#6 zakhussain299  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 25-February 11

Re: Integrating LDAP with JBoss AS

Posted 22 February 2012 - 07:56 AM

Ok I got the LDAP configured but now I can move onto what I actually wanted to do. I wanted to have form login on a url pattern handled by the servlet then once the user is authorized, I wanted the servlet to display the information specific to the role of the user. I have come up with the following code but it comes up with an error.


import java.io.IOException;
import java.io.PrintWriter;

import javax.faces.context.FacesContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class AuthServlet
 */
public class AuthServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html");
		request=(HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
		String user=request.getRemoteUser();
		PrintWriter writer=response.getWriter();
		if(request.isUserInRole("uv_admin")){
			writer.println("<h1>Welcome "+user+", login was successful</h1>");
		}else{
			writer.println("<h1>Not able to get the user</h1>");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html");
		request=(HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
		String user=request.getRemoteUser();
		PrintWriter writer=response.getWriter();
		if(request.isUserInRole("uv_admin")){
			writer.println("<h1>Welcome "+user+", login was successful</h1>");
		}else{
			writer.println("<h1>Not able to get the user</h1>");
		}
	}

}



It came up with the following exception and root cause in the browser.

Exception
javax.servlet.ServletException: Error instantiating servlet class com.xxx.AAServlet.AuthServlet
	org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
	org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
	org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
	org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
	org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	java.lang.Thread.run(Unknown Source)





Root cause

java.lang.ClassNotFoundException: com.xxx.AAServlet.AuthServlet
	java.net.URLClassLoader$1.run(Unknown Source)
	java.security.AccessController.doPrivileged(Native Method)
	java.net.URLClassLoader.findClass(Unknown Source)
	java.lang.ClassLoader.loadClass(Unknown Source)
	java.lang.ClassLoader.loadClass(Unknown Source)
	org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:240)
	org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
	org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
	org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
	org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
	org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	java.lang.Thread.run(Unknown Source)



Was This Post Helpful? 0
  • +
  • -

#7 zakhussain299  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 25-February 11

Re: Integrating LDAP with JBoss AS

Posted 22 February 2012 - 08:52 AM

Got it working
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1