Erro ao configurar JAAS!

Olá,

estou tentando configurar JAAS ao digitar http://localhost:8080/escola antes de ir ao arquivo index.html
queria que solicitasse na tela login usuário e senha (validar no banco de dados se existe) e ir pata tela menu central

mais não estou conseguindo configurar certo…

alguém pode me ajudar …

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.NullPointerException
	com.filters.LoginFilter.doFilter(LoginFilter.java:18)

note The full stack trace of the root cause is available in the JBoss Web/3.0.0-CR1 logs.
JBoss Web/3.0.0-CR1
 
public class LoginFilter implements Filter {
 
    @Override
    public void destroy() {
    }
 
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException,
            ServletException {
 
        String userName = SecurityAssociation.getPrincipal().getName();
 
        System.out.println("Yeeey! Get me here and find me in the database: " + userName);
 
        filterChain.doFilter(servletRequest, servletResponse);
    }
 
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }
}

<!-- Filter to get the user name and work with it -->
 <filter>
  <filter-name>LoginFilter</filter-name>
  <filter-class>com.filters.LoginFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>LoginFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <servlet>
  <servlet-name>Faces Servlet</servlet-name>
  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.xhtml</url-pattern>
 </servlet-mapping>
 <welcome-file-list>
  <welcome-file>index.html</welcome-file>
 </welcome-file-list>
 <error-page>
  <error-code>404</error-code>
  <location>/error.jsp</location>
 </error-page>
 <error-page>
  <error-code>403</error-code>
  <location>/error.jsp</location>
 </error-page>
 
 <!-- Validation By Form -->
 <login-config>
  <auth-method>FORM</auth-method>
  <form-login-config>
   <form-login-page>/pages/public/login.xhtml</form-login-page>
   <form-error-page>/pages/public/loginError.xhtml</form-error-page>
  </form-login-config>
 </login-config>
 <!-- Allowed Roles -->
 <security-role>
  <role-name>ADMIN</role-name>
 </security-role>
 <security-role>
  <role-name>USER</role-name>
 </security-role>
</web-app>

Olá,

descobri o erro na linha

//String userName = SecurityAssociation.getPrincipal().getName();
 
        //System.out.println("Yeeey! Get me here and find me in the database: " + userName);

após comentar essa linha pois ainda não tenho o usuário digitado…

mais ao comentar as linhas acima chama a página index.html

mais queria que chamasse a tela de login antes …o que houve de errado que fiz !!!

se alguém puder me ajudar …

abs

Oi,

A configuração no web.xml não está completa, falta a tag security-constraint. Nela é que serão definidos quais os recursos (paginas) que exigem segurança.

Olá,

obrigado pelo retorno.

Deixa eu tirar uma duvida o JAAS só faz validação do usuário e senha em cima de um diretório(pasta) é isso ???

abs

Olá,

mais uma duvida que estou tendo ao digitar localhost:8080/LoginJSF

porque não cai na tela login…pois o arquivo inputname.jsf está embaixo da pasta pages

não deveria chamar a tela de login !!!

pois pelo exemplo pra cai na tela de login teria digitar todo caminho http://localhost:8080/LoginJSF/pages/protected/admin/admin.html
alguém poderia me ajudar …

minha estrutura de package está assim

[code]
WebContent

  • pages
    • protected
      • admin
        -admin.xhtml
      • user
        • user.xhtml
    • public
      -login.xhtml
      -loginError.xhtml
      -public.xhtml
      inputname.jsf
      [/code]________________
      index.html
<html>
<head>
<meta http-equiv="Refresh" content="0; URL=pages/inputname.jsf" />
</head>

<h1>Index ....</h1>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
 <display-name>LoginJSF</display-name>
 <!-- Filter to get the user name and work with it -->
 <filter>
  <filter-name>LoginFilter</filter-name>
  <filter-class>com.filters.LoginFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>LoginFilter</filter-name>
  <url-pattern>/pages/protected/*</url-pattern>
 </filter-mapping>
 <servlet>
  <servlet-name>Faces Servlet</servlet-name>
  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.xhtml</url-pattern>
 </servlet-mapping>
 <welcome-file-list>
  <welcome-file>index.html</welcome-file>
 </welcome-file-list>
 <error-page>
  <error-code>404</error-code>
  <location>/error.jsp</location>
 </error-page>
 <error-page>
  <error-code>403</error-code>
  <location>/error.jsp</location>
 </error-page>
 <!-- Protected Areas -->
 
 <security-constraint>
  <web-resource-collection>
   <web-resource-name>Only admins</web-resource-name>
   <url-pattern>/pages/protected/admin/*</url-pattern>
  </web-resource-collection>
  <auth-constraint>
   <role-name>ADMIN</role-name>
  </auth-constraint>
 </security-constraint>
 <security-constraint>
  <web-resource-collection>
   <web-resource-name>Users and admins</web-resource-name>
   <url-pattern>/pages/protected/user/*</url-pattern>
  </web-resource-collection>
  <auth-constraint>
   <role-name>ADMIN</role-name>
   <role-name>USER</role-name>
  </auth-constraint>
 </security-constraint>

 <!--Validation By Form -->
 <login-config>
  <auth-method>FORM</auth-method>
  <form-login-config>
   <form-login-page>/pages/public/login.xhtml</form-login-page>
   <form-error-page>/pages/public/loginError.xhtml</form-error-page>
  </form-login-config>
 </login-config>
 <!-- Allowed Roles -->
 <security-role>
  <role-name>ADMIN</role-name>
 </security-role>
 <security-role>
  <role-name>USER</role-name>
 </security-role>
</web-app>

Não só de um diretório, as regras são definidas por padrão de URL. Esses padrões podem ser por diretório (/pasta/) , por extensão (.jsf) , etc.
Inclusive é possível colocar vários url-patterns dentro do mesmo resource-collection.

[quote=paribe]
ao digitar localhost:8080/LoginJSF
porque não cai na tela login…pois o arquivo inputname.jsf está embaixo da pasta pages
não deveria chamar a tela de login !!!

pois pelo exemplo pra cai na tela de login teria digitar todo caminho
[/paribe]
Essa parte da pergunta eu não entendi…
Está indo para a página de login e não deveria, ou não está indo e deveria ir…?

Explica melhor esse problema em “cair” na tela de login, não consegui entender também.

olá,

entendi agora o funcionamento JAAS pois pensei que podia validar somente o usuário e senha.

Mais usando JAAS tenho que associar o usuario com sua role a uma pasta ou diretório.

abs