Monday, November 22, 2010

Listing Sub-Pages on your Page in WordPress

I know I'm a WP noob, but this took me about an hour to figure out. Maybe I can save someone else some time.

Most of the code below comes from the WordPress docs, but there was one critical piece missing, $post->ID was returning nothing, even though I was in "the loop". I got around that whole thing once I learned that you can get the page id with get_the_ID().

<?php
// display only this page's children
$my_id = get_the_ID();
$subpages = wp_list_pages("title_li=&echo=0&depth=1&child_of=".$my_id);

if ($subpages) { ?>
<h2>Sub-topics</h2>
<ul>
<?php echo $subpages; ?>
</ul>         
<?php } ?>

I am using WordPress 3.0.1, if that helps anyone.

Wednesday, October 6, 2010

Product Sashimi is delicious!

On Saturday I participated in a Product Sashimi workshop with J. B. Rainsberger and Bonnie Aumann.

This workshop was all about learning how to "slice a product thinly" so that you can actually ship something of value quickly. We also spent a lot of time working on how to help turn a fuzzy customer product idea into something concrete that you can start to work on. I summarized it to my team like this: You customer comes in and they are usually asking for a whale. At the end of the project what they really wanted was a crab. Your job is to start from their request for a whale and 1) trim the whale down to the meaty parts they really want/need and 2) slice that meaty part thinly so that you can actually start development and deliver value soon.

I happen to work in an academic environment where my customers are colleagues with ideas for software and tools that will help their research or will be used internally for staff. No money actually changes hands for each project, but my team is a scarce resource and we have a lot of projects to handle, more than we can actually deliver. It's not that different from when I was a consultant with paying customers who need the maximum solution at minimum cost and they need it yesterday. You always want to get to delivering value as soon as possible, which means slicing the problem thinly, and you want to make sure that you know you are working on the most valuable things first, which means understanding their business and their needs.

The biggest challenge is understanding what the customer is asking for. Often times they struggle to put it in to words. Sometimes they can describe the solution they are looking for, but it doesn't match the problem they are describing. As knowledgable tech resources we immediately want to get to the meat of what they want, so our first question is "why do you want that?". A great reminder that J.B. and Bonnie kept mentioning is to consider how what you say sounds to the customer. Have you ever had an exchange like this:

Customer: I want an X. Can you make that for me?


Dev: Why do you want X?


Customer: What do you mean, 'why do I want that'?!

Depending on your tone and your relationship with your customer it can sound like you are questioning their own judgement of their needs, when in fact you are really just trying to understand their needs better. J.B. Gave a lot of great examples for what you can say instead. I won't give them all away, but one of my two favorite takeaways from the workshop was the Magic Wand technique.

Customer: I want an X. Can you make that for me?


Dev: Okay, (using imaginary magic wand) TADA! You have an X. Tell me a little about how you are going to use it.


Customer: Well...

This is going to go much better than the example above. It takes a lot of practice to get good at posing those questions.

My second favorite technique is the Lost Luggage Technique. Have you ever been the last one waiting for your bag to arrive on the luggage belt at the airport and then the belt shut off? So you go to the little room and tell them your bag is missing. Usually they will hand you a laminated sheet with pictures of suicases on it and ask you "which one of these does your bag most closely resemble?" followed by "How does your bag differ from the one in the picture?". This is a great technique because it grounds the conversation in something concrete and focuses both of your attention on the ways in which your understandings of the object in question differ.

For example, the customer describes what they want. It sounds a lot like a blog to you. So you say, "What if I give you a WordPress blog? What more do you think you need?"
and then listen to what they say. Oh, and write it down. Maybe they don't know everything a blog is capable of, so you might share that with them and check again. At this point it is all about listening, and keeping the conversation grounded in concrete terms as much as possible.

As you are listening and writing down what you are learning this is when the sashimi slicing begins. First you want to want to figure out the scope of this
You have to identify the simplest most barebones solution that could possibly fit the description of what the customer needs and then build out from there to find a simple solution that you can actually deliver. As J.B. put it succinctly, the goal is to learn what you don't have to do and try not to do it.

Once you have cut down the big fuzzy product description into a smaller fleshy piece now the slicing begins. In the training we went over techniques for identifying the major problem areas (maybe 4-8 of them) and then breaking those down in to features and then generating scenarios for those features.

I just gave my team a recap of some of the things that I learned at the sashimi workshop and it started a great discussion about how we are doing in understanding our customers' needs, how to define what is good enough (if you and your customer are both happy could you still not be done?) and even a quasi-role-playing session with our boss as the customer for a real request that had just come up. I am going to need a lot of practice asking those gently leading questions like "Tell me more about how you'd like to use that" and "I'm curious how you came up with the idea of a X".

When we got out of the meeting another one of our internal customers came over with a real request and we decided to see if we could use our new skills to help us learn more about what she is asking for. They ended up beating her with imaginary magic wands, but at least they didn't start off with "Why do you want that"!?!

I did successfully apply the lost luggage technique earlier this week. It's such a simple technique. I found myself with another developer and a customer and we were all talking in abstract terms about a report that she wanted. So, I drew a picture and I said "What if this was the report? would that meet your needs?" and the conversation became much more productive after that. A lot of practice is definintly needed, but I feel like I'm already getting value out of these techniques. I really wish this workshop was a month long so that I could soak up and really practice all of the things that Bonnie and J.B. were sharing with us.

Wednesday, August 25, 2010

Agile Philly Code Kata Night August: Architectural Katas

Thank you to Andre, Bonnie, Adam, Aaron and Sebastian for coming out to Code Kata night at the Math Forum! This was an experimental kata night in that we were trying out architectural katas for the first time.


In the beginning we went through a summary of the basic elements of architecture: communication/distribution, presentation/interaction, state management, processing, resource management and tools. For this we followed the slides that Ted Neward provided especially for this event and exercise. The idea is, roughly, that when you are designing the architecture of a system you have to consider each of these elements. I think we can all agree that one way or another requirements inform your technological choices. Asking questions about the system with regard to each of these elements can make it more likely that you don't miss support for a critical aspect of the system. Here are a few examples:


  • Communication/Distribution: In what format does data travel? JSON? XML? Over what medium? http? filesystem?
  • Presentation: What sort of perspectives in to the system do you need? do you need an admin console?
  • State Management: Does the state need to be persisted across different sessions?
  • Processing: Does processing need to be transactional?

Then we made two groups, each randomly selected a kata and spent 25 minutes trying to come up with a suitable architecture to meet the requirements. At the end of the time each group presented their proposal for 3 minutes and fielded 2 minutes of Q and A from me and the other group. I played the role of the customer/game master, answering clarifyng questions about the



I think it is fair to say that these exercises were hard. One of the exercises was to build a MMORPG. None of us had any experience building similar systems, so there were a lot of open questions about what was possible and how it could be done. I was probably not the best customer for this project either, since I have hardly seen a MMORPG before, let alone thought about how I would want one to work. Even if you are familiar with the domain and know about some of the relevant technology, it is still hard to cover all of the architectural bases in 25 minutes.



In the retrospective that followed the question came up, what are these exercises good for? Would this exercise really be valuable to the customer? Andre voiced his skepticism of architecture as a subject because that is not how he would ever work with a customer. As agile-minded folks, we prefer to see the architecture emerge as you are iterating and building the system with your customer. I don't think these exercises are really intended as practice for starting a project with a customer, although I may have set that up by calling myself the customer at the beginning of the exercise and saying that I would decide if I wanted to buy the system at the end. I like these exercises because it is an opportunity to wonder about how things work, and it piques my curiosity to go learn about technology that I haven't had a chance to use at work before (or yet?).



One benefit that we saw of these exercises is that they could get the whole team involved in design. Sebastian told us that his team actually does something similar on a regular basis. Pairs will take a card off the wall, think about how they are going to do it and "pre-sell" the approach to at least on the other pair (more for major changes). When the story is done they can present the result and the rest of the team has a chance to say "hey--that's not what you sold me!" which can help to reveal what the pair learned while they were building it. We also discussed ways of displaying architecture or the state of the system in the team area. One idea was modular printouts on the wall, legos or knex. All of these could be kept up to date as things changed. Sebastian once used the printouts as a progress chart, checking off parts of the system as they were completed.



All in all this was a fun kata night and I look forward to the next one. Many thanks to Ted Neward of Neward & Associates http://tedneward.com for letting us use his slides and architectural katas for our kata night.

Thursday, May 20, 2010

Setting up Alfresco 3.3 Community Edition Standalone Deployment Receiver for WCM

I'm trying out the latest edition of the Alfresco content management system community edition. This is a free, open-source content management system that can do both document and web content management (and much more). What my company wants to use it for is web content management (managing html, php, css, images etc. for our many websites).

We like open source software so we are trying to use the completely unsupported, not guaranteed OS version instead of the fully supported and tested enterprise version. Without support or thorough documentation I am on my own (with the help of generous community members) to get this thing installed, configured and up and running and to keep it that way.

One aspect of getting this project off the ground that was especially tricky was getting a Standalone Deployment Receiver working so that I could deploy content (again, html files, css, php) from my Alfresco repository on one machine to a folder on my web server. Here is how I did it:

Before I started I already had a Web Project in alfresco with some dummy content in it (index.html, and a directory with another html file in it).
  1. Downloaded Linux Installer for Standalone Deployment Receiver, Alfresco-DeploymentCommunity-3.3-Linux-x86-Install, from http://wiki.alfresco.com/wiki/Community_Edition_file_list_3.3
  2. Ran the installer (requires gui environment, expects to be able to pop up a window to walk you through installation)
  3. Accepted all defaults, including port numbers
  4. Started it up(start.sh)

Then I went to my web project in alfresco, and edited the web project settings and added a deployment receiver.  (My Web Project -> Actions -> Edit Web Project Settings -> Next -> Add Deployment Receiver) I added my remote machine as a test server.

Then I should be able to click My Sandbox -> More Actions -> Deploy, choose my test server and the content as it exists in my sandbox should be copied over to the remote server, but it didn't work.


Could not connect to remote service [rmi://144.118.94.157:44100/deployment]; nested exception is java.rmi.ConnectException: Connection refused to host: 127.0.1.1; nested exception is: java.net.ConnectException: Connection refused

I did some googling around and found several people mention that you need to do two things: add a setting to JAVA_OPTS for your alfresco tomcat and set up /etc/hosts in a certain way. I tried a bunch of different things that were suggested, but here is what I did that actually resulted in a successful deployment:

1. Made sure that my remote server had the 44100 port open
2. Made sure the deployment receiver was running on my remote server
3. Added to catalina.sh (/tomcat/bin/catalina.sh) the following line near the top before the first time JAVA_OPTS is used:

JAVA_OPTS="$JAVA_OPTS -Djava.rmi.server.hostname=144.118.68.94"

4. Modify /etc/hosts on the alfresco server to include a mapping from its IP address to the domain name like this:

xxx.xxx.xx.xx mydomainname.com

xxx.xxx.xx.xx is not my real IP address, obviously. On the remote server I did the same thing, mapping its IP to its domain name and mapping the alfresco server's IP to the alfresco server domain name, although I'm not sure that was necessary.

5. Restarted alfresco and the remote server (and started the FSR on the remote server again)

Finally! I am able to deploy snapshots from my sandbox to a test server. By repeating the process and setting the second machine as a "Live Server" in the web project settings I am able to deploy snapshots of approved committed content from all users to another remote server. On the remote servers you can do whatever you want, like deploy your web content to a directory that an apache instance serves up and voila! you have a website.

FYI, here are some of the sources I used to piece together this soution:

Thursday, April 15, 2010

Influencing Your Way to Agile

I recently presented at the Emerging Technologies for the Enterprise conference in Philadelphia.

Speaking at ETE

It was a fantastic conference, as always with the folks from Chariot Solutions. I had a great crowd even though I was in the last slot of the last day of the conference. For all of you that couldn't make it (and those of you who did and wanted my slides) I thought I'd write up my thoughts on influencing your way to Agile.

I love Philly ETE because of the community and the amazing speakers and all of the focus on new technologies, emerging practices and practical tips and tools—things that are relevant to the work that I do everyday that I can take back with me.

But how often do you really bring those ideas back to your organization and change things?

I'm not saying it doesn't happen—I have brought back some valuable tips and definitely picked up new technologies, but especially the ideas that involve changing the behavior, actions, opinions of others—maybe Uncle Bob sufficiently shamed you into deciding that you and your team needs to actually practice TDD—so many ideas like that fizzle out before they ever have a chance to become reality.

What inspired me to study influence is the patterns that I saw over and over again: You're in a company on a team. You have your job; you depend on some people and some people depend on you. There are some norms for how things get done, for how people interact and communicate. As an individual and an organization you sometimes fail and sometimes succeed at what you do. Love it or hate it but if you care at all about what you do and your organization (or the people in it) you see some room for improvement. So, you come up with an idea.

The goal is usually to take your idea and get to the point where you can give it a try so that you have a shot at turning it in to reality and making a positive change in your world.

But how do you get there? For most non trivial changes you have to get some others on board before you can turn your great idea in to reality. So between the time that you have a great idea and you give it a try you have to go and talk to them, convince them to go along with it.

What really bothers me is all too often you get stuck at these in between points before you even to give it a try. And what happens is that over time when you hear "no" often enough you often start to give up before you even try.

So many ideas, so much energy gets lost (wasted) because we don't know how to communicate our ideas and we don't have the relationships and skills we need in order to be able to successfully influence each other when a great idea does come along.

I know I titled my talk “influencing your way to agile” but I’m not really here to talk about agile. Agile is a mindset--a conscious decision to accept change and adapt the way we work to accommodate constantly changing requirements. In my mind a commitment to agile is also a commitment to discipline and continuous improvement. I’m not strict in my observance of agile practices--Agile techniques are just more tools in my toolbox, but I do buy into the core principles of transparency, collaboration, responsiveness, getting things done. They just seem like good ideas.

Most developers that I meet are either on a team that is trying to "be more agile" because of some pain or frustration with their current way of working or is already "sort of agile" and dealing with the same or new pains and frustrations with the way they work.

Regardless, I don't know if I've ever met anyone that has said "yeah, everything about the way my project/organization/community is perfect--nothing needs to change“

It doesn't matter if you are a developer or a team leader or an executive--I hear the same sort of thing--everyone has frustrations, sees opportunities for improvement, occasionally comes up with new ideas. Everyone is dealing with change and the behavior of others.

Behaviors are very hard to change. One way of looking at it is that there are two ways to do it and they are by influence or by authority.

If you are the CEO of your company (and a totalitarian one at that) then you can use your authority to force people to change their behavior. Most of us don’t have that much authority over others, which means we have to use our influence.

You are going to need to learn how to exercise the influence you have and grow your influence (by building the working trust relationships and trust between you and the people you work with) in order to make change happen.

Some people are really good at influence. The rest of us have to practice.

So I’ve come up with 6 steps to help you practice, or exercise your influence. These are meant to be applicable to exercising influence over your teammates, boss, customers, anyone. These steps are very simple and I can’t provide you with any sort of guarantee, but I have found that when you are just starting to become aware of the positive influence you can have on the people around you and you want to get better at it it helps to have steps to follow.

Step 0: Generate ideas

You can't influence change if you have no idea what you want to see happen. This is step 0 because most of the time you already have an idea before you come to me to talk about how to learn to exercise your positive influence on others.

Step 1: Pick an idea and take time to think about it

It is important that you are sure that the idea you decide to try to introduce into your organization is a good one. Also, you want to be sure that this is an idea that will benefit the whole organization--not just you or your team. If you are just out to make your own life easier you are going to have a harder time finding allies for your cause eventually. If you do believe that this change would benefit your organization as a whole then you also need to spend time practicing explaining that benefit--make sure you can clearly articulate what exactly you propose and how it specifically meets a need or contributes toward a goal for the organization, elevator-pitch style.

Also consider if this is the right time to introduce a new idea and make a big change. I tend to get excited about making improvements and want to start everything right now. The right idea at the wrong time is not the right idea, though, and that can be hard to see, especially if this improvement is one you have been searching and thirsting for for a long time.

Step 2: Find potential allies

Just like with collecting ideas you will need to collect allies. Who can help you make the change you are proposing? Who absolutely has to be involved? In other words, who do you need to influence?

Pick one person to start with.


Step 3: Get to know your potential ally

If you have a good working relationship with someone and you trust one another then it is relatively easy to convince them to help you try out a new idea if you really believe in its value.

If you don’t have a good working relationship with the person you decide you need to influence be ready to sell your idea—think of what they value, what they need—how would this change benefit them and their current situation. Some people can be convinced purely by explaining the benefit to the organization, but I don’t count on that. If the change that you are proposing doesn't benefit them directly sometimes you can offer them something unrelated instead. Is there a project they are working on that you can help with?

Communication styles are extremely important and we are often unconscious of the effects that our differing styles have on our ability to collaborate. Some people are very formal and others are very casual. Some people want all of the facts and they want them in writing, others would be annoyed by that. Some people want to hear an idea only after it has been fully flushed out, others prefer to hear about an idea at the very earliest stage (later is boring). It is important not to ignore the other person's preferred communication style and it often helps to adapt your style to match theirs while you are asking them to do you a favor.

Once you have thought about all of these things you are ready to go ask!

Step 3.5: Assume they are your ally

I caution everyone to skip this step at your own peril. When you don't have a good working relationship with someone (or especially when you have an antagonistic relationship) it is all too easy to walk up to them with your shoulders tensed and eyebrows lowered like you are ready for a fight. You may even have your come backs or defenses prepared ahead of time. If you do this be prepared to fail at influencing them to join your cause.

Push everything out of your mind except that which has to do with how your interests overlap and your future successes can reinforce one another. Picture them as an ally and then walk in to their office.


Step 4: Ask for it

Make your proposal, ask for their help. Show how it benefits them (and the organization). Listen to what they say in response.


Step 5: Rinse and repeat

The more successful exchanges you make the stronger your relationships become and the easier it is to get a yes.

Dealing with "No!"

If you go around asking people to change their behavior you are going to hear a lot of "No"s. It is important to listen to what they say when they say no, and how they said it and then to reflect on what happened. Was there a problem with the idea or with the relationship or the presentation of the idea? Often a combination of factors. It is important to reflect on the many refusals that you will receive to either come up with a better idea, or a better way to present the idea or to find relationships that need more work and ways to improve those relationships.

Here are some questions to ask yourself:
  • Did you present the idea in a way that made sense to them and their situation?
  • Do you really understand their context?
  • Was it a good idea?
  • Was it the wrong time?
  • Do they trust you?
  • Did they really say no?
That last one is interesting because sometimes they don't really say no, but they also don't say exactly what you were hoping. Often times instead of no they want to discuss your idea, criticizing it or questioning some of your assumptions--listen and learn what you can. A good critic can be one of your best allies sometimes.

But sometimes it is the relationship that is the problem and the other person is never going to say yes to your idea, no matter how good or beneficial to them. You might think the other person is just stubborn/incompetent/uncaring/evil. When they say no it feels personal. The resistance/misunderstanding is often a result of the positions that we hold in our organizations. When I start to view someone as hostle and irrational when they reject my ideas I like to ask myself this question: If you swapped jobs/roles how would the dynamic be different? Would you feel the same way they do? Would you act the same? Be honest.

Often if I can get out from under my anger and frustration I can see how the position the other person is in leads them to react to my idea in a certain way and that I would probably do the same in their position.

In my talk I went through some of the common patterns of system-related tensions and how to address them. Rather than go through them again I am going to just say that you need to read Seeing Systems: Unlocking the Mysteries of Organizational Life by Barry Oshry.

If you are having a hard time forming productive relationships across all layers you are going to have a hard time influencing change. Seeing these patterns helps you empathize, so that you can approach your colleague as an ally instead of an enemy. Seeing is not going to solve all of your problems, but it certainly helps.

Let's get practical


Okay, I want to give some practical tips for influencing change. The first three are general things that you muse do to succeed at influencing your organization:

  • Care deeply
  • Be positive
  • Stay focused

If you don't care deeply about the success of your whole organization and all of the people in it you are going to have a hard time mustering the energy to make real change happen.

Be positive to attract followers. Cynicism wears you down eventually and people are already going to be tired from all the work it takes to change our behavior for the better.

Stay focused: it is easy to get distracted at work because there are always a million things to do, fires to put out. Change is very slow and influence is very messy and if you lose focus on what you are trying to accomplish, well, you are not going to succeed. It isn't easy, but I find that it helps to have some key allies in play to help me stay focused. If you set up a regular meeting with an ally or mentor to discuss your progress, for example, it is a little easier stay focused week after week.

Don't be afraid to ask for help like that. Another common urge when you are championing a new idea or big change is to want to hold on to it like it is your baby. The thing about organizational change is that it needs to grow to be successful and that means you need to let it get too big to fit in your hands alone--ask for help. Getting help also means that you will be less likely to burn out and lose focus before you have reached your goal.

One good way to attract followers without having to hunt them down is to make your efforts visible. In Scrum we like to have information radiators in the team space so that anyone, any teammate or stakeholder or anyone, can walk by and see what is going on--what is done, what hasn't been started yet, what has been sitting in the in progress pile for a week (stuck?). This is also a good idea for your change projects. If you try out your new ideas and have a little success and want to try it on a larger scale, make that visible however you can.

Speaking of success, don't forget to celebrate even the smallest of victories. Cookies, a lap around the building, high five, happy dance, however you and your allies prefer to celebrate, take time to do so. And say thank you!

Whew, I have several more practical tips that I covered at ETE, but rather than write them all out here I'm going to say that instead you should go read Fearless Change: Patterns for Introducing New Ideas by Mary Lynn Manns and Linda Rising. This book is chock-full of simple and widely used tactics for introducing change. All of my favorite tools were in there as well as many that I hadn't tried before that I wish I had known of sooner.

Finally, be patient. I can't stress enough how SLOW change is. Some days it feels like we must be moving backwards we are moving so slow, but you have to keep working and stay positive and put on your long-range goggles before you give up and decide that it is hopeless.

And be flexible too, as the momentum for your change grows and you attract followers to your cause and learn about your organization your idea is going to change. Let it change; learn as you go. "Power is the ability to act as if you can make happen whatever it is you want to make happen, knowing that you cannot, and being willing to work with whatever does happen" -Barry Oshry (Seeing Systems)

Thanks for reading so long! Let me know how you are doing. What ideas are you trying to introduce? What are your favorite tools for introducing change?

Tuesday, January 26, 2010

My First Spring Roo App (two months later)

Getting Started with Spring Roo


When I started working with Roo I think they were on RC 2 and now we are on the full-fledged Release 1.0.0, and I noticed that a lot of the tutorials that got me through those early days are a little outdated since a few common commands and generated output have changed over the past two months. I thought since I borrowed so heavily from the ROOsters before me (thanks BTW, Ben Alex and Stefan Schmidt) I would return the favor and talk about my experience a bit. I haven't gotten around to writing my own step-by step guide, but at least I can tell you more about why I chose Roo and pass along the things I have learned along the way.


I don't remember when I first learned about Spring Roo, but right from the start I was impressed. I cut my Spring teeth working on a few fairly large and complicated Spring webapps for about a year before I met Roo. I did the Springsource training, drank the koolaid; I honestly like working with Spring and I feel at home working in Java, but I did miss the fun and seemingly fast-paced development on the Rails projects from my past. Roo promised to bring back the fun and help to make a lot of the routine work of writing Java code disappear.


I had a little side project that started up in November of 2009; the idea was basically a really simple CRUD app. Three domain objects, some security, done. We all know how requirements do tend to change and multiply (especially when you bring a nice-looking and complete webapp as a demo to the first meeting, thanks to Roo), but this project is under control and I am still using Roo to add functionality (like email sending) and to manage the simple domain objects and their controllers and views.


Gotchas


Oh man, have I fallen into a few holes on my way to getting this app off the ground. Some of them turned out to be ROO bugs (I was working with the release candidates, after all) and others were just boneheaded mistakes on my part. In hopes of helping you avoid the same traps here is my list of gotchas and tips for working in Roo. I'll update these as I get a chance, but here are some of my recent lessons learned:


  • If you push in Roo on your domain object so that all of the entity management code is laying around and love to collect all of your imports under something like javax.persistence.* make sure you have an explicit import for javax.persistence.EntityManager. I usually set my minimum pretty low, so that if I optimize imports (ctrl + shift + o in eclipse/STS) then it will use a * instead of listing imports individually if I have more than 10 or so from the same package. That is normally fine, but causes serious problems for your little Roo app. It will yell at you for not returning the right type on your entityManager() method.
  • I am using some security on my manager methods and I went to write a test and I wasn't getting the results I expected. It was saying something about "can't parse expression" referring to the Spring EL expression that is used in the PreAuthorize annotation on my manager method. Well, it turns out I was using the wrong kind of authentication token to fake someone being logged in for my tests. Here is the real way to do it:


    I call this from my test:

    private void addResearcherToSecurityContext(Researcher researcher, boolean admin) {
         Collection authorities = researcher.getAuthorities();
         if (admin) {
             authorities.add(new GrantedAuthorityImpl("ROLE_ADMIN"));
         }
         TestingAuthenticationToken authentication = new TestingAuthenticationToken(researcher, researcher.getPassword(), authorities.toArray(new GrantedAuthority[authorities.size()]));
         SecurityContextHolder.getContext().setAuthentication(authentication);
    }
    

    and put this in my test application context:
    <bean class="org.springframework.security.authentication.TestingAuthenticationProvider" id="testAuthenticationProvider" />
    

    and put this in my test application security context:
    <authentication-manager alias="authenticationManager">
    <authentication-provider  ref="testAuthenticationProvider" />
    </authentication-manager> 
    

    Simple, huh? It really is. You should know that my Researcher object extends UserDetails and that is what I use for authentication. Now I can write methods where I try to update someone else's account or do admin-y things as a non-admin and make sure that I get an access denied exception and all my data is safe.


  • This is more of a spring/hibernate thing than a Roo gotcha, but I'm going to put it here anyway because it just happened to me again... If you have a manager or, in this case, a test, and all of the methods are transactional. Don't annotate each method with @Transactional because inevitably you are going forget one time and then sit there running your test over and over wondering why it is saying "org.hibernate.SessionException: Session is closed!". You can stick the @Transactional on your class and then you are all set, no matter how many methods you add.
  • Don't forget: the forums and jira are your friends. There is also a seemingly constantly growing list of Roo links and resources on the forum