jeudi 2 juillet 2015

How I can user web security in my java ee application with wildfly?

hi community i want to add web security to my java ee web application. For this i look on oracle site. I use a WildFly 8 Applicationserver and define a login.xhtml and error.xhtml.

I create two users in my WildFly.

For ADMINISTRATOR: ticketAdmin For USER: ticketUser

in the documentation i read i must configuration the web.xml and I done that.

Here my web.xml:

<security-constraint>

    <web-resource-collection>
        <web-resource-name>Webseite</web-resource-name>
        <url-pattern>/*</url-pattern>
        <http-method>POST</http-method>
        <http-method>GET</http-method>
    </web-resource-collection>

    <auth-constraint>
        <role-name>ADMINISTRATOR</role-name>
        <role-name>USER</role-name>
    </auth-constraint>

  </security-constraint>

  <security-constraint>
    <web-resource-collection>
        <web-resource-name>Komponenten</web-resource-name>
        <url-pattern>/javax.faces.resource/*</url-pattern>
    </web-resource-collection>
  </security-constraint>

  <login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
        <form-login-page>/login.xhtml</form-login-page>
        <form-error-page>/error.xhtml</form-error-page>
    </form-login-config>
  </login-config>

  <security-role>
    <role-name>ADMINISTRATOR</role-name>
  </security-role>

  <security-role>
    <role-name>USER</role-name>
  </security-role>

But if I start my Application the login.xhtml not start. :(

Here is my login.xhtml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ift.tt/kkyg93">
<html xmlns="http://ift.tt/lH0Osb"
      xmlns:ui="http://ift.tt/KsEgXx"
      xmlns:f="http://ift.tt/HcrI1S"
      xmlns:h="http://ift.tt/HjFrZb">

    <ui:composition template="/templates/template.xhtml">

        <ui:define name="title">Anmeldung</ui:define>

        <ui:define name="content">

            <form method="POST" action="j_security_check">
                <div class="row form-group">

                    <div class="col-sm-12">
                        <div class="col-sm-2">
                            <h:outputLabel for="j_username" value="Anmeldename" />
                        </div>
                        <div class="col-sm-10">
                            <h:inputText id="j_username" size="20" />
                        </div>
                    </div>

                    <div class="col-sm-12">
                        <div class="col-sm-2">
                            <h:outputLabel for="j_password" value="Kennwort" />
                        </div>
                        <div class="col-sm-10">
                            <h:inputSecret id="j_password" size="20" />
                        </div>
                    </div>

                    <div class="col-sm-12" style="margin-top:20px">
                        <input type="submit" value="Anmelden" 
                                class="btn btn-default" />
                    </div>

                </div>
            </form> 

        </ui:define>

    </ui:composition>
</html>




Aucun commentaire:

Enregistrer un commentaire