static synchronized Writer getWriter(ClientContext context) { Writer replicationTable = writers.get(context.getCredentials()); if (replicationTable == null) { configureMetadataTable(context, MetadataTable.NAME); replicationTable = new Writer(context, MetadataTable.ID); writers.put(context.getCredentials(), replicationTable); } return replicationTable; }
@Override public String whoami() { ensureOpen(); return getCredentials().getPrincipal(); }
public String getPrincipal() { ensureOpen(); return getCredentials().getPrincipal(); }
public AuthenticationToken getAuthenticationToken() { ensureOpen(); return getCredentials().getToken(); }
/** * Serialize the credentials just before initiating the RPC call */ public synchronized TCredentials rpcCreds() { ensureOpen(); if (getCredentials().getToken().isDestroyed()) { rpcCreds = null; } if (rpcCreds == null) { rpcCreds = getCredentials().toThrift(getInstanceID()); } return rpcCreds; }
@Override public void changeLocalUserPassword(final String principal, final PasswordToken token) throws AccumuloException, AccumuloSecurityException { checkArgument(principal != null, "principal is null"); checkArgument(token != null, "token is null"); final Credentials toChange = new Credentials(principal, token); executeVoid(client -> client.changeLocalUserPassword(Tracer.traceInfo(), context.rpcCreds(), principal, ByteBuffer.wrap(token.getPassword()))); if (context.getCredentials().getPrincipal().equals(principal)) { context.setCredentials(toChange); } }
public ConnectorImpl(ClientContext context) throws AccumuloSecurityException, AccumuloException { this.context = context; SingletonManager.setMode(Mode.CONNECTOR); if (context.getCredentials().getToken().isDestroyed()) throw new AccumuloSecurityException(context.getCredentials().getPrincipal(), SecurityErrorCode.TOKEN_EXPIRED); // Skip fail fast for system services; string literal for class name, to avoid dependency on // server jar final String tokenClassName = context.getCredentials().getToken().getClass().getName(); if (!SYSTEM_TOKEN_NAME.equals(tokenClassName)) { ServerClient.executeVoid(context, iface -> { if (!iface.authenticate(Tracer.traceInfo(), context.rpcCreds())) throw new AccumuloSecurityException("Authentication failed, access denied", SecurityErrorCode.BAD_CREDENTIALS); }); } }
@Override public void delete(String namespace) throws AccumuloException, AccumuloSecurityException, NamespaceNotFoundException, NamespaceNotEmptyException { checkArgument(namespace != null, "namespace is null"); Namespace.ID namespaceId = Namespaces.getNamespaceId(context, namespace); if (namespaceId.equals(Namespace.ID.ACCUMULO) || namespaceId.equals(Namespace.ID.DEFAULT)) { Credentials credentials = context.getCredentials(); log.debug("{} attempted to delete the {} namespace", credentials.getPrincipal(), namespaceId); throw new AccumuloSecurityException(credentials.getPrincipal(), SecurityErrorCode.UNSUPPORTED_OPERATION); } if (Namespaces.getTableIds(context, namespaceId).size() > 0) { throw new NamespaceNotEmptyException(namespaceId.canonicalID(), namespace, null); } List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(namespace.getBytes(UTF_8))); Map<String,String> opts = new HashMap<>(); try { doNamespaceFateOperation(FateOperation.NAMESPACE_DELETE, args, opts, namespace); } catch (NamespaceExistsException e) { // should not happen throw new AssertionError(e); } }
context.getCredentials().getPrincipal(), tse.getCode(), Tables.getPrintableTableInfoFromId(context, tableId), tse); queueException(location, cmidToCm, ase);
public ClientContext(SingletonReservation reservation, ClientInfo info, AccumuloConfiguration serverConf) { this.info = info; this.hadoopConf = info.getHadoopConf(); zooCache = new ZooCacheFactory().getZooCache(info.getZooKeepers(), info.getZooKeepersSessionTimeOut()); this.serverConf = serverConf; timeoutSupplier = memoizeWithExpiration( () -> getConfiguration().getTimeInMillis(Property.GENERAL_RPC_TIMEOUT)); sslSupplier = memoizeWithExpiration(() -> SslConnectionParams.forClient(getConfiguration())); saslSupplier = memoizeWithExpiration( () -> SaslConnectionParams.from(getConfiguration(), getCredentials().getToken())); this.singletonReservation = Objects.requireNonNull(reservation); this.tableops = new TableOperationsImpl(this); this.namespaceops = new NamespaceOperationsImpl(this, tableops); }