博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
configure JAAS for jboss 7.1 and mysql--reference
阅读量:6508 次
发布时间:2019-06-24

本文共 9703 字,大约阅读时间需要 32 分钟。

Hello all, In this tutorial we are going to configure JAAS for jboss 7.1 and mysql for Form based authentication to be used in a web application. . We have already covered how toThe difference between these is due to jBoss 7.1 application server. We need to configure subsystems and modules in case of jBoss 7.1 unlike Tomcat. It is assumed that you have basic knowledge of mysql, application servers, eclipse and creating a dynamic web project.

 

Configure JAAS for jboss 7.1

Pre-requisites:

  1. jBoss 7.1 application server
  2. Mysql database
  3. eclipse IDE (I’m using Juno in this article)
  4. Mysql connector jar file

Database configuration.

Create a database and create three tables as provided in the diagram.

Tables to be created for JDBCRealm of users

  • users: Stores username and password which need to be authenticated
  • roles :  Stores allowed roles
  • users_roles: Stores the relation between users and their allowed roles.

This table structure is needed to configure JAAS for jboss 7.1 and mysql

Create database :

 

 

 Insert data into database:

 

Now we are done with your database part. We need to tell jBoss application server that we are going to use this database for JDBCRealm purpose. Normally we would place mysql connector jar into library of web application but for jBoss 7.1 we need to create a module for it and declare it in jBoss configuration file i.e. standalone.xml .

 

Creating module for mysql :

  • Navigate to <jboss_home>/modules/com  e.g. C:\jboss-as-7.1.1.Final\modules\com
  • Create a folder called mysql in it and under mysql , create another folder named main
  • Under main , copy your mysql connector jar file  and create a file calledmodule.xml

Your structure and the files under main folder should be

Folder structure for module

 

Now that we have created module.xml file and copied mysql connector jar for jdbc connectivity we need to specify that we are using this mysql connector jar as a resource for this module name.

So in your blank module.xml file, put following code

 

We are done for module creation. Now we need to configure it in standalone.xml

Configure module in standalone.xml

Navigate to <jboss_home>/standalone/configuration and open standalone.xml .

You will find a datasources tag under which you need to put this

 

  •  jndi name is the identifier we are going to use in our security configuration.
  • jdbc:mysql://localhost:3306/tutorialsDB is our database to which jndi name points.

Add following code to subsystems tag.

Configure jdbc driver using previously created module. Add following into drivers tag instandalone.xml

Now jBoss7.1 know that this database will be used as datasource. Now we need to configure this JAAS for jboss 7.1. So we will define security subsystem for authentication and authorization.

Add following code to  standalone.xml  under security-domains

 

  •  dsJndiName defines the name of the datasource used for jdbc realm.
  • principalsQuery defines the query which retrieves all usernames from the database which is configured for jdbc realm. In our case tutorialsdb will be used.
  • rolesQuery defines the roles defined for user which is authenticated.

Configuration is done for jBoss application server.

Application configuration:

First create a new dynamic web project in eclipse. We will name it jBossJaasMysql.After creating it, create files as shown in following folder structure.

Folder Structure of application

  • login.jsp : asks username and password for the user.
  • index.jsp : This is a protected resource. Accessing this directly should ask for username and password using FORM based authentication and authorization service which we have configured.
  • jboss-web.xml : Tells the application which security system should be used.
  • web.xml: Configures application for FORM based authentication.

 

 

index.jsp

login.jsp

error.jsp

Add this code to your web.xml

 

  •  code in web-resource-collection tag means that resources with url pattern/protected/*  are constrained such that only DELETE, GET, POST and PUT operations can be performed for the role user
  • login-config configures the FORM authentication.

This is your jboss-web.xml

We are all done with configuration and setup part.

Hit the url http://localhost:8080/jBossJaasMysql/protected/index.jsp

As this is constrained resource, you will be asked to log in to application by this page.

Login page

Enter wrong username and password e.g. someUser/somePassword and click submit. You will see error.jsp showing message Invalid username and/or password.

Now again visit http://localhost:8080/jBossJaasMysql/protected/index.jsp  and enter username as prasad and password as kharkar.

This time, as we configure JAAS for jboss 7.1 and mysql the user prasad will be checked into database and the roles allotted to him. If he enters correct password, then he is authenticated. If a constrained resource is allowed to access a particular role, then it will be available. As index.jsp can be accessed with role user, prasad can accessindex.jsp now.

Hope this tutorial helps configure JAAS for jboss 7.1 and mysql.

原文地址:http://www.thejavageek.com/2013/09/18/configure-jaas-jboss-7-1-mysql/

转载地址:http://gfwfo.baihongyu.com/

你可能感兴趣的文章
C#基础第五天
查看>>
python 小数相加报错 invalid literal for int() with base 10
查看>>
【ubuntu】linux链接库
查看>>
uva 12325 枚举暴力 b
查看>>
多线程问题(JVM重排序)
查看>>
LeetCode 459 Repeated Substring Pattern
查看>>
POJ 3268 Silver Cow Party
查看>>
Android Camera开发:使用TextureView和SurfaceTexture预览Camera 基础拍照demo
查看>>
EMLS项目推进思考
查看>>
Eclipse快捷键 10个最有用的快捷键
查看>>
2018-2019-1 20165302 实验五 通讯协议设计
查看>>
快速寻找满足条件的两个数
查看>>
centos6.5安装LNMP
查看>>
Golang 知识点总结
查看>>
JAVA 8 特性
查看>>
算法设计 - LCS 最长公共子序列&&最长公共子串 &&LIS 最长递增子序列
查看>>
WebService之Axis2快速入门(7): Spring与axis整合发布为WebServic
查看>>
Uliweb查看模板调用关系
查看>>
C#与PHP通信压缩
查看>>
根据经纬度获取时区信息
查看>>