org.apache.hadoop.security.token.Token.getPassword()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(129)

本文整理了Java中org.apache.hadoop.security.token.Token.getPassword()方法的一些代码示例,展示了Token.getPassword()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Token.getPassword()方法的具体详情如下:
包路径:org.apache.hadoop.security.token.Token
类名称:Token
方法名:getPassword

Token.getPassword介绍

[英]Get the token password/secret
[中]获取令牌密码/密码

代码示例

代码示例来源:origin: apache/hbase

private static char[] buildClientPassword(Token<BlockTokenIdentifier> blockToken) {
 return new String(Base64.encodeBase64(blockToken.getPassword(), false), Charsets.UTF_8)
   .toCharArray();
}

代码示例来源:origin: apache/hive

/** Verifies the token available as serialized bytes. */
 public void verifyToken(byte[] tokenBytes) throws IOException {
  if (!UserGroupInformation.isSecurityEnabled()) return;
  if (tokenBytes == null) throw new SecurityException("Token required for authentication");
  Token<LlapTokenIdentifier> token = new Token<>();
  token.readFields(new DataInputStream(new ByteArrayInputStream(tokenBytes)));
  verifyToken(token.decodeIdentifier(), token.getPassword());
 }
}

代码示例来源:origin: apache/hbase

public SaslClientCallbackHandler(Token<? extends TokenIdentifier> token) {
 this.userName = SaslUtil.encodeIdentifier(token.getIdentifier());
 this.userPassword = SaslUtil.encodePassword(token.getPassword());
}

代码示例来源:origin: apache/hive

public SaslClientCallbackHandler(Token<? extends TokenIdentifier> token) {
 this.userName = encodeIdentifier(token.getIdentifier());
 this.userPassword = encodePassword(token.getPassword());
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

@SuppressWarnings("unchecked")
public UserGroupInformation verifyToken(
  Token<? extends AbstractDelegationTokenIdentifier> token)
    throws IOException {
 AbstractDelegationTokenIdentifier id = secretManager.decodeTokenIdentifier(token);
 secretManager.verifyToken(id, token.getPassword());
 return id.getUser();
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

public SaslClientCallbackHandler(Token<? extends TokenIdentifier> token) {
 this.userName = SaslRpcServer.encodeIdentifier(token.getIdentifier());
 this.userPassword = SaslRpcServer.encodePassword(token.getPassword());
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

/**
 * Construct a TokenProto from this Token instance.
 * @return a new TokenProto object holding copies of data in this instance
 */
public TokenProto toTokenProto() {
 return TokenProto.newBuilder().
   setIdentifier(ByteString.copyFrom(this.getIdentifier())).
   setPassword(ByteString.copyFrom(this.getPassword())).
   setKindBytes(ByteString.copyFrom(
     this.getKind().getBytes(), 0, this.getKind().getLength())).
   setServiceBytes(ByteString.copyFrom(
     this.getService().getBytes(), 0, this.getService().getLength())).
   build();
}

代码示例来源:origin: apache/hive

/**
 * Verify token string
 * @param tokenStrForm
 * @return user name
 * @throws IOException
 */
public synchronized String verifyDelegationToken(String tokenStrForm) throws IOException {
 Token<DelegationTokenIdentifier> t = new Token<>();
 t.decodeFromUrlString(tokenStrForm);
 DelegationTokenIdentifier id = getTokenIdentifier(t);
 verifyToken(id, t.getPassword());
 return id.getUser().getShortUserName();
}

代码示例来源:origin: apache/hbase

/**
 * Converts a Token instance (with embedded identifier) to the protobuf representation.
 *
 * @param token the Token instance to copy
 * @return the protobuf Token message
 */
public static AuthenticationProtos.Token toToken(Token<AuthenticationTokenIdentifier> token) {
 AuthenticationProtos.Token.Builder builder = AuthenticationProtos.Token.newBuilder();
 builder.setIdentifier(ByteString.copyFrom(token.getIdentifier()));
 builder.setPassword(ByteString.copyFrom(token.getPassword()));
 if (token.getService() != null) {
  builder.setService(ByteString.copyFromUtf8(token.getService().toString()));
 }
 return builder.build();
}

代码示例来源:origin: apache/hbase

private Token<? extends TokenIdentifier> createTokenMockWithCredentials(
  String principal, String password)
  throws IOException {
 Token<? extends TokenIdentifier> token = createTokenMock();
 if (!Strings.isNullOrEmpty(principal) && !Strings.isNullOrEmpty(password)) {
  when(token.getIdentifier()).thenReturn(Bytes.toBytes(DEFAULT_USER_NAME));
  when(token.getPassword()).thenReturn(Bytes.toBytes(DEFAULT_USER_PASSWORD));
 }
 return token;
}

代码示例来源:origin: apache/hbase

@Test
public void testSaslClientCallbackHandler() throws UnsupportedCallbackException {
 final Token<? extends TokenIdentifier> token = createTokenMock();
 when(token.getIdentifier()).thenReturn(Bytes.toBytes(DEFAULT_USER_NAME));
 when(token.getPassword()).thenReturn(Bytes.toBytes(DEFAULT_USER_PASSWORD));
 final NameCallback nameCallback = mock(NameCallback.class);
 final PasswordCallback passwordCallback = mock(PasswordCallback.class);
 final RealmCallback realmCallback = mock(RealmCallback.class);
 final RealmChoiceCallback realmChoiceCallback = mock(RealmChoiceCallback.class);
 Callback[] callbackArray = {nameCallback, passwordCallback, realmCallback, realmChoiceCallback};
 final SaslClientCallbackHandler saslClCallbackHandler = new SaslClientCallbackHandler(token);
 saslClCallbackHandler.handle(callbackArray);
 verify(nameCallback).setName(anyString());
 verify(realmCallback).setText(any());
 verify(passwordCallback).setPassword(any());
}

代码示例来源:origin: Qihoo360/XLearning

@Override
public GetDelegationTokenResponse getDelegationToken(
  GetDelegationTokenRequest request) throws IOException {
 UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
 // Verify that the connection is kerberos authenticated
 if (!isAllowedDelegationTokenOp()) {
  throw new IOException(
    "Delegation Token can be issued only with kerberos authentication");
 }
 GetDelegationTokenResponse response = recordFactory.newRecordInstance(
   GetDelegationTokenResponse.class);
 String user = ugi.getUserName();
 Text owner = new Text(user);
 Text realUser = null;
 if (ugi.getRealUser() != null) {
  realUser = new Text(ugi.getRealUser().getUserName());
 }
 MRDelegationTokenIdentifier tokenIdentifier =
   new MRDelegationTokenIdentifier(owner, new Text(
     request.getRenewer()), realUser);
 Token<MRDelegationTokenIdentifier> realJHSToken =
   new Token<MRDelegationTokenIdentifier>(tokenIdentifier,
     jhsDTSecretManager);
 org.apache.hadoop.yarn.api.records.Token mrDToken =
   org.apache.hadoop.yarn.api.records.Token.newInstance(
     realJHSToken.getIdentifier(), realJHSToken.getKind().toString(),
     realJHSToken.getPassword(), realJHSToken.getService().toString());
 response.setDelegationToken(mrDToken);
 return response;
}

代码示例来源:origin: apache/hbase

@Test
public void testSaslClientCallbackHandlerWithException() {
 final Token<? extends TokenIdentifier> token = createTokenMock();
 when(token.getIdentifier()).thenReturn(Bytes.toBytes(DEFAULT_USER_NAME));
 when(token.getPassword()).thenReturn(Bytes.toBytes(DEFAULT_USER_PASSWORD));
 final SaslClientCallbackHandler saslClCallbackHandler = new SaslClientCallbackHandler(token);
 try {
  saslClCallbackHandler.handle(new Callback[] { mock(TextOutputCallback.class) });
 } catch (UnsupportedCallbackException expEx) {
  //expected
 } catch (Exception ex) {
  fail("testSaslClientCallbackHandlerWithException error : " + ex.getMessage());
 }
}

代码示例来源:origin: apache/hbase

private static ExportProtos.ExportRequest getConfiguredRequest(Configuration conf,
    Path dir, final Scan scan, final Token<?> userToken) throws IOException {
 boolean compressed = conf.getBoolean(FileOutputFormat.COMPRESS, false);
 String compressionType = conf.get(FileOutputFormat.COMPRESS_TYPE,
     DEFAULT_TYPE.toString());
 String compressionCodec = conf.get(FileOutputFormat.COMPRESS_CODEC,
     DEFAULT_CODEC.getName());
 DelegationToken protoToken = null;
 if (userToken != null) {
  protoToken = DelegationToken.newBuilder()
      .setIdentifier(ByteStringer.wrap(userToken.getIdentifier()))
      .setPassword(ByteStringer.wrap(userToken.getPassword()))
      .setKind(userToken.getKind().toString())
      .setService(userToken.getService().toString()).build();
 }
 LOG.info("compressed=" + compressed
     + ", compression type=" + compressionType
     + ", compression codec=" + compressionCodec
     + ", userToken=" + userToken);
 ExportProtos.ExportRequest.Builder builder = ExportProtos.ExportRequest.newBuilder()
     .setScan(ProtobufUtil.toScan(scan))
     .setOutputPath(dir.toString())
     .setCompressed(compressed)
     .setCompressCodec(compressionCodec)
     .setCompressType(compressionType);
 if (protoToken != null) {
  builder.setFsToken(protoToken);
 }
 return builder.build();
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

/**
 * Generate a DelegationTokenAuthenticatedURL.Token from the given generic
 * typed delegation token.
 *
 * @param dToken The delegation token.
 * @return The DelegationTokenAuthenticatedURL.Token, with its delegation
 *         token set to the delegation token passed in.
 */
private DelegationTokenAuthenticatedURL.Token generateDelegationToken(
  final Token<?> dToken) {
 DelegationTokenAuthenticatedURL.Token token =
   new DelegationTokenAuthenticatedURL.Token();
 Token<AbstractDelegationTokenIdentifier> dt =
   new Token<>(dToken.getIdentifier(), dToken.getPassword(),
     dToken.getKind(), dToken.getService());
 token.setDelegationToken(dt);
 return token;
}

代码示例来源:origin: apache/hbase

ClientProtos.DelegationToken.newBuilder()
 .setIdentifier(UnsafeByteOperations.unsafeWrap(userToken.getIdentifier()))
 .setPassword(UnsafeByteOperations.unsafeWrap(userToken.getPassword()))
 .setKind(userToken.getKind().toString())
 .setService(userToken.getService().toString()).build();

代码示例来源:origin: org.apache.hadoop/hadoop-common

if (!MessageDigest.isEqual(password, token.getPassword())) {
 throw new AccessControlException(renewer
   + " is trying to renew a token "

代码示例来源:origin: apache/hbase

@Test
 public void testTokenCreation() throws Exception {
  Token<AuthenticationTokenIdentifier> token =
    secretManager.generateToken("testuser");

  AuthenticationTokenIdentifier ident = new AuthenticationTokenIdentifier();
  Writables.getWritable(token.getIdentifier(), ident);
  assertEquals("Token username should match", "testuser",
    ident.getUsername());
  byte[] passwd = secretManager.retrievePassword(ident);
  assertTrue("Token password and password from secret manager should match",
    Bytes.equals(token.getPassword(), passwd));
 }
// This won't work any more now RpcServer takes Shaded Service. It depends on RPCServer being able to provide a

代码示例来源:origin: apache/accumulo

private void setPasswordFromToken(Token<? extends TokenIdentifier> token,
  AuthenticationTokenIdentifier identifier) {
 if (!AuthenticationTokenIdentifier.TOKEN_KIND.equals(token.getKind())) {
  String msg = "Expected an AuthenticationTokenIdentifier but got a " + token.getKind();
  log.error(msg);
  throw new IllegalArgumentException(msg);
 }
 setPassword(token.getPassword());
 this.identifier = identifier;
}

代码示例来源:origin: apache/hbase

DelegationToken.newBuilder()
 .setIdentifier(ByteStringer.wrap(userToken.getIdentifier()))
 .setPassword(ByteStringer.wrap(userToken.getPassword()))
 .setKind(userToken.getKind().toString())
 .setService(userToken.getService().toString()).build();

相关文章