[Security & JAAS/JBoss] - Issue in encrypting the password using MD5
by Tony Jim
I am using JBoss 4.2.2GA application server with Struts and EJB.
I am trying to encrypt the password using the message digest - MD5(given below) and store it in the mysql DB.
Using DatabaseServerLoginModule, I am trying to authenticate, but it's failing. Please help on this.
Please help whether any configuration setting needs to be done.
login.config.xml
==================
| <application-policy name="testDB">
| <authentication>
| <login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule"
| flag="required">
|
| <module-option name="hashAlgorithm">MD5</module-option>
| <module-option name="hashEncoding">base64</module-option>
| <module-option name="hashUserPassword">true</module-option>
| <module-option name="hashStorePassword">true</module-option>
|
| <module-option name="dsJndiName">java:/MySqlDS</module-option>
| <module-option name="principalsQuery">
| select passwd from Users username where username=?</module-option>
| <module-option name="rolesQuery">
| select userRoles, 'Roles' from UserRoles where username=?</module-option>
| </login-module>
| </authentication>
| </application-policy>
|
I am using the below program to encrypt the password using MD5 and storing the encrypted value "5f4dcc3b5aa765d61d8327deb882cf99" in mysql table
| import java.security.MessageDigest;
| import java.security.NoSuchAlgorithmException;
|
| public class MainClass {
| public static void main(String args[]) throws Exception {
| String sessionid = "password";
| byte[] defaultBytes = sessionid.getBytes();
| System.out.println("defaultBytes ::"+defaultBytes);
| try{
| MessageDigest algorithm = MessageDigest.getInstance("MD5");
| algorithm.reset();
| algorithm.update(defaultBytes);
| byte messageDigest[] = algorithm.digest();
|
| StringBuffer hexString = new StringBuffer();
| for (int i=0;i<messageDigest.length;i++) {
| hexString.append(Integer.toHexString(0xFF & messageDigest));
| }
| String foo = messageDigest.toString();
| System.out.println("sessionid "+sessionid+" md5 version is "+hexString.toString());
| System.out.println("foo "+foo);
| sessionid=hexString+"";
| }catch(NoSuchAlgorithmException nsae){
|
| }
| }
| }
|
| output:
| -------
| defaultBytes ::[B@192d342
| sessionid password md5 version is 5f4dcc3b5aa765d61d8327deb882cf99
| foo [B@167d940
|
my mysql tables
| mysql> select * from userroles;
| +----------+-----------+
| | username | userRoles |
| +----------+-----------+
| | ram | admin |
| | sachin | guest |
| | tiger | admin |
| +----------+-----------+
| 3 rows in set (0.14 sec)
|
| mysql> select * from users;
| +----------+----------------------------------+
| | username | passwd |
| +----------+----------------------------------+
| | ram | passwd |
| | sachin | passwd |
| | tiger | 5f4dcc3b5aa765d61d8327deb882cf99 |
| +----------+----------------------------------+
| 3 rows in set (0.17 sec)
|
Geting the error message:
| 19:51:29,212 DEBUG [DatabaseServerLoginModule] Bad password for username=tiger
|
web.xml
==========
| <security-constraint>
| <web-resource-collection>
| <web-resource-name>Testing</web-resource-name>
| <url-pattern>/*</url-pattern>
| <http-method>GET</http-method>
| <http-method>POST</http-method>
| </web-resource-collection>
|
| <auth-constraint>
| <role-name>admin</role-name>
| </auth-constraint>
|
| <user-data-constraint>
| <transport-guarantee>CONFIDENTIAL</transport-guarantee>
| </user-data-constraint>
|
| </security-constraint>
|
| <login-config>
| <auth-method>FORM</auth-method>
| <form-login-config>
| <form-login-page>/login.jsp</form-login-page>
| <form-error-page>/error.jsp</form-error-page>
| </form-login-config>
| </login-config>
|
| <security-role>
| <role-name>admin</role-name>
| </security-role>
|
But for the userid: ram and passwd, I am able to login. Whereas for the user "tiger" with the encrypted password, I couldn't able to login.
Please throw some light on it. Please help to check the configuration in login-config.xml
And I have an another doubt. If the user is attempting to enter invalid password for more than 5 times, we need to lock his account.
Whether JBoss' DatabaseServerLoginModule or any other loginmodule is providing this functionality? If not, how to achieve?]
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4229602#4229602
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4229602
17 years, 1 month
[Beginners Corner] - How to create DataSource dynamically in jboss
by psivaji
Hi,
Could anyone have idea about creating datasource dynamically in jboss?
I tried to use the LocalTxDataSource, but it is getting NullPointerException when it tries to get the TranscationManager.
Here is the code for reference,
Properties initialContextProperties = new Properties();
initialContextProperties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
initialContextProperties.put("java.naming.provider.url", "jnp://localhost:1099/");
LocalTxDataSource localDataSource = new LocalTxDataSource();
CachedConnectionManagerReference ccmr = new CachedConnectionManagerReference();
localDataSource.setInitialContextProperties(initialContextProperties);
localDataSource.setConnectionURL(connectionURL);
localDataSource.setDriverClass(driverClass);
localDataSource.setUserName(userName);
localDataSource.setPassword(password);
localDataSource.setMinSize(minSize);
localDataSource.setMaxSize(maxSize);
localDataSource.setJndiName(dsName);
localDataSource.setNewConnectionSQL(query);
localDataSource.setValidConnectionCheckerClassName("org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker");
localDataSource.setCheckValidConnectionSQL(query);
localDataSource.setTransactionIsolation("TRANSACTION_READ_COMMITTED");
try {
InitialContext ctx = new InitialContext(initialContextProperties);
localDataSource.setCachedConnectionManager(ccmr);
//localDataSource.bindConnectionFactory();
localDataSource.start();
DataSource ds = (DataSource)ctx.lookup(dsName);
logger.debug("DSConfigureScheduler::ds: "+ds);
con = ds.getConnection(); //It fails here
Thanks,
Pugazhenthi.S
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4229596#4229596
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4229596
17 years, 1 month
[JBoss Messaging] - Re: about transaction and order
by the.finder
In my case, I need to process message by order, so I create a Session Bean (Processor) to do that, the code is like following:
| @TransactionAttribute(TransactionAttributeType.REQUIRED)
| public boolean process() throws BusinessException {
| try {
| Message message = poll();
| if (message != null) {
| handle(message);
| return true;
| }
| } catch (Exception e) {
| logger.error("error", e);
| throw new BusinessException(e);
| }
| return false;
| }
|
in the function poll(), I just create a MessageConsumer and call receive().
In another job, call this session bean like this:
| processor.open();
| try {
| while (processor.process())
| ;
| } finally {
| processor.close();
| }
|
and in open() function, i create connection and session, and in close() function i close them.
In my test, first put 10 messages into the queue, and the 5th will throw a exception in process.
I found strange problems:
1. messages after the 5th one was processed, i.e. some of 6, 7, 8, 9, 10 was processed
2. there are 2 messages left, one is the 5th, another is any of 6, 7, 8, 9, 10
How to explain these?
And how to receive 1, 2, 3, 4, and then blocked.
My version jboss-messaging-1.4.2.GA-SP1.
The following is the code to send message:
| Connection connection = factory.createConnection();
| Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
| MessageProducer pub = session.createProducer(topic);
| ObjectMessage msg = session.createObjectMessage();
| msg.setObject(cmd);
| pub.send(msg);
| pub.close();
| session.close();
| connection.close();
|
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4229593#4229593
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4229593
17 years, 1 month