<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
AS7 : Security Domain Model - need help!
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/chris81t">chris81t</a> in <i>JBoss AS 7 Development</i> - <a href="http://community.jboss.org/message/641555#641555">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Hello,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I'm writing a web application ( using JBoss AS7.0.2 ) which requires a login. A few month's ago I have written a custom loginModule / Realm for the glassfish server ( custom while using db-tables that knows the login-informations. I know that DatabaseModules exist, but the given/required table structure of that existing db-module doesn't match with my db-model )</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I have found following article: <a class="" href="http://community.jboss.org/docs/DOC-16811">http://community.jboss.org/wiki/JBossAS7SecurityDomainModel</a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>There I found the hint to the article: <a class="" href="http://community.jboss.org/docs/DOC-17357">http://community.jboss.org/wiki/JBossAS7SecurityCustomLoginModules</a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><strong>First question:</strong> Is a custom login module only possible with the coming AS 7.1 release? Or can I use it with my AS 7.0.2 app-server?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>So my first step is to write a simple prototype- example web application, which uses the <strong>UsersRoles</strong> Security Domain.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>First I have added to the standalone.xml following part (blue text):</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-xml">            <span class="jive-xml-tag"><security-domains></span>
                <span class="jive-xml-tag"><security-domain name="other" cache-type="default"></span>
                    <span class="jive-xml-tag"><authentication></span>
                        <span class="jive-xml-tag"><login-module code="Disabled" flag="required"/></span>
                    <span class="jive-xml-tag"></authentication></span>
                <span class="jive-xml-tag"></security-domain></span>
                <span class="jive-xml-tag"><security-domain name="form-auth" cache-type="default"></span>
                    <span class="jive-xml-tag"><authentication></span>
                        <span class="jive-xml-tag"><login-module code="UsersRoles" flag="required"></span>
                            <span class="jive-xml-tag"><module-option name="usersProperties" value="users.properties"/></span>
                            <span class="jive-xml-tag"><module-option name="rolesProperties" value="roles.properties"/></span>
                        <span class="jive-xml-tag"></login-module></span>
                    <span class="jive-xml-tag"></authentication></span>
                <span class="jive-xml-tag"></security-domain></span>
            <span class="jive-xml-tag"></security-domains></span>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Now my web- example project (JSF2.0 using CDI) (is attached as an eclipse project to this post):</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>- the project contains the properties files</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I have got as the welcome page a start.xhtml. While defined the security-constraint in the web.xml the login.xhtml page (two input fields for user/password and one commandButton for the login) should be called, if an access to the start.xhtml will occur.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="text-decoration: underline;">Here some code-snippets:</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The managed bean, which executes the login while pressing the commandButton:</p><pre class="jive-pre"><code class="jive-code jive-java">@Named
@RequestScoped
<font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> LoginBean <font color="navy"><b>implements</b></font> Serializable <font color="navy">{</font>
 
 
          <font color="navy"><b>private</b></font> <font color="navy"><b>static</b></font> <font color="navy"><b>final</b></font> <font color="navy"><b>long</b></font> serialVersionUID = -6308095244497641582L;
          <font color="navy"><b>private</b></font> String user;
          <font color="navy"><b>private</b></font> String password;
 
          <font color="navy"><b>public</b></font> String getUser() <font color="navy">{</font>
                    <font color="navy"><b>return</b></font> user;
          <font color="navy">}</font>
          <font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> setUser(String user) <font color="navy">{</font>
                    this.user = user;
          <font color="navy">}</font>
          <font color="navy"><b>public</b></font> String getPassword() <font color="navy">{</font>
                    <font color="navy"><b>return</b></font> password;
          <font color="navy">}</font>
          <font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> setPassword(String password) <font color="navy">{</font>
                    this.password = password;
          <font color="navy">}</font>
 
          <font color="navy"><b>public</b></font> String login() <font color="navy">{</font>
                    FacesContext fc = FacesContext.getCurrentInstance();
                    ExternalContext ec = fc.getExternalContext();
                    HttpServletRequest hsr = (HttpServletRequest) ec.getRequest();
 
                    <font color="navy"><b>try</b></font> <font color="navy">{</font>
                              hsr.login(user, password); 
                    <font color="navy">}</font>
                    <font color="navy"><b>catch</b></font> (ServletException se) <font color="navy">{</font>
                              <font color="darkgreen">// create a message to inform the user</font>
                              FacesMessage msg = <font color="navy"><b>new</b></font> FacesMessage(FacesMessage.SEVERITY_WARN,
                                                                                                                        <font color="red">"Ein falscher Profilname und "</font> +
                                                                                                                        <font color="red">"oder ein falsches Passwort "</font> +
                                                                                                                        <font color="red">"wurde eingegeben!"</font>,
                                                                                                                        <font color="navy"><b>null</b></font>);
                              fc.addMessage(null, msg);
                              <font color="navy"><b>return</b></font> <font color="navy"><b>null</b></font>;
                    <font color="navy">}</font>
 
                    <font color="darkgreen">// for the first test simply navigate to the one existing page</font>
                    <font color="navy"><b>return</b></font> <font color="red">"/start"</font>;
          <font color="navy">}</font>
<font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>web.xml</p><pre class="jive-pre"><code class="jive-code jive-xml"><span class="jive-xml-tag"><?xml version="1.0" encoding="UTF-8"?></span>
<span class="jive-xml-tag"><span><web-app xmlns:xsi="</span><a class="jive-link-external-small" href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a><span>"
                     xmlns="</span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/javaee" target="_blank">http://java.sun.com/xml/ns/javaee</a><span>"
                     xmlns:web="</span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" target="_blank">http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd</a><span>"
                     xsi:schemaLocation="</span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/javaee" target="_blank">http://java.sun.com/xml/ns/javaee</a><span> </span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" target="_blank">http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd</a><span>"
                     id="WebApp_ID"
                     version="3.0"></span></span>
  
   <span class="jive-xml-tag"><display-name></span>LoginExample<span class="jive-xml-tag"></display-name></span>
  <span class="jive-xml-comment"><!-- Change to "Production" when you are ready to deploy -->
  <span class="jive-xml-tag"><context-param></span>
    <span class="jive-xml-tag"><param-name></span>javax.faces.PROJECT_STAGE<span class="jive-xml-tag"></param-name></span>
    <span class="jive-xml-tag"><param-value></span>Development<span class="jive-xml-tag"></param-value></span>
  <span class="jive-xml-tag"></context-param></span>
  <!-- Welcome page -->
  <span class="jive-xml-tag"><welcome-file-list></span>
    <span class="jive-xml-tag"><welcome-file></span>/start.xhtml<span class="jive-xml-tag"></welcome-file></span>
  <span class="jive-xml-tag"></welcome-file-list></span>
  <span class="jive-xml-tag"><servlet></span>
    <span class="jive-xml-tag"><servlet-name></span>Faces Servlet<span class="jive-xml-tag"></servlet-name></span>
    <span class="jive-xml-tag"><servlet-class></span>javax.faces.webapp.FacesServlet<span class="jive-xml-tag"></servlet-class></span>
    <span class="jive-xml-tag"><load-on-startup></span>1<span class="jive-xml-tag"></load-on-startup></span>
  <span class="jive-xml-tag"></servlet></span>
  <span class="jive-xml-tag"><servlet-mapping></span>
    <span class="jive-xml-tag"><servlet-name></span>Faces Servlet<span class="jive-xml-tag"></servlet-name></span>
    <span class="jive-xml-tag"><url-pattern></span>*.xhtml<span class="jive-xml-tag"></url-pattern></span>
  <span class="jive-xml-tag"></servlet-mapping></span> 
  <!-- Define a Security Constraint on this Application -->
  <span class="jive-xml-tag"><security-constraint></span>
    <span class="jive-xml-tag"><web-resource-collection></span>
      <span class="jive-xml-tag"><web-resource-name></span>SALES Application<span class="jive-xml-tag"></web-resource-name></span>
      <span class="jive-xml-tag"><url-pattern></span>/*<span class="jive-xml-tag"></url-pattern></span>
    <span class="jive-xml-tag"></web-resource-collection></span>
    <span class="jive-xml-tag"><auth-constraint></span>
       <span class="jive-xml-tag"><role-name></span>user<span class="jive-xml-tag"></role-name></span>
    <span class="jive-xml-tag"></auth-constraint></span>
  <span class="jive-xml-tag"></security-constraint></span>
  <!-- Define the Login Configuration for this Application -->
  <span class="jive-xml-tag"><login-config></span>
    <span class="jive-xml-tag"><auth-method></span>FORM<span class="jive-xml-tag"></auth-method></span>
    <span class="jive-xml-tag"><realm-name></span>Login Example Application<span class="jive-xml-tag"></realm-name></span>
    <span class="jive-xml-tag"><form-login-config></span>
       <span class="jive-xml-tag"><form-login-page></span>/login.xhtml<span class="jive-xml-tag"></form-login-page></span>
       <span class="jive-xml-tag"><form-error-page></span>/failure.xhtml<span class="jive-xml-tag"></form-error-page></span>
    <span class="jive-xml-tag"></form-login-config></span>
  <span class="jive-xml-tag"></login-config></span>
  <!-- Security roles referenced by this web application --></span>
  <span class="jive-xml-tag"><security-role></span>
    <span class="jive-xml-tag"><description></span>
      The role that is required to log in to the Example Application
    <span class="jive-xml-tag"></description></span>
    <span class="jive-xml-tag"><role-name></span>user<span class="jive-xml-tag"></role-name></span>
  <span class="jive-xml-tag"></security-role></span>
 
<span class="jive-xml-tag"></web-app></span>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>jboss-web.xml</p><pre class="jive-pre"><code class="jive-code jive-xml"><span class="jive-xml-tag"><?xml version="1.0" encoding="UTF-8"?></span>
<span class="jive-xml-tag"><jboss-web></span>
          <span class="jive-xml-tag"><security-domain></span>form-auth<span class="jive-xml-tag"></security-domain></span>
          <span class="jive-xml-tag"><disable-audit></span>true<span class="jive-xml-tag"></disable-audit></span>
          <span class="jive-xml-tag"><context-root></span>/login<span class="jive-xml-tag"></context-root></span>
<span class="jive-xml-tag"></jboss-web></span>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><strong>during the deployment the jboss fails with following error:</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><blockquote class="jive-quote"><p>15:56:16,109 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-10) MSC00001: Failed to start service jboss.deployment.unit."SecurityDomainLoginExample.war".PARSE: org.jboss.msc.service.StartException in service jboss.deployment.unit."SecurityDomainLoginExample.war".PARSE: Failed to process phase PARSE of deployment "SecurityDomainLoginExample.war"</p><p>          at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:121) [jboss-as-server-7.0.2.Final.jar:7.0.2.Final]</p><p>          at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]</p><p>          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]</p><p>          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [:1.7.0_b147-icedtea]</p><p>          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [:1.7.0_b147-icedtea]</p><p>          at java.lang.Thread.run(Thread.java:722) [:1.7.0_b147-icedtea]</p><p>Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: Failed to parse "/content/SecurityDomainLoginExample.war/WEB-INF/jboss-web.xml" at [4,2]</p><p>          at org.jboss.as.web.deployment.JBossWebParsingDeploymentProcessor.deploy(JBossWebParsingDeploymentProcessor.java:68)</p><p>          at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115) [jboss-as-server-7.0.2.Final.jar:7.0.2.Final]</p><p>          ... 5 more</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>15:56:16,111 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) Service status report</p><p>  Services which failed to start:</p><p>      service jboss.deployment.unit."SecurityDomainLoginExample.war".PARSE: org.jboss.msc.service.StartException in service jboss.deployment.unit."SecurityDomainLoginExample.war".PARSE: Failed to process phase PARSE of deployment "SecurityDomainLoginExample.war"</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></blockquote><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Can anybody help me? Thank's!</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Regards,</p><p>Christian</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/641555#641555">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss AS 7 Development at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2225">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>