Example usage for org.apache.shiro.util StringUtils hasLength

List of usage examples for org.apache.shiro.util StringUtils hasLength

Introduction

In this page you can find the example usage for org.apache.shiro.util StringUtils hasLength.

Prototype

public static boolean hasLength(String str) 

Source Link

Document

Check that the given String is neither null nor of length 0.

Usage

From source file:com.leshazlewood.samples.shiromt.web.tenant.SubdomainTenantResolver.java

License:Apache License

@Override
public Tenant resolveTenant(ServletRequest request, ServletResponse response) {
    String key = resolveTenantKey(request);

    Tenant tenant = null;//from  w  ww .ja  v  a2  s. c o m
    if (StringUtils.hasLength(key)) {
        tenant = tenantManager.findByNameKey(key);
    }
    if (tenant == null) {
        tenant = tenantManager.getSystemTenant();
    }

    return tenant;
}

From source file:com.leshazlewood.samples.shiromt.web.tenant.SubdomainTenantResolver.java

License:Apache License

protected String resolveTenantKey(ServletRequest request) {
    String hostHeader = request.getServerName();
    if (hostHeader != null) {
        hostHeader = hostHeader.toLowerCase();
    }/*ww w .j  ava2 s.  co m*/
    String base = this.baseDomain;
    String key = null;

    if (base == null && StringUtils.hasLength(hostHeader)) {
        //infer the base from the host header:
        assert hostHeader != null;
        String[] tokens = hostHeader.split("\\.");
        if (tokens.length > 2) {
            StringBuilder sb = new StringBuilder();
            int subcount = tokens.length - 2;
            for (int i = 0; i < subcount; i++) {
                if (i > 0) {
                    sb.append(".");
                }
                sb.append(tokens[i]);
            }
            key = sb.toString();
        }
    }

    if (key == null && StringUtils.hasLength(base) && StringUtils.hasLength(hostHeader)) {
        assert hostHeader != null;
        int index = hostHeader.lastIndexOf(base);
        if (index >= 0) {
            key = hostHeader.substring(0, index);
        }
    }
    return key;
}