lunedì 20 maggio 2013

Error mounting ext3 partition: no journal found

After some power failures, I can't mount my HDD ext3 partition.
The kernel says:
EXT4-fs (sde1): mounting ext3 file system using the ext4 subsystem
EXT4-fs error (device sde1): ext4_iget:3889: inode #8: comm mount: bad extra_isize (33280 != 256)
EXT4-fs (sde1): no journal found 

The solution was to recreate the journal of ext33 partition (from http://www.watters.ws/mediawiki/index.php/Repair_ext3_journal_errors):

tune2fs -O ^has_journal /dev/sdXY

e2fsck -f /dev/sdXY

tune2fs -j /dev/sdXY 

domenica 17 febbraio 2013

IpadCharge on Fedora 18

If you installed with you ipad_charge and it dowsn't work, try to update che /etc/udev/95-ipad_charge.rules with the last one from https://github.com/mkorenkov/ipad_charge.

domenica 11 novembre 2012

Redeploy war in Tomcat 7 using curl and bash


 curl -T - -u user:password 'http://servername:8000/manager/text/deploy?update=true&path=/webapp' < webapp.war  

martedì 17 luglio 2012

Hardware reverse engineering - GSM Modem Da Sistemi MT0124

I bought this printed circuit board in an electronics fair. It contains a well documented GSM module by Telit and a handful of components for its powering and RS232 serial level converter (from CMOS level 2.8Volt to RS232 7.5Volt):

Even if the GSM module is well documented and even if the salesman assured me that I'd find the electric schema of circuit board on the Internet, I not found it, and I had to spend 10 hours to make the reverse engineering of pin out. 
This are the pin functions:
1. +Vcc (it works from 6 to 12 Volt)
2. bypass to RJ45 connector
3. Serial DCD (out from pcb)
4. Serial DTR (in)
5. Serial CTS (out)
6. Serial RTS (in)
7. Serial RX (out)
8. Serial TX (in)
9. Reset
10. ON/OFF (pull up, 1 sec to GND to switch on/off the GSM module)
11. bypass to RJ45 connector
12. GND



giovedì 7 giugno 2012

Get the Realm (or LoginService) instance from a ServletConxtext in Tomcat 7 and Jetty 7.5

Container-Managed Authentication is not always the best choose for implement security in web application. A typical example is when an home page have to be personalized if the current user is logged or not. With Container Managed Security, if a page isn't protected by a security-constraint, also if the current user is logged, the request.getUserPrinipal() is null.
See http://stackoverflow.com/questions/7795012/request-getuserprincipal-got-null.

A way to skip over the problem is to implement Application-Managed Authentication in web application. This means that web-app developer have to implements authentication/authorization.

But not everything is lost! We can reuse the Realm configured within application server to authenticate/authorize application's users.
There are two snippet of code that retrieve the Realm authenticator from ServletContext.

Get Tomcat 7 Realm from ServletContext:

 ApplicationContextFacade acf = (ApplicationContextFacade) servletContext;  
 Field privateField = ApplicationContextFacade.class.getDeclaredField("context");  
 privateField.setAccessible(true);  
 ApplicationContext appContext = (ApplicationContext) privateField.get(acf);  
 Field privateField2 = ApplicationContext.class.getDeclaredField("context");  
 privateField2.setAccessible(true);  
 StandardContext stdContext = (StandardContext) privateField2.get(appContext);  
 realm = stdContext.getRealm();  

The realm variable is an instance of org.apache.catalina.Realm, and you can call on this the authenticate method to authenticate and get roles of users:

 Principal principal = realm.authenticate(user, password);  
 if (principal == null)  
    return null;  
 GenericPrincipal genericPrincipal = (GenericPrincipal) principal;  
 return new DemoPrincipal(principal, genericPrincipal.getRoles());  


This is the counter part for Jetty 7.5. Be ware that normally Jetty don't allow to reach the container classes from web application class loader, we need to disable this option, see http://docs.codehaus.org/display/JETTY/Classloading.
 WebAppContext.Context context = ((org.eclipse.jetty.webapp.WebAppContext.Context) servletContext);  
 ContextHandler contextHandler = context.getContextHandler();  
 ConstraintSecurityHandler securityHandler = contextHandler  
       .getChildHandlerByClass(org.eclipse.jetty.security.ConstraintSecurityHandler.class);  
 loginService = securityHandler.getLoginService();  

 UserIdentity login = loginService.login(user, password);  
 if (login == null)  
     return null;  
 Principal principal = login.getUserPrincipal();  
 Field privateField = DefaultUserIdentity.class.getDeclaredField("_roles");  
 privateField.setAccessible(true);  
 String[] roles = (String[]) privateField.get(login);    
 return new DemoPrincipal(principal, roles);

I use Jetty with maven, this is may configuration:
 <plugin>  
      <groupId>org.mortbay.jetty</groupId>  
      <artifactId>jetty-maven-plugin</artifactId>  
      <version>${jetty.version}</version>  
      <configuration>  
           <loginServices>  
                <loginService implementation="org.eclipse.jetty.security.HashLoginService">  
                     <name>MyRealm</name>  
                     <config>${basedir}/src/main/resources/jetty-realm.properties</config>  
                </loginService>  
           </loginServices>  
           <scanIntervalSeconds>1000</scanIntervalSeconds>  
           <webAppConfig>  
                <serverClasses>  
                     <serverClass implementation="java.lang.String">  
                          -org.eclipse.jetty.  
                     </serverClass>  
                </serverClasses>  
           </webAppConfig>  
      </configuration>  
 </plugin>  

martedì 5 giugno 2012

Tell your browser to ask for save password in web AJAX login

Store password in browser is a useful functionality, the browser intercept the POST action of form and under a few condition (browser dependent) ask to store password.

Unfortunately, this mechanism don't works well when you implement a RIA (Rich Internet Application) and use AJAX call for authenticate users because your submit through XHR and not by html form submit.

I use a simple trick to show password store request from browser. After the AJAX login request complete, if the user is successful authenticate, submit the login form to a url that return a HTTP 204 status (204 NO CONTENT). The browser ask to save password but the user does not navigate anywhere else.

This is an example:

         <form method="post" action="http://demo.utilities-online.info/backend/none">  
           Username: <input id="username" type="text" name="username"><br/>  
           Password: <input id="password" type="password" name="password"><br/>  
           <input type="button" value="login" onclick="sendRequest();">  
         </form>  

try now!

Username:
Password:


Enjoy with AJAX!

giovedì 8 marzo 2012

BIRT segmentation fault on linux

I'm running BIRT in my box and experienced, several times, code dump of JVM with segmentation fault.
A problem go away when I added some options of JVM:
-Xss256k -XX:MaxPermSize=384m

Software version:
Fedora 16
JVM 1.7.0_03
Tomcat 17.0.25
BIRT 3.7.1