@Override
    public boolean implies(Permission p) {
        // By default only supports comparisons with other WildcardPermissions
        if (!(p instanceof WildcardPermission)) {
            return false;
        }

        WildcardPermission wp = (WildcardPermission) p;

        List<Set<String>> otherParts = getParts(wp);

        int i = 0;
        for (Set<String> otherPart : otherParts) {
            // If this permission has less parts than the other permission, everything after the number of parts contained
            // in this permission is automatically implied, so return true
            if (getParts().size() - 1 < i) {
                return true;
            } else {
                Set<String> thisPart = getParts().get(i);

                // all tokens from otherPart must pass at least one token from thisPart
                for (String otherToken : otherPart) {
                    if (!caseSensitive) {
                        otherToken = otherToken.toLowerCase();
                    }
                	boolean otherIsMatched = false;
                	for (String token : thisPart) {
                        if (token.equals(WILDCARD_TOKEN)) {
                        	otherIsMatched = true;
                        	break;
                        }
                        if (matches(token, otherToken)) {
                        	otherIsMatched = true;
                        	break;
                        }
                	}
                	if (!otherIsMatched) {
                		return false;
                	}
                }
                i++;
            }
        }

        // If this permission has more parts than the other parts, only imply it if all of the other parts are wildcards
        for (; i < getParts().size(); i++) {
            Set<String> part = getParts().get(i);
            if (!part.contains(WILDCARD_TOKEN)) {
                return false;
            }
        }

        return true;
    }
@Test
    public void testIntrapartWildcard() {
        ActiveMQWildcardPermission superset = new ActiveMQWildcardPermission("topic:ActiveMQ.Advisory.*:read");
        ActiveMQWildcardPermission subset = new ActiveMQWildcardPermission("topic:ActiveMQ.Advisory.Topic:read");

        assertTrue(superset.implies(subset));
        assertFalse(subset.implies(superset));
    }