Can I port Glassfish jdbcRealm to JBoss? - jboss

My application is running on Glassfish 3.1 using jdbcRealm is its authentication and authorization. I want to port this app to JBoss 6. Can I create a jdbcRealm inside JBoss 6 like in Glassfish3 that map to a USER table in my database? Can I do it via admin-console? In JBoss, I figure out how to create database connection (just by create datasource), but in Glassfish I also set up JavaMail Sessions in Glassfish with jndi, mail-host, transport protocol..., can I port that over to JBoss as well?

Answers on your questions:
Can I create a jdbcRealm inside JBoss
6 like in Glassfish3 that map to a
USER table in my database?
If I understand correctly you use database to authenticate users?
You can define something like that in JBoss. The easiest way is to add proper security domain definition to the conf/login-config.xml file.
It can looks like that:
<application-policy name="database-domain">
<authentication>
<login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag="required">
<module-option name="dsJndiName">java:/yourDataSource</module-option>
<module-option name="principalsQuery">select password from users where userid = ?</module-option>
<module-option name="rolesQuery">select role, 'Roles' from roles where userid = ?</module-option>
</login-module>
</authentication>
</application-policy>
You should also create proper data source and put database library to the lib directory.
Can I do it via admin-console?
I do not know if it is possible to make these changes using web console.
In JBoss, I figure out how to create
database connection (just by create
datasource), but in Glassfish I also
set up JavaMail Sessions in Glassfish
with jndi, mail-host, transport
protocol..., can I port that over to
JBoss as well?
JBoss use default database to store some information. If you want to change that the simples way is to define new data source with the DefaultDS name and delete the deploy/hsqldb-ds.xml file.
In JBoss 6 they change JMS provider and it also use its own DB to stre some info, bu I don't know if and how to change it.

Related

Implementing role based security in EJB, JPA, JSF application in JBoss

We are planning an application using EJB, JPA (persistence) & JSF (Primefaces) architecture on JBoss EAP 6.4. The way data is stored in the database or the nature of the application is, we need to use/implement Role Based Security from application layer as well. We are able to create multiple DB Connection pools (to the same DB instance) in JBoss container and each JNDI is associated with a specific DB role. In other words, if I use JNDI_Role1 connection then it will return rows from DB table according to Role1 vs if I use JNDI_Role2 connection then it will return rows from the same DB table according to Role2 which would be different then Role1 and so on. We have 4 different roles created in DB, so 4 different JNDI connection pools in JBoss container.
Now, can I implement this in my Persistence layer? If yes, how can I do that? Should I create multiple EntityManager instances tied to each connection pool/JNDI? Any suggestions with some sample code would be really appreciated!!
Thanks in advance!!
There are some links which describes role based security: See the links
[1]https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.4/html-single/Security_Guide/index.html
[2]https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/6.4/html-single/how_to_configure_server_security/
[3]https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/6.4/html-single/security_architecture/#role_based_access_control

Spring Boot JPA Database Choice

How can I start a stand-alone Spring Boot JPA application -- not via cli -- with a choice of databases to get data, e.g., localhost:5432/my_db; or 192.168.1.100:5432/our_db, or example.com:5432/their_db?
Mine currently uses the one in the application.properties file that contains:
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/my_db
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create
Thanks in advance
Since you probably need to configure username and password as well, I recommend creating separate application-mydatasource.properties files for each data source configuration. You will then activate the datasource you want to use based on setting the active profile. You can set the active profile either in application.properties (spring.profiles.active) or via a command line argument:
$ java -jar -Dspring.profiles.active=mydatasource demo-0.0.1-SNAPSHOT.jar
The application-mydatasource.properties will then override any properties in your application.properties. I believe you will also need to set spring.profiles= to the list of profiles available.
See Profile specific properties.
Another options besides the #Profile label, that you will have to declare in every enviroment that you will deploy the application, you could use in Spring Boot the label:
#ConditionalOnProperty(name="propertyName", havingValue="propertyValue")
And declare a property to decide wich database you want to load in each case!
Hope being helping!!

Create entity bean from existing Database through glassfish resource (connection pool)

I want to create an entity class from database. My database would be HSQL and i use file to store the data.
I have no problem to config the connection pool to connect to this database # glassfish The name of the resource which uses the connection pool (HSQL-file) is HSQLJdbcResource:
And no problem to reach this resource from a JSP file, this code works perfectly:
But i do have a problem, when i want to create the entity class from database with the netbeans wizard, because somehow the neatbeans can't find the driver for this :
I have the driver and attached to the project and also i can manage to create the entity class trough std datasource but i want trought glassfish resource, because if dont do the way like this --- the file will be locked because of my JPA which use glassfish resource and connection pool... Vicious Circle, is there any solution for this?
Please check to see if the driver path is correct.
Add the hsql driver in your system class path.
Also, this might be helpful: http://hsqldb.org/doc/guide/ch04.html

Best way to store Database configuration parameters?

I'm developing a web application at the moment. The web application needs to access a Patients database, which for now is a simple MySQL database but may likely be replaced by some other DB (or data source) in the future. At the moment, everything is hardcoded but I would like to have some way to configure the DB connection (that is, the database URL, user, password etc.).
What would be a simple and straightforward solution? It would be good if I could change the configuration by simple editing of a file.
I've seen there's the Properties API as well as Preferences. Or is there some idiom concerning servlets/web apps?
A servlet is part of a web app, and this web app is deployed in a Java EE container (Tomcat, WebLogic, etc.).
The standard way to get a database connection is to use JNDI to get a DataSource instance, and to ask a connection to this DataSource. The DataSource, most of the time, will pool database connections to avoid creating and closing too many connections and thus be much faster :
Context initCtx = new InitialContext();
DataSource dataSource = (DataSource) initCtx.lookup("java:comp/env/jdbc/MyDataSource");
Connection c = dataSource.getConnection();
try {
// ...
}
finally {
c.close(); // makes the connection available for a new thread
}
The DataSource will have to be declared in the web.xml file:
<resource-ref>
<description>Datasource example</description>
<res-ref-name>jdbc/MyDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
It will have to be defined (with its URL, number of connections, user, password, settings, etc.) inside your Java EE container. This is where it depends on your container.
Read the following explanations for Tomcat : http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html
I think a configuration XML along with your web application is a good idea. Each time the application is initiated by a new request the configuration is loaded and the database connection information available from any internal context that you make.
On IIS this is a standard way through the Web.config file.
regards

jboss username and password for login

How can, we know the jboss username and password for login
Under your JBoss application server directory, look for a file named:
conf/login-config.xml
There will be a block called:
<application-policy name="jmx-console">
... which will tell where your file-based username=password combinations are stored. I believe the default path is:
conf/props/jmx-console-users.properties
By default credential in Jboss is Given below
login: admin
password: admin
But if you use EAP these credential are turn off by default and there is no active user (security reasons :)). If you want to turn on these user you have to edit file in your current profile: ./deploy/management/console-mgr.sar/web-console.war/WEB-INF/classes/web-console-users.properties. It should be enough to remove # sign form the line with the user.
If you want to create new user don't forget to set up correct groups in
web-console-roles.properties file.
You can easly find information where these information are store. Just open the ./conf/login-config.xml file and find the proper security domain definition. In case of Web Console application it will be web-console policy.
or
in JBoss application server directory you have to look for a file named which is given below:
conf/login-config.xml
Inside this file search for application and go to below tags
<application-policy name="jmx-console">
which will tell where your file-based username=password combinations are stored. I think that default path is:
conf/props/jmx-console-users.properties
User: jboss
Password: passw0rd
If you are referring to JBoss' console user/password.