• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TestTokenSecretManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.hadoop.ipc.TestSaslRPC.TestTokenSecretManager的典型用法代码示例。如果您正苦于以下问题:Java TestTokenSecretManager类的具体用法?Java TestTokenSecretManager怎么用?Java TestTokenSecretManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TestTokenSecretManager类属于org.apache.hadoop.ipc.TestSaslRPC包,在下文中一共展示了TestTokenSecretManager类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testProxyWithToken

import org.apache.hadoop.ipc.TestSaslRPC.TestTokenSecretManager; //导入依赖的package包/类
@Test
public void testProxyWithToken() throws Exception {
  final Configuration conf = new Configuration(masterConf);
  TestTokenSecretManager sm = new TestTokenSecretManager();
  SecurityUtil.setAuthenticationMethod(AuthenticationMethod.KERBEROS, conf);
  UserGroupInformation.setConfiguration(conf);
  final Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
      .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0)
      .setNumHandlers(5).setVerbose(true).setSecretManager(sm).build();

  server.start();

  final UserGroupInformation current = UserGroupInformation
      .createRemoteUser(REAL_USER_NAME);    
  
  final InetSocketAddress addr = NetUtils.getConnectAddress(server);
  TestTokenIdentifier tokenId = new TestTokenIdentifier(new Text(current
      .getUserName()), new Text("SomeSuperUser"));
  Token<TestTokenIdentifier> token = new Token<TestTokenIdentifier>(tokenId,
      sm);
  SecurityUtil.setTokenService(token, addr);
  UserGroupInformation proxyUserUgi = UserGroupInformation
      .createProxyUserForTesting(PROXY_USER_NAME, current, GROUP_NAMES);
  proxyUserUgi.addToken(token);
  
  refreshConf(conf);
  
  String retVal = proxyUserUgi.doAs(new PrivilegedExceptionAction<String>() {
    @Override
    public String run() throws Exception {
      try {
        proxy = RPC.getProxy(TestProtocol.class,
            TestProtocol.versionID, addr, conf);
        String ret = proxy.aMethod();
        return ret;
      } catch (Exception e) {
        e.printStackTrace();
        throw e;
      } finally {
        server.stop();
        if (proxy != null) {
          RPC.stopProxy(proxy);
        }
      }
    }
  });
  //The user returned by server must be the one in the token.
  Assert.assertEquals(REAL_USER_NAME + " (auth:TOKEN) via SomeSuperUser (auth:SIMPLE)", retVal);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:50,代码来源:TestDoAsEffectiveUser.java


示例2: testTokenBySuperUser

import org.apache.hadoop.ipc.TestSaslRPC.TestTokenSecretManager; //导入依赖的package包/类
@Test
public void testTokenBySuperUser() throws Exception {
  TestTokenSecretManager sm = new TestTokenSecretManager();
  final Configuration newConf = new Configuration(masterConf);
  SecurityUtil.setAuthenticationMethod(AuthenticationMethod.KERBEROS, newConf);
  UserGroupInformation.setConfiguration(newConf);
  final Server server = new RPC.Builder(newConf)
      .setProtocol(TestProtocol.class).setInstance(new TestImpl())
      .setBindAddress(ADDRESS).setPort(0).setNumHandlers(5).setVerbose(true)
      .setSecretManager(sm).build();

  server.start();

  final UserGroupInformation current = UserGroupInformation
      .createUserForTesting(REAL_USER_NAME, GROUP_NAMES);
  
  refreshConf(newConf);
  
  final InetSocketAddress addr = NetUtils.getConnectAddress(server);
  TestTokenIdentifier tokenId = new TestTokenIdentifier(new Text(current
      .getUserName()), new Text("SomeSuperUser"));
  Token<TestTokenIdentifier> token = new Token<TestTokenIdentifier>(tokenId,
      sm);
  SecurityUtil.setTokenService(token, addr);
  current.addToken(token);
  String retVal = current.doAs(new PrivilegedExceptionAction<String>() {
    @Override
    public String run() throws Exception {
      try {
        proxy = RPC.getProxy(TestProtocol.class,
            TestProtocol.versionID, addr, newConf);
        String ret = proxy.aMethod();
        return ret;
      } catch (Exception e) {
        e.printStackTrace();
        throw e;
      } finally {
        server.stop();
        if (proxy != null) {
          RPC.stopProxy(proxy);
        }
      }
    }
  });
  String expected = REAL_USER_NAME + " (auth:TOKEN) via SomeSuperUser (auth:SIMPLE)";
  Assert.assertEquals(retVal + "!=" + expected, expected, retVal);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:48,代码来源:TestDoAsEffectiveUser.java


示例3: testProxyWithToken

import org.apache.hadoop.ipc.TestSaslRPC.TestTokenSecretManager; //导入依赖的package包/类
@Test
public void testProxyWithToken() throws Exception {
  final Configuration conf = new Configuration(masterConf);
  TestTokenSecretManager sm = new TestTokenSecretManager();
  conf
      .set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
  UserGroupInformation.setConfiguration(conf);
  final Server server = RPC.getServer(new TestImpl(),
      ADDRESS, 0, 5, true, conf, sm);

  server.start();

  final UserGroupInformation current = UserGroupInformation
      .createRemoteUser(REAL_USER_NAME);
  final InetSocketAddress addr = NetUtils.getConnectAddress(server);
  TestTokenIdentifier tokenId = new TestTokenIdentifier(new Text(current
      .getUserName()), new Text("SomeSuperUser"));
  Token<TestTokenIdentifier> token = new Token<TestTokenIdentifier>(tokenId,
      sm);
  SecurityUtil.setTokenService(token, addr);
  UserGroupInformation proxyUserUgi = UserGroupInformation
      .createProxyUserForTesting(PROXY_USER_NAME, current, GROUP_NAMES);
  proxyUserUgi.addToken(token);
  
  refreshConf(conf);
  
  String retVal = proxyUserUgi.doAs(new PrivilegedExceptionAction<String>() {
    @Override
    public String run() throws Exception {
      try {
        proxy = (TestProtocol) RPC.getProxy(TestProtocol.class,
            TestProtocol.versionID, addr, conf);
        String ret = proxy.aMethod();
        return ret;
      } catch (Exception e) {
        e.printStackTrace();
        throw e;
      } finally {
        server.stop();
        if (proxy != null) {
          RPC.stopProxy(proxy);
        }
      }
    }
  });
  //The user returned by server must be the one in the token.
  Assert.assertEquals(REAL_USER_NAME + " via SomeSuperUser", retVal);
}
 
开发者ID:Seagate,项目名称:hadoop-on-lustre,代码行数:49,代码来源:TestDoAsEffectiveUser.java


示例4: testTokenBySuperUser

import org.apache.hadoop.ipc.TestSaslRPC.TestTokenSecretManager; //导入依赖的package包/类
@Test
public void testTokenBySuperUser() throws Exception {
  TestTokenSecretManager sm = new TestTokenSecretManager();
  final Configuration newConf = new Configuration(masterConf);
  newConf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION,
      "kerberos");
  UserGroupInformation.setConfiguration(newConf);
  final Server server = RPC.getServer(new TestImpl(),
      ADDRESS, 0, 5, true, newConf, sm);

  server.start();

  final UserGroupInformation current = UserGroupInformation
      .createUserForTesting(REAL_USER_NAME, GROUP_NAMES);
  refreshConf(newConf);
  
  final InetSocketAddress addr = NetUtils.getConnectAddress(server);
  TestTokenIdentifier tokenId = new TestTokenIdentifier(new Text(current
      .getUserName()), new Text("SomeSuperUser"));
  Token<TestTokenIdentifier> token = new Token<TestTokenIdentifier>(tokenId,
      sm);
  SecurityUtil.setTokenService(token, addr);
  current.addToken(token);
  String retVal = current.doAs(new PrivilegedExceptionAction<String>() {
    @Override
    public String run() throws Exception {
      try {
        proxy = (TestProtocol) RPC.getProxy(TestProtocol.class,
            TestProtocol.versionID, addr, newConf);
        String ret = proxy.aMethod();
        return ret;
      } catch (Exception e) {
        e.printStackTrace();
        throw e;
      } finally {
        server.stop();
        if (proxy != null) {
          RPC.stopProxy(proxy);
        }
      }
    }
  });
  String expected = REAL_USER_NAME + " via SomeSuperUser";
  Assert.assertEquals(retVal + "!=" + expected, expected, retVal);
}
 
开发者ID:Seagate,项目名称:hadoop-on-lustre,代码行数:46,代码来源:TestDoAsEffectiveUser.java



注:本文中的org.apache.hadoop.ipc.TestSaslRPC.TestTokenSecretManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MaxDirectoryItemsExceededException类代码示例发布时间:2022-05-22
下一篇:
Java StatusLine类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap