|
Page Created :
OPENEJB :
Security Annotations
Security Annotations has been created by David Blevins (Sep 11, 2007). Content:This page shows the correct usage of the security related annotations:
Basic idea
Restricting a MethodRestrict the 'svnCommit' method to only individuals logged in and part of the "committer" role. Note that more than one role can be listed. @Stateless
@DeclareRoles({"committer"})
public class OpenSourceProjectBean implements Project {
@RolesAllowed({"committer"})
public String svnCommit(String s) {
return s;
}
}
DeclaredRolesYou need to update the @DeclaredRoles when referencing more roles in your annotations. @Stateless
@DeclareRoles({"committer", "contributor"})
public class OpenSourceProjectBean implements Project {
@RolesAllowed({"committer"})
public String svnCommit(String s) {
return s;
}
@RolesAllowed({"contributor"})
public String submitPatch(String s) {
return s;
}
}
Restricting all methods in a class@Stateless
@DeclareRoles({"committer", "contributor"})
public class OpenSourceProjectBean implements Project {
@RolesAllowed({"committer"})
public String svnCommit(String s) {
return s;
}
@RolesAllowed({"contributor"})
public String submitPatch(String s) {
return s;
}
}
ExampleBusiness Interface public static interface Project { public String svnCommit(String s); public String submitPatch(String s); public String svnCheckout(String s); public String deleteProject(String s); public boolean isCallerInRole(String s); } @Stateless
@DeclareRoles({"committer", "contributor","community"})
public class FooBean implements Project {
@Resource
private SessionContext context;
@RolesAllowed({"committer"})
public String svnCommit(String s) {
return s;
}
@RolesAllowed({"committer", "contributor"})
public String submitPatch(String s) {
return s;
}
@PermitAll
public String svnCheckout(String s) {
return s;
}
@DenyAll
public String deleteProject(String s) {
return s;
}
public boolean isCallerInRole(String role){
return context.isCallerInRole(role);
}
}
@Stateless @RunAs("contributor") @DeclareRoles({"committer", "contributor","community"}) public class BarBean implements Project { @Resource private SessionContext context; @RolesAllowed({"committer"}) public String svnCommit(String s) { return s; } @RolesAllowed({"committer", "contributor"}) public String submitPatch(String s) { return s; } @PermitAll public String svnCheckout(String s) { return s; } @DenyAll public String deleteProject(String s) { return s; } @PermitAll public boolean isCallerInRole(String role){ return context.isCallerInRole(role); } } |
Powered by
Atlassian Confluence
(Version: 2.2.9 Build:#527 Sep 07, 2006)
-
Bug/feature request
Unsubscribe or edit your notifications preferences
Unsubscribe or edit your notifications preferences
