Search in sources :

Example 1 with SystemCredentials

use of org.apache.accumulo.server.security.SystemCredentials in project accumulo by apache.

the class SystemCredentialsIT method main.

public static void main(final String[] args) throws AccumuloException, TableNotFoundException, AccumuloSecurityException {
    Credentials creds = null;
    if (args.length < 2)
        throw new RuntimeException("Incorrect usage; expected to be run by test only");
    if (args[0].equals("bad")) {
        Instance inst = new Instance() {

            @Override
            public int getZooKeepersSessionTimeOut() {
                throw new UnsupportedOperationException();
            }

            @Override
            public String getZooKeepers() {
                throw new UnsupportedOperationException();
            }

            @Override
            public String getRootTabletLocation() {
                throw new UnsupportedOperationException();
            }

            @Override
            public List<String> getMasterLocations() {
                throw new UnsupportedOperationException();
            }

            @Override
            public String getInstanceName() {
                throw new UnsupportedOperationException();
            }

            @Override
            public String getInstanceID() {
                return SystemCredentials.class.getName();
            }

            @Override
            public Connector getConnector(String principal, AuthenticationToken token) throws AccumuloException, AccumuloSecurityException {
                throw new UnsupportedOperationException();
            }

            @Deprecated
            @Override
            public Connector getConnector(String user, CharSequence pass) throws AccumuloException, AccumuloSecurityException {
                throw new UnsupportedOperationException();
            }

            @Deprecated
            @Override
            public Connector getConnector(String user, ByteBuffer pass) throws AccumuloException, AccumuloSecurityException {
                throw new UnsupportedOperationException();
            }

            @Deprecated
            @Override
            public Connector getConnector(String user, byte[] pass) throws AccumuloException, AccumuloSecurityException {
                throw new UnsupportedOperationException();
            }
        };
        creds = SystemCredentials.get(inst);
    } else if (args[0].equals("good")) {
        creds = SystemCredentials.get(HdfsZooInstance.getInstance());
    } else if (args[0].equals("bad_password")) {
        Instance inst = new Instance() {

            @Override
            public int getZooKeepersSessionTimeOut() {
                throw new UnsupportedOperationException();
            }

            @Override
            public String getZooKeepers() {
                throw new UnsupportedOperationException();
            }

            @Override
            public String getRootTabletLocation() {
                throw new UnsupportedOperationException();
            }

            @Override
            public List<String> getMasterLocations() {
                throw new UnsupportedOperationException();
            }

            @Override
            public String getInstanceName() {
                throw new UnsupportedOperationException();
            }

            @Override
            public String getInstanceID() {
                return SystemCredentials.class.getName();
            }

            @Override
            public Connector getConnector(String principal, AuthenticationToken token) throws AccumuloException, AccumuloSecurityException {
                throw new UnsupportedOperationException();
            }

            @Deprecated
            @Override
            public Connector getConnector(String user, CharSequence pass) throws AccumuloException, AccumuloSecurityException {
                throw new UnsupportedOperationException();
            }

            @Deprecated
            @Override
            public Connector getConnector(String user, ByteBuffer pass) throws AccumuloException, AccumuloSecurityException {
                throw new UnsupportedOperationException();
            }

            @Deprecated
            @Override
            public Connector getConnector(String user, byte[] pass) throws AccumuloException, AccumuloSecurityException {
                throw new UnsupportedOperationException();
            }
        };
        creds = new SystemCredentials(inst, "!SYSTEM", new PasswordToken("fake"));
    } else {
        throw new RuntimeException("Incorrect usage; expected to be run by test only");
    }
    Instance instance = HdfsZooInstance.getInstance();
    Connector conn;
    try {
        conn = instance.getConnector(creds.getPrincipal(), creds.getToken());
    } catch (AccumuloSecurityException e) {
        e.printStackTrace(System.err);
        System.exit(BAD_PASSWD_FAIL_CODE);
        return;
    }
    try (Scanner scan = conn.createScanner(RootTable.NAME, Authorizations.EMPTY)) {
        for (Entry<Key, Value> e : scan) {
            e.hashCode();
        }
    } catch (RuntimeException e) {
        // catch the runtime exception from the scanner iterator
        if (e.getCause() instanceof AccumuloSecurityException && ((AccumuloSecurityException) e.getCause()).getSecurityErrorCode() == SecurityErrorCode.BAD_CREDENTIALS) {
            e.printStackTrace(System.err);
            System.exit(FAIL_CODE);
        }
    }
}
Also used : SystemCredentials(org.apache.accumulo.server.security.SystemCredentials) Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) Instance(org.apache.accumulo.core.client.Instance) HdfsZooInstance(org.apache.accumulo.server.client.HdfsZooInstance) ByteBuffer(java.nio.ByteBuffer) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Value(org.apache.accumulo.core.data.Value) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Credentials(org.apache.accumulo.core.client.impl.Credentials) SystemCredentials(org.apache.accumulo.server.security.SystemCredentials) Key(org.apache.accumulo.core.data.Key)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 Connector (org.apache.accumulo.core.client.Connector)1 Instance (org.apache.accumulo.core.client.Instance)1 Scanner (org.apache.accumulo.core.client.Scanner)1 Credentials (org.apache.accumulo.core.client.impl.Credentials)1 AuthenticationToken (org.apache.accumulo.core.client.security.tokens.AuthenticationToken)1 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)1 Key (org.apache.accumulo.core.data.Key)1 Value (org.apache.accumulo.core.data.Value)1 HdfsZooInstance (org.apache.accumulo.server.client.HdfsZooInstance)1 SystemCredentials (org.apache.accumulo.server.security.SystemCredentials)1