Zombie apocalypse board game? Hell yes! I’m in!
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!
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.
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.
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.
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!
Go here now and sign the petition: http://www.deletion-not-blocking.eu/sign.html
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.
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.
Praise the divine bacon! See y’all back for dinner!
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!
And yes, it was absolutely delicious! See you in a couple of hours for lunch. With bacon!
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).