当前位置: 首页>>代码示例>>Java>>正文


Java StringUtils.hasText方法代码示例

本文整理汇总了Java中org.apache.shiro.util.StringUtils.hasText方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.hasText方法的具体用法?Java StringUtils.hasText怎么用?Java StringUtils.hasText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.shiro.util.StringUtils的用法示例。


在下文中一共展示了StringUtils.hasText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onAccessDenied

import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
@Override
protected boolean onAccessDenied(ServletRequest request,
		ServletResponse response) throws Exception {
	
		Subject subject = getSubject(request, response);  
        if (null == subject.getPrincipal()) {//表示没有登录,重定向到登录页面  
            saveRequest(request);
            WebUtils.issueRedirect(request, response, ShiroUtils.LOGIN_URL);  
        } else {
    		if(ShiroUtils.isAjax(request)){
    			Map<String, Object> result = new HashMap<String, Object>();
    			result.put("status", "401");
    			result.put("message", "sorry,您没有权限");
    			result.put("url", ShiroUtils.UNAUTHORIZED);
    			ShiroUtils.writeJson(response, result);
    		}else
    		{
    			if (StringUtils.hasText(ShiroUtils.UNAUTHORIZED)) {//如果有未授权页面跳转过去  
	                WebUtils.issueRedirect(request, response, ShiroUtils.UNAUTHORIZED);  
	            } else {//否则返回401未授权状态码  
	                WebUtils.toHttp(response).sendError(HttpServletResponse.SC_UNAUTHORIZED);  
	            } 
    		}
        }  
	return Boolean.FALSE;
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:27,代码来源:PermissionFilter.java

示例2: onAccessDenied

import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
@Override
protected boolean onAccessDenied(ServletRequest request,
		ServletResponse response) throws Exception {
	
		Subject subject = getSubject(request, response);  
        if (subject.getPrincipal() == null) {//表示没有登录,重定向到登录页面  
            saveRequest(request);  
            WebUtils.issueRedirect(request, response, ShiroUtils.LOGIN_URL);  
        } else {  
        	if(ShiroUtils.isAjax(request)){
    			Map<String, Object> result = new HashMap<String, Object>();
    			result.put("status", "401");
    			result.put("message", "sorry,您没有权限");
    			result.put("url", ShiroUtils.UNAUTHORIZED);
    			ShiroUtils.writeJson(response, result);
    		}else
    		{
    			if (StringUtils.hasText(ShiroUtils.UNAUTHORIZED)) {//如果有未授权页面跳转过去  
	                WebUtils.issueRedirect(request, response, ShiroUtils.UNAUTHORIZED);  
	            } else {//否则返回401未授权状态码  
	                WebUtils.toHttp(response).sendError(HttpServletResponse.SC_UNAUTHORIZED);  
	            } 
    		}
        }  
	return false;
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:27,代码来源:RoleFilter.java

示例3: onAccessDenied

import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
@Override
protected boolean onAccessDenied(ServletRequest request,
		ServletResponse response) throws Exception {
   		if(ShiroUtils.isAjax(request)){
   			Map<String, Object> result = new HashMap<String, Object>();
   			result.put("status", "401");
   			result.put("message", "非法操作");
   			result.put("url", ShiroUtils.INDEX_URL);
   			ShiroUtils.writeJson(response, result);
   		}else
   		{
   			if (StringUtils.hasText(ShiroUtils.INDEX_URL)) {//如果有未授权页面跳转过去  
                WebUtils.issueRedirect(request, response, ShiroUtils.INDEX_URL);
            } else {//否则返回401未授权状态码
                WebUtils.toHttp(response).sendError(HttpServletResponse.SC_UNAUTHORIZED);  
            } 
   		}
	return Boolean.FALSE;
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:20,代码来源:URLFilter.java

示例4: isContinued

import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
protected static boolean isContinued(String line) {
    if (!StringUtils.hasText(line)) {
        return false;
    }
    int length = line.length();
    //find the number of backslashes at the end of the line.  If an even number, the
    //backslashes are considered escaped.  If an odd number, the line is considered continued on the next line
    int backslashCount = 0;
    for (int i = length - 1; i > 0; i--) {
        if (line.charAt(i) == ESCAPE_TOKEN) {
            backslashCount++;
        } else {
            break;
        }
    }
    return backslashCount % 2 != 0;
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:18,代码来源:Ini.java

示例5: validateAuthenticationInfo

import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
/**
 * Validates the configuration in the JNDI <code>environment</code> settings and throws an exception if a problem
 * exists.
 * <p/>
 * This implementation will throw a {@link AuthenticationException} if the authentication mechanism is set to
 * 'simple', the principal is non-empty, and the credentials are empty (as per
 * <a href="http://tools.ietf.org/html/rfc4513#section-5.1.2">rfc4513 section-5.1.2</a>).
 *
 * @param environment the JNDI environment settings to be validated
 * @throws AuthenticationException if a configuration problem is detected
 */
protected void validateAuthenticationInfo(Hashtable<String, Object> environment)
    throws AuthenticationException
{
    // validate when using Simple auth both principal and credentials are set
    if(SIMPLE_AUTHENTICATION_MECHANISM_NAME.equals(environment.get(Context.SECURITY_AUTHENTICATION))) {

        // only validate credentials if we have a non-empty principal
        if( environment.get(Context.SECURITY_PRINCIPAL) != null &&
            StringUtils.hasText( String.valueOf( environment.get(Context.SECURITY_PRINCIPAL) ))) {

            Object credentials = environment.get(Context.SECURITY_CREDENTIALS);

            // from the FAQ, we need to check for empty credentials:
            // http://docs.oracle.com/javase/tutorial/jndi/ldap/faq.html
            if( credentials == null ||
                (credentials instanceof byte[] && ((byte[])credentials).length <= 0) || // empty byte[]
                (credentials instanceof char[] && ((char[])credentials).length <= 0) || // empty char[]
                (String.class.isInstance(credentials) && !StringUtils.hasText(String.valueOf(credentials)))) {

                throw new javax.naming.AuthenticationException("LDAP Simple authentication requires both a "
                                                                   + "principal and credentials.");
            }
        }
    }
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:37,代码来源:JndiLdapContextFactory.java

示例6: Section

import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
private Section(String name, String sectionContent) {
    if (name == null) {
        throw new NullPointerException("name");
    }
    this.name = name;
    Map<String,String> props;
    if (StringUtils.hasText(sectionContent) ) {
        props = toMapProps(sectionContent);
    } else {
        props = new LinkedHashMap<String,String>();
    }
    if ( props != null ) {
        this.props = props;
    } else {
        this.props = new LinkedHashMap<String,String>();
    }
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:18,代码来源:Ini.java

示例7: getCache

import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
/**
 * Returns the cache with the specified {@code name}.  If the cache instance does not yet exist, it will be lazily
 * created, retained for further access, and then returned.
 *
 * @param name the name of the cache to acquire.
 * @return the cache with the specified {@code name}.
 * @throws IllegalArgumentException if the {@code name} argument is {@code null} or does not contain text.
 * @throws CacheException           if there is a problem lazily creating a {@code Cache} instance.
 */
public <K, V> Cache<K, V> getCache(String name) throws IllegalArgumentException, CacheException {
    if (!StringUtils.hasText(name)) {
        throw new IllegalArgumentException("Cache name cannot be null or empty.");
    }

    Cache cache;

    cache = caches.get(name);
    if (cache == null) {
        cache = createCache(name);
        Cache existing = caches.putIfAbsent(name, cache);
        if (existing != null) {
            cache = existing;
        }
    }

    //noinspection unchecked
    return cache;
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:29,代码来源:AbstractCacheManager.java

示例8: applyChainConfig

import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
protected void applyChainConfig(String chainName, Filter filter, String chainSpecificFilterConfig) {
    if (log.isDebugEnabled()) {
        log.debug("Attempting to apply path [" + chainName + "] to filter [" + filter + "] " +
                "with config [" + chainSpecificFilterConfig + "]");
    }
    if (filter instanceof PathConfigProcessor) {
        ((PathConfigProcessor) filter).processPathConfig(chainName, chainSpecificFilterConfig);
    } else {
        if (StringUtils.hasText(chainSpecificFilterConfig)) {
            //they specified a filter configuration, but the Filter doesn't implement PathConfigProcessor
            //this is an erroneous config:
            String msg = "chainSpecificFilterConfig was specified, but the underlying " +
                    "Filter instance is not an 'instanceof' " +
                    PathConfigProcessor.class.getName() + ".  This is required if the filter is to accept " +
                    "chain-specific configuration.";
            throw new ConfigurationException(msg);
        }
    }
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:20,代码来源:DefaultFilterChainManager.java

示例9: applyLoginUrlIfNecessary

import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
private void applyLoginUrlIfNecessary(Filter filter) {
    String loginUrl = shiroConfig.getProperty("login.url", "/login");
    if (StringUtils.hasText(loginUrl) && (filter instanceof AccessControlFilter)) {
        AccessControlFilter acFilter = (AccessControlFilter) filter;
        //only apply the login url if they haven't explicitly configured one already:
        String existingLoginUrl = acFilter.getLoginUrl();
        if (AccessControlFilter.DEFAULT_LOGIN_URL.equals(existingLoginUrl)) {
            acFilter.setLoginUrl(loginUrl);
        }
    }
}
 
开发者ID:GojaFramework,项目名称:goja,代码行数:12,代码来源:GojaShiroFilter.java

示例10: createChain

import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
void createChain(String chainName, String chainDefinition) {
  if (!StringUtils.hasText(chainName)) {
    throw new NullPointerException("chainName cannot be null or empty.");
  }
  if (!StringUtils.hasText(chainDefinition)) {
    throw new NullPointerException("chainDefinition cannot be null or empty.");
  }
  String[] filterTokens = splitChainDefinition(chainDefinition);

  //each token is specific to each doFilter.
  //strip the name and extract any doFilter-specific config between brackets [ ]
  for (String token : filterTokens) {
    String[] nameConfigPair = toNameConfigPair(token);

    //now we have the doFilter name, path and (possibly null) path-specific config.  Let's apply them:
    addToChain(chainName, nameConfigPair[0], nameConfigPair[1]);
  }
}
 
开发者ID:orctom,项目名称:laputa,代码行数:19,代码来源:LaputaFilterChainManager.java

示例11: addToChain

import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
public void addToChain(String chainName, String filterName, String chainSpecificFilterConfig) {
  if (!StringUtils.hasText(chainName)) {
    throw new IllegalArgumentException("chainName cannot be null or empty.");
  }
  Filter filter = getFilter(filterName);
  if (filter == null) {
    throw new IllegalArgumentException("There is no doFilter with name '" + filterName +
        "' to apply to chain [" + chainName + "] in the pool of available Filters.  Ensure a " +
        "doFilter with that name/path has first been registered with the addFilter method(s).");
  }

  applyChainConfig(chainName, filter, chainSpecificFilterConfig);

  NamedFilterList chain = ensureChain(chainName);
  chain.add(filter);
}
 
开发者ID:orctom,项目名称:laputa,代码行数:17,代码来源:LaputaFilterChainManager.java

示例12: createEnvironment

import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
protected WebEnvironment createEnvironment(ServletContext sc) {

        Class<?> clazz = determineWebEnvironmentClass(sc);
        if (!MutableWebEnvironment.class.isAssignableFrom(clazz)) {
            throw new ConfigurationException("Custom WebEnvironment class [" + clazz.getName() +
                    "] is not of required type [" + WebEnvironment.class.getName() + "]");
        }

        String configLocations = sc.getInitParameter(CONFIG_LOCATIONS_PARAM);
        boolean configSpecified = StringUtils.hasText(configLocations);

        if (configSpecified && !(ResourceConfigurable.class.isAssignableFrom(clazz))) {
            String msg = "WebEnvironment class [" + clazz.getName() + "] does not implement the " +
                    ResourceConfigurable.class.getName() + "interface.  This is required to accept any " +
                    "configured " + CONFIG_LOCATIONS_PARAM + "value(s).";
            throw new ConfigurationException(msg);
        }

        MutableWebEnvironment environment = (MutableWebEnvironment) ClassUtils.newInstance(clazz);

        environment.setServletContext(sc);

        if (configSpecified && (environment instanceof ResourceConfigurable)) {
            ((ResourceConfigurable) environment).setConfigLocations(configLocations);
        }

        customizeEnvironment(environment);

        //environment.setWebSecurityManager(defaultWebSecurityManager);


        //LifecycleUtils.initialBuild(environment);

        return environment;
    }
 
开发者ID:Teddy-Zhu,项目名称:SilentGo,代码行数:36,代码来源:ShiroLoader.java

示例13: getCache

import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
@Override
public <K, V> Cache<K, V> getCache(String name) throws CacheException {
    if (!StringUtils.hasText(name)) {
        throw new IllegalArgumentException("Cache name cannot be null or empty.");
    }
    log.debug("redis cache manager get cache name is :{}", name);
    Cache cache = (Cache) redisTemplate.opsForValue().get(name);
    if (cache == null) {
        cache = new RedisCache<>(redisTemplate);
        redisTemplate.opsForValue().set(SystemConstant.shiro_cache_prefix + name, cache);
    }
    return cache;
}
 
开发者ID:Ouyangan,项目名称:hunt-admin,代码行数:14,代码来源:RedisCacheManager.java

示例14: createSessionContext

import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
protected SessionContext createSessionContext() {
    SessionContext sessionContext = new DefaultSessionContext();
    if (StringUtils.hasText(host)) {
        sessionContext.setHost(host);
    }
    return sessionContext;
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:8,代码来源:DelegatingSubject.java

示例15: applyLoginUrlIfNecessary

import org.apache.shiro.util.StringUtils; //导入方法依赖的package包/类
private void applyLoginUrlIfNecessary(Filter filter) {
    String loginUrl = getLoginUrl();
    if (StringUtils.hasText(loginUrl) && (filter instanceof AccessControlFilter)) {
        AccessControlFilter acFilter = (AccessControlFilter) filter;
        //only apply the login url if they haven't explicitly configured one already:
        String existingLoginUrl = acFilter.getLoginUrl();
        if (AccessControlFilter.DEFAULT_LOGIN_URL.equals(existingLoginUrl)) {
            acFilter.setLoginUrl(loginUrl);
        }
    }
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:12,代码来源:ShiroFilterFactoryBean.java


注:本文中的org.apache.shiro.util.StringUtils.hasText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。