JDBC Realm not working : Login failed: No LoginModules configured for jdbcAuth

百般思念 提交于 2019-12-12 05:12:27

问题


Getting the following error while i try to login :

Warning: WEB9102: Web Login Failed: com.sun.enterprise.security.auth.login.common.LoginException: Login failed: No LoginModules configured for jdbcAuth

My Glassfish server version is 4

I am working on jdbc auth realm with oracle 12c as database for user authentication.

i have created a jdbc connection pool with name Oracle pool by the following properties :

Then connected the resource with the pool by name jdbc/OracleConnection :

created the tables in oracle 12c using following command :

SQL> create table users(
   2  id number,
   3  username varchar(150) not null,
   4  password varchar(50) not null,
   5  primary key (id));

SQL> create table groups(
   2  id number,
   3  username varchar2(150) not null,
   4  groupname varchar2(100) not null,
   5  primary key(id));

SQL> create sequence users_s
  2  start with 1
  3  increment by 1;

SQL> create sequence groups_s
  2  start with 1
  3  increment by 1;

inserted data using following command :

SQL> insert into users values(
  2  users_s.nextval,
  3  'admin',
  4  dbms_obfuscation_toolkit.md5(input=>utl_raw.cast_to_raw('password')));

SQL> insert into users values(
  2  users_s.nextval,
  3  'juneau',
  4  dbms_obfuscation_toolkit.md5(input=>utl_raw.cast_to_raw('password')))
  5  ;

created Realm in server-config :

After that created a new Dynamic Web Project in eclipse :

directory structure :

following are the files of that :

glassfish-web.xml :

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
    <context-root>/PsyCoder</context-root>
    <security-role-mapping>
        <role-name>admin</role-name>
        <group-name>administrator</group-name>
    </security-role-mapping>
    <security-role-mapping>
        <role-name>user</role-name>
        <group-name>reader</group-name>
    </security-role-mapping>
    <parameter-encoding default-charset="UTF-8"/>
</glassfish-web-app>

web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">
    <display-name>PsyCoder</display-name>
     <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>/faces/*</url-pattern>
    </servlet-mapping>
     <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
    <security-constraint>
        <display-name>Admin</display-name>
        <web-resource-collection>
            <web-resource-name>Admin Tools</web-resource-name>
            <description />
            <url-pattern>/faces/admin/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <description />
            <role-name>admin</role-name>
        </auth-constraint>
    </security-constraint>
    <security-constraint>
        <display-name>User</display-name>
        <web-resource-collection>
            <web-resource-name>Protected Users Area</web-resource-name>
            <description />
            <url-pattern>/faces/users/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <description />
            <role-name>user</role-name>
        </auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>JDBCAuth</realm-name>
        <form-login-config>
            <form-login-page>/faces/login.xhtml</form-login-page>
            <form-error-page>/faces/loginError.xhtml</form-error-page>
        </form-login-config>
    </login-config>
</web-app>

index.xhtml :

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">
    <h:head>
        <title>Welcome to the secure application</title>
    </h:head>
    <h:body>
        Select where you want to go:
        <br />
        <h:link outcome="admin/index" value="To the admin section" /><br />
        <h:link outcome="users/index" value="To the user section" />
    </h:body>
</html>

login.xhtml :

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:p="http://primefaces.org/ui" 
      xmlns:h="http://java.sun.com/jsf/html">
    <h:head>
        <title>Login Form</title>
    </h:head>
    <h:body>
        <p:panel header="Login From">
            <form method="POST" action="j_security_check">
                Username: <input type="text" name="j_username" />
                Password: <input type="password" name="j_password" />
                <br />
                <input type="submit" value="Login" />
                <input type="reset" value="Reset" />
            </form> 
        </p:panel>
    </h:body>
</html>

loginError.xhtml :

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:p="http://primefaces.org/ui" 
      xmlns:h="http://java.sun.com/jsf/html">
    <h:head>
        <title>Login Error </title>
    </h:head>
    <h:body>
        <p:panel header="Login Error">
            Sorry, you made an Error. <br />Please try again: <a href="#{facesContext.externalContext.requestContextPath}/" >Homepage</a>
        </p:panel>
    </h:body>
</html>

admin/index.xhtml :

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">
    <h:head>
        <title>Secured Admin Area</title>
    </h:head>
    <h:body>
        <h1>Hello Admin</h1>
        <br />
        <h:link outcome="/index" value="Back to Homepage" />
    </h:body>
</html>

users/index.xhtml :

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">
    <h:head>
        <title>Public Users Area</title>
    </h:head>
    <h:body>
        <h1>Hello users</h1>
        <br />
        <h:link outcome="/index" value="Back to Homepage" />
    </h:body>
</html>

来源:https://stackoverflow.com/questions/46347889/jdbc-realm-not-working-login-failed-no-loginmodules-configured-for-jdbcauth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!