/** * Create or update an existing key. * * @param serviceType the type of service to create a token for * @param user the user the token is for * @param topologyId the topology the token is for * @return a newly generated token that should be good to start using form now until it expires. */ public WorkerToken createOrUpdateTokenFor(WorkerTokenServiceType serviceType, String user, String topologyId) { long nextVersion = state.getNextPrivateWorkerKeyVersion(serviceType, topologyId); SecretKey topoSecret = getCurrentSecret(); long expirationTimeMillis = Time.currentTimeMillis() + tokenLifetimeMillis; WorkerTokenInfo info = new WorkerTokenInfo(user, topologyId, nextVersion, expirationTimeMillis); byte[] serializedInfo = ClientAuthUtils.serializeWorkerTokenInfo(info); byte[] signature = WorkerTokenSigner.createPassword(serializedInfo, topoSecret); WorkerToken ret = new WorkerToken(serviceType, ByteBuffer.wrap(serializedInfo), ByteBuffer.wrap(signature)); PrivateWorkerKey key = new PrivateWorkerKey(ByteBuffer.wrap(topoSecret.getEncoded()), user, expirationTimeMillis); state.addPrivateWorkerKey(serviceType, topologyId, nextVersion, key); LOG.info("Created new WorkerToken for user {} topology {} on service {}", user, topologyId, serviceType); return ret; }
WorkerTokenManager wtm = new WorkerTokenManager(conf, mockState); when(mockState.getNextPrivateWorkerKeyVersion(type, topoId)).thenReturn(versionNumber); doAnswer((invocation) -> {
WorkerTokenManager wtm = new WorkerTokenManager(conf, mockState); when(mockState.getNextPrivateWorkerKeyVersion(type, topoId)).thenReturn(versionNumber); doAnswer((invocation) -> {