Java tutorial
/** * @Class Name : EgovStringUtil.java * @Description : ? ?? * @Modification Information * * ? ? * ------- -------- --------------------------- * 2009.01.13 ? * 2009.02.13 ? * * @author * @since 2009. 01. 13 * @version 1.0 * @see * */ package egovframework.let.utl.fcc.service; /* * Copyright 2001-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the ";License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS"; BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; public class EgovAuthUtil { private static final Logger LOGGER = LoggerFactory.getLogger(EgovAuthUtil.class); /** * @return true if the user has one of the specified roles. */ public static boolean hasRole(String[] roles) { boolean result = false; for (GrantedAuthority authority : SecurityContextHolder.getContext().getAuthentication().getAuthorities()) { String userRole = authority.getAuthority(); for (String role : roles) { if (role.equals(userRole)) { result = true; break; } } if (result) { break; } } return result; } }