Example usage for org.apache.lucene.util.automaton CharacterRunAutomaton run

List of usage examples for org.apache.lucene.util.automaton CharacterRunAutomaton run

Introduction

In this page you can find the example usage for org.apache.lucene.util.automaton CharacterRunAutomaton run.

Prototype

public boolean run(String s) 

Source Link

Document

Returns true if the given string is accepted by this automaton.

Usage

From source file:org.elasticsearch.index.reindex.TransportReindexAction.java

License:Apache License

static void checkRemoteWhitelist(CharacterRunAutomaton whitelist, RemoteInfo remoteInfo) {
    if (remoteInfo == null) {
        return;//from  www.j av a  2 s .  c o m
    }
    String check = remoteInfo.getHost() + ':' + remoteInfo.getPort();
    if (whitelist.run(check)) {
        return;
    }
    throw new IllegalArgumentException(
            '[' + check + "] not whitelisted in " + REMOTE_CLUSTER_WHITELIST.getKey());
}

From source file:org.elasticsearch.xpack.core.security.authz.accesscontrol.FieldSubsetReader.java

License:Open Source License

/**
 * Wrap a single segment, exposing a subset of its fields.
 *///from w w  w .  ja v a  2 s . c om
FieldSubsetReader(LeafReader in, CharacterRunAutomaton filter) {
    super(in);
    ArrayList<FieldInfo> filteredInfos = new ArrayList<>();
    for (FieldInfo fi : in.getFieldInfos()) {
        if (filter.run(fi.name)) {
            filteredInfos.add(fi);
        }
    }
    fieldInfos = new FieldInfos(filteredInfos.toArray(new FieldInfo[filteredInfos.size()]));
    this.filter = filter;
}

From source file:org.elasticsearch.xpack.core.security.authz.privilege.ApplicationPrivilegeTests.java

License:Open Source License

public void testNonePrivilege() {
    final ApplicationPrivilege none = ApplicationPrivilege.NONE.apply("super-mega-app");
    CharacterRunAutomaton run = new CharacterRunAutomaton(none.getAutomaton());
    for (int i = randomIntBetween(5, 10); i > 0; i--) {
        final String action;
        if (randomBoolean()) {
            action = randomAlphaOfLengthBetween(3, 12);
        } else {/*from  ww  w  .  j  ava  2s .  c o m*/
            action = randomAlphaOfLengthBetween(3, 6) + randomFrom(":", "/") + randomAlphaOfLengthBetween(3, 8);
        }
        assertFalse("NONE should not grant " + action, run.run(action));
    }
}

From source file:org.elasticsearch.xpack.core.security.authz.privilege.ApplicationPrivilegeTests.java

License:Open Source License

public void testGetPrivilegeByName() {
    final ApplicationPrivilegeDescriptor descriptor = descriptor("my-app", "read", "data:read/*",
            "action:login");
    final ApplicationPrivilegeDescriptor myWrite = descriptor("my-app", "write", "data:write/*",
            "action:login");
    final ApplicationPrivilegeDescriptor myAdmin = descriptor("my-app", "admin", "data:read/*", "action:*");
    final ApplicationPrivilegeDescriptor yourRead = descriptor("your-app", "read", "data:read/*",
            "action:login");
    final Set<ApplicationPrivilegeDescriptor> stored = Sets.newHashSet(descriptor, myWrite, myAdmin, yourRead);

    assertEqual(ApplicationPrivilege.get("my-app", Collections.singleton("read"), stored), descriptor);
    assertEqual(ApplicationPrivilege.get("my-app", Collections.singleton("write"), stored), myWrite);

    final ApplicationPrivilege readWrite = ApplicationPrivilege.get("my-app", Sets.newHashSet("read", "write"),
            stored);//from   ww  w  . j ava2  s.c  om
    assertThat(readWrite.getApplication(), equalTo("my-app"));
    assertThat(readWrite.name(), containsInAnyOrder("read", "write"));
    assertThat(readWrite.getPatterns(),
            arrayContainingInAnyOrder("data:read/*", "data:write/*", "action:login"));

    CharacterRunAutomaton run = new CharacterRunAutomaton(readWrite.getAutomaton());
    for (String action : Arrays.asList("data:read/settings", "data:write/user/kimchy", "action:login")) {
        assertTrue(run.run(action));
    }
    for (String action : Arrays.asList("data:delete/user/kimchy", "action:shutdown")) {
        assertFalse(run.run(action));
    }
}

From source file:org.elasticsearch.xpack.core.security.support.Automatons.java

License:Open Source License

private static Predicate<String> predicate(Automaton automaton, final String toString) {
    CharacterRunAutomaton runAutomaton = new CharacterRunAutomaton(automaton, maxDeterminizedStates);
    return new Predicate<String>() {
        @Override/*w w  w.j  a  va2s .  c  o  m*/
        public boolean test(String s) {
            return runAutomaton.run(s);
        }

        @Override
        public String toString() {
            return toString;
        }
    };
}

From source file:org.elasticsearch.xpack.core.security.support.AutomatonsTests.java

License:Open Source License

private void assertMatch(Automaton automaton, String text) {
    CharacterRunAutomaton runAutomaton = new CharacterRunAutomaton(automaton, DEFAULT_MAX_DETERMINIZED_STATES);
    assertTrue(runAutomaton.run(text));
}

From source file:org.elasticsearch.xpack.core.security.support.AutomatonsTests.java

License:Open Source License

private void assertMismatch(Automaton automaton, String text) {
    CharacterRunAutomaton runAutomaton = new CharacterRunAutomaton(automaton, DEFAULT_MAX_DETERMINIZED_STATES);
    assertFalse(runAutomaton.run(text));
}

From source file:org.elasticsearch.xpack.core.security.support.AutomatonsTests.java

License:Open Source License

public void testLotsOfIndices() {
    final int numberOfIndices = scaledRandomIntBetween(512, 1024);
    final List<String> names = new ArrayList<>(numberOfIndices);
    for (int i = 0; i < numberOfIndices; i++) {
        names.add(randomAlphaOfLengthBetween(6, 48));
    }/*from w w  w .  j a v  a  2 s .co  m*/
    final Automaton automaton = Automatons.patterns(names);
    assertTrue(automaton.isDeterministic());

    CharacterRunAutomaton runAutomaton = new CharacterRunAutomaton(automaton);
    for (String name : names) {
        assertTrue(runAutomaton.run(name));
    }
}