concept method in category flex

This is an excerpt from Manning's book Flex on Java.
Integrating Flex with Java is what this book is all about. That’s why chapter 5 will demonstrate further how to connect a Flex client more directly to the server side using the open source BlazeDS framework. BlazeDS provides a mechanism for allowing Flex to call methods on Java objects through binary serialization with the Action Message Format or AMF. This is much faster than what’s possible with web services or XML/HTTP(s) because it uses real objects and doesn’t have to marshal XML.
Even though all the remote components that you use to communicate with external services have methods supporting sending credentials for authentication, this is not an ideal solution because the application would need to hold the username and password, in order for you to manually pass them along with every remote method call you made. Not only is this tedious, it’s error prone. Instead you’ll leverage the ChannelSet to authenticate the user to the server side and maintain a session until you either close the application or log out.
Moving on to a more finely grained security, you can set up a global method interceptor using AOP pointcut syntax to define a pattern of methods you want to secure. The following code shows an example of this taken from the security.xml file provided by AppFuse.
<global-method-security>
<protect-pointcut
expression=" execution(* *..service.UserManager.getUsers(..))"
access="ROLE_ADMIN"/>
</global-method-security>This will constrain any call to a method named getUsers contained in a class or interface named UserManager whose package name ends with "service". As you can see this method allows you to apply very complex patterns to define which methods get secured.
<bean id="issueService" class="org.foj.service.impl.IssueManagerImpl">
<constructor-arg ref="issueDao"/>
<constructor-arg ref="commentService"/>
<security:intercept-methods>
<security:protect method="save"
access="ROLE_USER,ROLE_ADMIN" />
<security:protect method="remove*"
access="ROLE_ADMIN" />
</security:intercept-methods>
</bean>The code shows how to secure methods at the bean level in XML by using the Spring application context. This gives you more localized control over the security than the global method illustrated previously, keeping the security constraints closer to the code that it affects.
public interface IssueManager {
...
@Secured({"ROLE_USER", "ROLE_ADMIN"})
@RemotingInclude
Issue save(Issue issue);
@Secured({"ROLE_ADMIN"})
@RemotingInclude
void remove(Long id);
}The code shows the final method of securing the business methods by using the @Secured annotation. This is the most localized method of security and the method you’re going to use in upcoming examples. This keeps the declared security constraints right with the code you’re trying to secure. The other advantage to using the annotations over the other methods is that if people decide to override what you’ve defined in the code, they can override it using the XML configuration.