To get the username and check roles, you should be able to use the
following methods from HttpServletRequest:
request.getRemoteUser()
request.isUserInRole(String roleName)
Matt
On 7/31/07, tibi <[EMAIL PROTECTED]> wrote:
> not sure if this helps you but i have a myBaseAction class as follows:
>
>
> package nl.topticketline.topnet.util;
>
> import org.acegisecurity.Authentication;
> import org.acegisecurity.context.SecurityContextHolder;
> import org.acegisecurity.userdetails.UserDetails;
> import org.appfuse.model.Role;
> import org.appfuse.model.User;
> import org.appfuse.webapp.action.BaseAction;
>
> /**
> * This can be extended by action classes instead of the BaseAction.
> *
> * @author tibi
> *
> */
> public abstract class MyBaseAction extends BaseAction {
> public static final String AJAX = "AJAX";
>
> /**
> * 1 will be true other values will be false.
> */
> public boolean getValueAsBoolean(String booleanStr) {
> if ("1".equals(booleanStr)) {
> return true;
> }
> return false;
> }
>
> /**
> * Will return the userName as string from the logged in user.
> *
> * @return
> */
> public String getLoggedInUserName() {
> if (SecurityContextHolder.getContext() != null) {
> Authentication auth =
> SecurityContextHolder.getContext().getAuthentication();
> if (auth != null) {
> Object obj = auth.getPrincipal();
> log.debug("object:" + obj);
> if (obj != null) {
> if (obj instanceof UserDetails) {
> return ((UserDetails) obj).getUsername();
> } else {
> return (String) obj;
> }
> }
> }
> }
> return null;
> }
>
> /**
> * Will return the logged in user.
> *
> * @return
> */
> public User getLoggedInUser() {
> String userName = getLoggedInUserName();
> if (userName == null) {
> log.warn("userName is null");
> return null;
> }
> log.debug("getting user:" + userName);
> if (userManager == null) {
> return null;
> }
> return userManager.getUserByUsername(userName);
> }
>
> /**
> * checks if the logged in user has the role provided.
> *
> * @param roleName
> * @return
> */
> public boolean loggedInUserHasRole(String roleName) {
> if (roleName == null || roleName.length() == 0 ||
> getLoggedInUser() == null) {
> log.warn("roleName is not set right or there is no user found");
> return false;
> }
> for (Role role : getLoggedInUser().getRoles()) {
> if (roleName.equals(role.getName())) {
> return true;
> }
> }
> return false;
>
> }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
http://raibledesigns.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]