/*
 * Copyright (c) 2011 Evolveum
 *
 * The contents of this file are subject to the terms
 * of the Common Development and Distribution License
 * (the License). You may not use this file except in
 * compliance with the License.
 *
 * You can obtain a copy of the License at
 * http://www.opensource.org/licenses/cddl1 or
 * CDDLv1.0.txt file in the source code distribution.
 * See the License for the specific language governing
 * permission and limitations under the License.
 *
 * If applicable, add the following below the CDDL Header,
 * with the fields enclosed by brackets [] replaced by
 * your own identifying information:
 *
 * Portions Copyrighted 2011 [name of copyright owner]
 * Portions Copyrighted 2010 Forgerock
 */

package com.evolveum.midpoint.web.security;

import java.io.Serializable;
import java.util.Collection;

import org.springframework.context.annotation.Scope;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;

/**
 * 
 * @author lazyman
 */
@Controller("security")
@Scope("session")
public class SecurityUtils implements Serializable {

	private static final long serialVersionUID = 4319833095810269507L;

	public boolean getIsUserLoggedIn() {
		return isUserInRole("ROLE_USER") || isUserInRole("ROLE_ADMIN");
	}

	private boolean isUserInRole(final String role) {
		final Collection<GrantedAuthority> grantedAuthorities = (Collection<GrantedAuthority>) SecurityContextHolder
				.getContext().getAuthentication().getAuthorities();
		for (GrantedAuthority grantedAuthority : grantedAuthorities) {
			if (role.equals(grantedAuthority.getAuthority())) {
				return true;
			}
		}
		return false;
	}

	public String getShortUserName() {
		Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();

		if (principal == null) {
			return "Not Logged in";
		}

		if (principal instanceof PrincipalUser) {
			PrincipalUser user = (PrincipalUser) principal;
			if (user.getFullName() != null) {
				return user.getFullName();
			}

			return user.getName();
		}

		return principal.toString();
	}
}

@@ -1342,36 +1342,116 @@
 ER%22)
- %7C%7C isUserInRole(%22ROLE_ADMIN
+;%0A%09%7D%0A%09%0A%09public boolean getIsAdminLoggedIn() %7B%0A%09%09return isUserInRole(%22ROLE_ADMIN%22) %7C%7C isUserInRole(%22ROLE_USER
 %22);%0A

Add option for user and admin.