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


Java RegexUtils类代码示例

本文整理汇总了Java中org.jasig.cas.util.RegexUtils的典型用法代码示例。如果您正苦于以下问题:Java RegexUtils类的具体用法?Java RegexUtils怎么用?Java RegexUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: toProxyPolicy

import org.jasig.cas.util.RegexUtils; //导入依赖的package包/类
@Override
public RegisteredServiceProxyPolicy toProxyPolicy(final ServiceData data) {
    final RegisteredServiceProxyPolicyBean proxyPolicy = data.getProxyPolicy();

    final String type = proxyPolicy.getType();
    if (StringUtils.equalsIgnoreCase(type, RegisteredServiceProxyPolicyBean.Types.REGEX.toString())) {
        final String value = proxyPolicy.getValue();
        if (StringUtils.isNotBlank(value) && RegexUtils.isValidRegex(value)) {
            return new RegexMatchingRegisteredServiceProxyPolicy(value);
        } else {
            throw new IllegalArgumentException("Invalid regex pattern specified for proxy policy: " + value);
        }
    } else if (StringUtils.equalsIgnoreCase(type, RegisteredServiceProxyPolicyBean.Types.REFUSE.toString())) {
        return new RefuseRegisteredServiceProxyPolicy();
    }

    return null;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:19,代码来源:DefaultProxyPolicyMapper.java

示例2: getRegisteredService

import org.jasig.cas.util.RegexUtils; //导入依赖的package包/类
/**
 * Gets the registered service by id that would either match an ant or regex pattern.
 *
 * @param id the id
 * @return the registered service
 */
private AbstractRegisteredService getRegisteredService(@NotNull final String id) {
    if (RegexUtils.isValidRegex(id)) {
        return new RegexRegisteredService();
    }

    if (new AntPathMatcher().isPattern(id)) {
        return new RegisteredServiceImpl();
    }
    return null;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:17,代码来源:DefaultLdapRegisteredServiceMapper.java

示例3: matches

import org.jasig.cas.util.RegexUtils; //导入依赖的package包/类
@Override
public boolean matches(final Service service) {
    if (this.servicePattern == null) {
        this.servicePattern = RegexUtils.createPattern(this.serviceId);
    }
    return service != null && this.servicePattern != null
            && this.servicePattern.matcher(service.getId()).matches();
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:9,代码来源:RegexRegisteredService.java

示例4: determineServiceTypeByPattern

import org.jasig.cas.util.RegexUtils; //导入依赖的package包/类
/**
 * Determine service type by pattern.
 *
 * @param serviceId the service id
 * @return the abstract registered service
 */
private static AbstractRegisteredService determineServiceTypeByPattern(final String serviceId) {
    if (RegexUtils.isValidRegex(serviceId)) {
        LOGGER.debug("Service id {} is a valid regex.", serviceId);
        return new RegexRegisteredService();
    }

    if (new AntPathMatcher().isPattern(serviceId)) {
        LOGGER.debug("Service id {} is a valid ant pattern.", serviceId);
        return new RegisteredServiceImpl();
    }
    throw new RuntimeException("Service id " + serviceId + " cannot be resolve to a service type");
}
 
开发者ID:xuchengdong,项目名称:cas4.1.9,代码行数:19,代码来源:RegisteredServiceEditBean.java

示例5: doPrincipalAttributesAllowServiceAccess

import org.jasig.cas.util.RegexUtils; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * Verify presence of service required attributes.
 * <ul>
 *     <li>If no required attributes are specified, authz is granted.</li>
 *     <li>If ALL required attributes must be present, and the principal contains all and there is
 *     at least one attribute value that matches the required, authz is granted.</li>
 *     <li>If ALL required attributes don't have to be present, and there is at least
 *     one principal attribute present whose value matches the required, authz is granted.</li>
 *     <li>Otherwise, access is denied</li>
 * </ul>
 * Note that comparison of principal/required attributes is case-sensitive. Exact matches are required
 * for any individual attribute value.
 */
@Override
public boolean doPrincipalAttributesAllowServiceAccess(final String principal, final Map<String, Object> principalAttributes) {
    if (this.requiredAttributes.isEmpty()) {
        LOGGER.debug("No required attributes are specified");
        return true;
    }
    if (principalAttributes.isEmpty()) {
        LOGGER.debug("No principal attributes are found to satisfy attribute requirements");
        return false;
    }

    if (principalAttributes.size() < this.requiredAttributes.size()) {
        LOGGER.debug("The size of the principal attributes that are [{}] does not match requirements, "
                + "which means the principal is not carrying enough data to grant authorization",
                principalAttributes);
        return false;
    }

    final Map<String, Set<String>> requiredAttrs = this.getRequiredAttributes();
    LOGGER.debug("These required attributes [{}] are examined against [{}] before service can proceed.",
            requiredAttrs, principalAttributes);

    final Sets.SetView<String> difference = Sets.intersection(requiredAttrs.keySet(), principalAttributes.keySet());
    final Set<String> copy = difference.immutableCopy();

    if (this.requireAllAttributes && copy.size() < this.requiredAttributes.size()) {
        LOGGER.debug("Not all required attributes are available to the principal");
        return false;
    }

    for (final String key : copy) {
        final Set<String> requiredValues = this.requiredAttributes.get(key);
        final Set<String> availableValues;

        final Object objVal = principalAttributes.get(key);
        if (objVal instanceof Collection) {
            final Collection valCol = (Collection) objVal;
            availableValues = Sets.newHashSet(valCol.iterator());
        } else {
            availableValues = Sets.newHashSet(objVal.toString());
        }

        final Set<?> differenceInValues;
        final Pattern pattern = RegexUtils.concatenate(requiredValues, this.caseInsensitive);
        if (pattern != null) {
            differenceInValues = Sets.filter(availableValues, Predicates.contains(pattern));
        } else {
            differenceInValues = Sets.intersection(availableValues, requiredValues);
        }

        if (!differenceInValues.isEmpty()) {
            LOGGER.info("Principal is authorized to access the service");
            return true;
        }
    }
    LOGGER.info("Principal is denied access as the required attributes for the registered service are missing");
    return false;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:74,代码来源:DefaultRegisteredServiceAccessStrategy.java

示例6: doPrincipalAttributesAllowServiceAccess

import org.jasig.cas.util.RegexUtils; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * Verify presence of service required attributes.
 * <ul>
 *     <li>If no required attributes are specified, authz is granted.</li>
 *     <li>If ALL required attributes must be present, and the principal contains all and there is
 *     at least one attribute value that matches the required, authz is granted.</li>
 *     <li>If ALL required attributes don't have to be present, and there is at least
 *     one principal attribute present whose value matches the required, authz is granted.</li>
 *     <li>Otherwise, access is denied</li>
 * </ul>
 * Note that comparison of principal/required attributes is case-sensitive. Exact matches are required
 * for any individual attribute value.
 */
@Override
public boolean doPrincipalAttributesAllowServiceAccess(final String principal, final Map<String, Object> principalAttributes) {
    if (this.requiredAttributes.isEmpty()) {
        logger.debug("No required attributes are specified");
        return true;
    }
    if (principalAttributes.isEmpty()) {
        logger.debug("No principal attributes are found to satisfy attribute requirements");
        return false;
    }

    if (principalAttributes.size() < this.requiredAttributes.size()) {
        logger.debug("The size of the principal attributes that are [{}] does not match requirements, "
                + "which means the principal is not carrying enough data to grant authorization",
                principalAttributes);
        return false;
    }

    final Map<String, Set<String>> requiredAttrs = this.getRequiredAttributes();
    logger.debug("These required attributes [{}] are examined against [{}] before service can proceed.",
            requiredAttrs, principalAttributes);

    final Sets.SetView<String> difference = Sets.intersection(requiredAttrs.keySet(), principalAttributes.keySet());
    final Set<String> copy = difference.immutableCopy();

    if (this.requireAllAttributes && copy.size() < this.requiredAttributes.size()) {
        logger.debug("Not all required attributes are available to the principal");
        return false;
    }

    for (final String key : copy) {
        final Set<String> requiredValues = this.requiredAttributes.get(key);
        final Set<String> availableValues;

        final Object objVal = principalAttributes.get(key);
        if (objVal instanceof Collection) {
            final Collection valCol = (Collection) objVal;
            availableValues = Sets.newHashSet(valCol.iterator());
        } else {
            availableValues = Sets.newHashSet(objVal.toString());
        }

        final Set<?> differenceInValues;
        final Pattern pattern = RegexUtils.concatenate(requiredValues, this.caseInsensitive);
        if (pattern != null) {
            differenceInValues = Sets.filter(availableValues, Predicates.contains(pattern));
        } else {
            differenceInValues = Sets.intersection(availableValues, requiredValues);
        }

        if (!differenceInValues.isEmpty()) {
            logger.info("Principal is authorized to access the service");
            return true;
        }
    }
    logger.info("Principal is denied access as the required attributes for the registered service are missing");
    return false;
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:74,代码来源:DefaultRegisteredServiceAccessStrategy.java

示例7: doPrincipalAttributesAllowServiceAccess

import org.jasig.cas.util.RegexUtils; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * Verify presence of service required attributes.
 * <ul>
 *     <li>If no required attributes are specified, authz is granted.</li>
 *     <li>If ALL required attributes must be present, and the principal contains all and there is
 *     at least one attribute value that matches the required, authz is granted.</li>
 *     <li>If ALL required attributes don't have to be present, and there is at least
 *     one principal attribute present whose value matches the required, authz is granted.</li>
 *     <li>Otherwise, access is denied</li>
 * </ul>
 * Note that comparison of principal/required attributes is case-sensitive. Exact matches are required
 * for any individual attribute value.
 */
@Override
public boolean doPrincipalAttributesAllowServiceAccess(final Map<String, Object> principalAttributes) {
    if (this.requiredAttributes.isEmpty()) {
        logger.debug("No required attributes are specified");
        return true;
    }
    if (principalAttributes.isEmpty()) {
        logger.debug("No principal attributes are found to satisfy attribute requirements");
        return false;
    }

    if (principalAttributes.size() < this.requiredAttributes.size()) {
        logger.debug("The size of the principal attributes that are [{}] does not match requirements, "
                + "which means the principal is not carrying enough data to grant authorization",
                principalAttributes);
        return false;
    }

    final Map<String, Set<String>> requiredAttrs = this.getRequiredAttributes();
    logger.debug("These required attributes [{}] are examined against [{}] before service can proceed.",
            requiredAttrs, principalAttributes);

    final Sets.SetView<String> difference = Sets.intersection(requiredAttrs.keySet(), principalAttributes.keySet());
    final Set<String> copy = difference.immutableCopy();

    if (this.requireAllAttributes && copy.size() < this.requiredAttributes.size()) {
        logger.debug("Not all required attributes are available to the principal");
        return false;
    }

    for (final String key : copy) {
        final Set<String> requiredValues = this.requiredAttributes.get(key);
        final Set<String> availableValues;

        final Object objVal = principalAttributes.get(key);
        if (objVal instanceof Collection) {
            final Collection valCol = (Collection) objVal;
            availableValues = Sets.newHashSet(valCol.iterator());
        } else {
            availableValues = Sets.newHashSet(objVal.toString());
        }

        final Set<?> differenceInValues;
        final Pattern pattern = RegexUtils.concatenate(requiredValues, this.caseInsensitive);
        if (pattern != null) {
            differenceInValues = Sets.filter(availableValues, Predicates.contains(pattern));
        } else {
            differenceInValues = Sets.intersection(availableValues, requiredValues);
        }

        if (!differenceInValues.isEmpty()) {
            logger.info("Principal is authorized to access the service");
            return true;
        }
    }
    logger.info("Principal is denied access as the required attributes for the registered service are missing");
    return false;
}
 
开发者ID:xuchengdong,项目名称:cas4.1.9,代码行数:74,代码来源:DefaultRegisteredServiceAccessStrategy.java


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