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);
}
}
}
Aggregations