Basic HTTP Authentication in JBoss AS 7

February 17th, 2012 FighterHayabusa No comments

I’ve started playing around with the new and improved JBoss AS 7 lately. It’s really quite nice. I haven’t had a great deal of experience with the older versions but as I understand it it’s quite different from before. It’s really rich on great features and very snappy. I’d recommend anyone that does Java EE development to check it out.

That it’s new and different might also explain why it was so frackin’ hard to find the proper way to set up Basic HTTP Authentication for a web application in JBoss AS 7. Not even the official documentation seems entirely updated (or maybe I just didn’t have the patience to read the docs thoroughly..) so I spent a great deal of time searching the web and piecing together little bits here and there before I finally reached a solution.

First I had to add a security domain to the configuration-file standalone.xml like this:

<?xml version='1.0' encoding='UTF-8'?>
<server name="myserver" xmlns="urn:jboss:domain:1.0">
...
<subsystem xmlns="urn:jboss:domain:security:1.0">
<security-domains>
<security-domain name="mysecuritydomain">
<authentication>
<login-module code="UsersRoles" flag="required">
<module-option name="usersProperties" value="${jboss.server.config.dir}/users.properties"/>
<module-option name="rolesProperties" value="${jboss.server.config.dir}/roles.properties"/>
</login-module>
</authentication>
</security-domain>
</security-domains>
</subsystem>
...
</server>

Then I had to create the files referenced in the module-options above and place them in the appropriate directory – in my case the same directory as the standalone.xml-file. The contents of these files should look something like this:

users.properties:

myuser1=mypass1
myuser2=mypass2

roles.properties:

myuser1=user,admin
myuser2=user

The next step was specifying my security domain in the file jboss-web.xml and putting it in the WEB-INF-directory of my web app:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<security-domain>mysecuritydomain</security-domain>
</jboss-web>

Finally the following was added to my web.xml (also in the WEB-INF-directory):

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
...
<security-constraint>
<web-resource-collection>
<web-resource-name>MyResourceName</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>qvuser</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>My kinda secure web application</realm-name>
</login-config>
<security-role>
<description>Role for simple users</description>
<role-name>user</role-name>
</security-role>
<security-role>
<description>Role for administrators</description>
<role-name>admin</role-name>
</security-role>
...
</web-app>

Now when I access my web app I’m prompted with the very familiar type of window asking me for a username and a password. All done!

Numbing the pain of VBScript with a generic logging-class

October 18th, 2011 FighterHayabusa No comments

VBScript is a pain the ass. However when working on Windows I’ve found it useful plenty of times since it’s the only scripting language supported out of the box by most Windows-flavors (although that’s changed now with PowerShell I suppose). There’s also the whole VBA-thing which crosses over into VBScript-territory in various applications. QlikView for example uses VBScript as an internal scripting language for macros and exposes a VBA-esque API for that purpose.

Anyway, the other day at work while hacking away at a humongous VBScript/VBA-macro I got tired of how much debugging my 600+ lines of VBScript-code sucked (mainly because of QlikView’s useless debugger) and threw together a simple generic logging-class that I thought I’d share. So here you go:

Class Logger

Private mLogFile
Private EFSO
Private EFP
Private mIsEnabled

Private Sub Class_Initialize()
'Do nothing
End Sub

Private Sub Class_Terminate()
If IsObject(EFP) AND TypeName(EFP) = "TextStream" Then
EFP.Close
End If
Set EFP = Nothing
Set EFSO = Nothing
End Sub

Public Default Function Init(pLogFile)
mLogFile = pLogFile
mIsEnabled = True
Call InitFileObjects
Set Init = Me
End Function

Private Sub InitFileObjects
If IsObject(EFP) AND TypeName(EFP) = "TextStream" Then
EFP.Close
End If
Set EFSO = CreateObject("Scripting.FileSystemObject")
Set EFP = EFSO.OpenTextFile(mLogFile, 8, True)
End Sub

Public Property Get logFile
logFile = mLogFile
End Property

Public Property Let logFile(pLogFile)
mLogFile = pLogFile
Call InitFileObjects
End Property

Public Property Get IsEnabled
IsEnabled = mIsEnabled
End Property

Public Property Let IsEnabled(pIsEnabled)
mIsEnabled = pIsEnabled
End Property

Public Sub doLog(pMessage)
If (mIsEnabled = True) Then
EFP.WriteLine(pMessage)
End If
End Sub

End Class

Not the hottest piece of code you’ll ever see but maybe somebody besides me will find it useful.

Simple iTunes “what’s playing?”-server with AppleScript and netcat

May 28th, 2011 FighterHayabusa No comments

I run a computer setup at home where I have a Linux-PC and a MacMini sharing a screen, keyboard, mouse and speakers through a KVM-switch. This particular switch has the neat feature that you can switch over everything except the speakers if you like. So I can be rocking the iTunes on the Mac while I’m burning through some code in Eclipse on the Linux-PC for example. Pretty useful since I keep almost all my digital music in iTunes on the Mac and do most of my coding and hardcore geeking on the Linux-box. The only problem is that if I wanna check what’s playing currently I have to switch the screen over to the Mac to see the track playing in iTunes. Well, I made a quick hack to solve this “problem”.

Netcat is a really useful tool for testing various network related things and it can also be used to set up a simple client-server connection. So I thought I could use it to push information from the Mac over to the Linux-PC without too much hassle, and I was correct. Combined with some AppleScript that reads the information about the song playing from iTunes I quickly had a “server” that would answer client-requests for this information. Here’s the code:

AppleScript (compiled and saved as itunescurrent.scpt):
tell application "iTunes"
try
if not (exists current track) then return
set this_artist to (get artist of current track)
set this_track to (get name of current track)
set this_album to (get album of current track)
end try
end tell
try
set track_info to this_artist & " - " & this_track & " (" & this_album & ")"
return track_info
on error err
display dialog err
end try

Server-script using netcat (saved as itunescurrent-server.sh):
#!/bin/bash
SERVERPORT=4321
while [ 1 ]; do
osascript itunescurrent.scpt | nc -l $SERVERPORT
done
exit 0

So I put those two files in the same directory, navigated there in a command prompt window and executed the server-script. What the server does then is simply hang in an infinite loop waiting for a client to request information from it.

The script running as the client is just as simple:

#!/bin/bash
SERVERIP=192.168.1.108
SERVERPORT=4321
CURRENTTRACK=""
ITUNESINFO=""
while [ 1 ]; do
ITUNESINFO=`nc $SERVERIP $SERVERPORT`
if [ "$ITUNESINFO" != "$CURRENTTRACK" ] ; then
clear
CURRENTTRACK=$ITUNESINFO
echo $CURRENTTRACK
fi
sleep 5
done
exit 0

I think it’s pretty self-explanatory.

So now I can read what’s playing on my Mac in a terminal window on my Linux-PC instead of having to waste precious seconds switching back and forth and checking iTunes. Problem solved! And anyone who wants to can grab the code from the Downloads-page.

Vilken nytta gjorde FRA i lördags?

December 15th, 2010 FighterHayabusa No comments

Jag tycker att det är intressant att mitt i allt detta ståhej om den klantiga bombmannen i Stockholm är det ingen som ifrågasätter varför detta dåd inte kunde förutspås och förhindras av övervakande instanser som FRA eller Säpo? Var det inte just sånt här som FRAs snokande i hela Sveriges befolknings privatliv skulle förhindra? Är inte detta ett utmärkt tillfälle att ta upp debatten igen, utvärdera och (förhoppningsvis) tänka om? Det enda FRA verkar göra bra är att leverera privata uppgifter om oss till USA och det var väl ändå inte det som sades vara dess uppgift va?

Inte heller är det speciellt många som lägger ihop ett och ett och listar ut att en stor anledning till att Sverige nu är ett lockande mål för de av media kallade islamistiska extremisterna är att den svenska regeringen sitter i fickan på USA – det USA som hejdlöst krigar i åtskilliga muslimska nationer och skänker stöd i miljardklassen till Israel – och tar order från Vita Huset och amerikanska ekonomiska intressen istället för att tjäna befolkningen i landet de påstås regera i.

Det finns inga ursäkter eller förlåtande omständigheter för terrordåd och de begås enbart av fullständiga galningar men det är ändå hög tid att fler börjar följa sambanden och pekar ett anklagande finger på nickedockorna och förrädarna i vår regering och riksdag, för de är inte oskyldiga de heller. De är i alla fall oändligt mycket mer skyldiga än alla de fullständigt oskyldiga muslimer boendes i Sverige som av mindre vettiga personer nu kommer att betraktas som potentiella terrorister och beskyllas för både det ena och det andra.

Låt er inte sköljas med i den rasistiska och islamofobiska vågen som spolar igenom Sverige. Dra inte alla över en kam. Och låt inte kräken som försöker montera ner demokratin inifrån vinna poäng på det här.

To all citizens of the EU, sign this now!

October 7th, 2010 FighterHayabusa No comments

Say NO to internet censorship and pointless blocking of child pornography websites and at the same time YES to striking at child pornography in a way that actually works!

Deletion, not blocking!

Go here now and sign the petition: http://www.deletion-not-blocking.eu/sign.html

It’s Bacon Day! Meal three: Dinner

September 4th, 2010 FighterHayabusa No comments

For dinner I decided on a bacon burger, always a delicious choice. But for extra deliciousness I slapped on an extra meat patty, cheese and some fried red onions.

Once again, bacon frying

Once again, bacon frying

Frying the red onions

Frying the red onions

Meat! Gooood!

Meat! Gooood!

The finished bacon burger in all its glory

The finished bacon burger in all its glory

It’s Bacon Day! Meal two: Lunch

September 4th, 2010 FighterHayabusa No comments

The bacon feast continues. For lunch I made a nice chicken salad with cherry tomatoes, cucumber, corn, maché salad, grilled chicken, mushrooms and, of course, bacon.

Lovely bacon frying

Lovely bacon frying

The salad before adding the bacon

The salad before adding the bacon

Bacon added

Bacon added

Nom nom nom

Nom nom nom

Praise the divine bacon! See y’all back for dinner!

Categories: Posts in English Tags: , , ,

It’s Bacon Day! Meal one: Breakfast

September 4th, 2010 FighterHayabusa No comments

To celebrate that’s it’s Bacon Day today I’ve decided to include bacon in all of my meals of the day. First out: breakfast!

For breakfast my girlfriend requested pancakes, so pancakes it is but I decided to stuff mine with cheese, arugula and bacon.

Check out the pictures!

Making the pancakes

Making the pancakes

The delicious bacon

The delicious bacon

Soon the feast will be ready...

Soon the feast will be ready...

Bacon stuffed pancakes, ready to eat!

Bacon stuffed pancakes, ready to eat!

Eating the pancakes

Eating the pancakes

And yes, it was absolutely delicious! See you in a couple of hours for lunch. With bacon!

The most boring video you’ll ever see

August 2nd, 2010 FighterHayabusa 1 comment

Don’t say I didn’t warn you… ;-)

To anyone who actually gives a hoot, that’s my HTC Hero receiving the officially sanctioned Eclair-update from HTC (rather than the hacked HTC Legend Eclair ROM I’ve been running the past couple of months).

Time for Android to step up its game

July 21st, 2010 FighterHayabusa No comments

The past couple of weeks I’ve been playing with mobile apps development, both for Android and for iOS (meaning iPhone and iPad in layman’s terms). Being an open source kinda guy and very familiar with Java I immediately felt very comfortable with the Android SDK and the platform as a whole. It really is a great platform and very viable for creating great apps and experiences for mobile devices. However, there are a couple of key issues that I believe need to be fixed in order to push Android to the next level.android-robot-logo

First and foremost, paid apps are still not available everywhere. Only users in a few select countries can download apps from Android Market that cost money and, even worse, developers in even fewer countries can publish non-free apps for people to buy. As a mere users there are ways around this but if you’re – like me – a Swedish developer there’s no way to get paid for your efforts. This is a really big deal since developers outside of the nine supported merchant countries also need to eat and pay the bills or whatever it is you use money for. Sure, one might claim that true hardcore developers will develop awesome apps anyway and give them away on Android Market because digital creativity is in our nature and this is true to some extent. But at the end of the day money is one of the best incentives out there and the fact that many potential Android developers can’t charge for their apps is most surely causing a lot of app-awesomeness from happening and keeping the platform from experiencing the kind of “gold-rush” that iOS is having.  It may even be driving some developers to the iOS-platform instead since they might reckon that if they can’t paid why should they bother with the platform anyway?

I don’t see what the frackin’ hold-up is here really. So Google, get off your asses and make this happen sooner than later. Market needs to have paid apps and developers getting paid everywhere, OK?

Another thing that is painfully obvious when you look at the variety of Android devices out there is that the hardware companies that sell them, companies like HTC, SonyEricsson and Samsung, care only about selling new devices. They have very little interest in delivering software updates for devices that customers have already bought. I mean, it took HTC a full year to push out an OS-upgrade for the HTC Hero and SonyEricsson is at this moment selling Android 1.6 devices with the plan to update them to 2.1 around New Year. Meanwhile, FroYo (Android 2.2) devices are starting to hit the market and the specs for 3.0 are already out there.

I fully understand that it may not be easy for these companies that are primarily manufacturers of hardware to wrap their business models and brains around the fact that these days, with mobile phones becoming more and more like “real” computers, software matters more than hardware. A mobile phone will become obsolete a lot faster due to an old OS than due to year-old hardware. So something needs to be done about this. HTC and others need to take care of their customers and push out the updates a lot quicker because not everybody wants to (or can) buy a new $500 mobile phone every three months just to get the latest software. Maybe Google should set up some sort of centralized repository that the makers of Android phones could use to make sure they’re all in sync with each other and with what’s new? I don’t know, but something should be done to keep the platform from fragmenting any further.

And finally one other thing that I think can be a real game-changer is Flash-support. Yes, there is Flash-support in FroYo, I haven’t experienced it first-hand myself though so I don’t know how well it works. But my point here is that since Apple is taking a serious stand against Flash on devices running iOS there is a chance for Android (and Adobe naturally) to shine here. Make Flash work flawlessly on all contemporary Android devices and you will have a feature on the platform that the main competition can’t and will not match, which naturally is a great advantage.

These are the major points that bother me at the moment and I believe them all to be more or less critical for the growth of Android. I want to underline here though that although there are flaws – every platform has them – I believe a great deal in Android and will continue to submerge myself in the platform with great joy.

So Google and everybody else involved, time to step it up a notch OK? I’ll be watching you ;-)