Java Code Examples for org.apache.hadoop.security.SecurityUtil#getSubject()

The following examples show how to use org.apache.hadoop.security.SecurityUtil#getSubject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestConfiguredPolicy.java    From RDFS with Apache License 2.0 6 votes vote down vote up
public void testConfiguredPolicy() throws Exception {
  Configuration conf = new Configuration();
  conf.set(KEY_1, AccessControlList.WILDCARD_ACL_VALUE);
  conf.set(KEY_2, USER1 + " " + GROUPS1[0]);
  
  ConfiguredPolicy policy = new ConfiguredPolicy(conf, new TestPolicyProvider());
  SecurityUtil.setPolicy(policy);
  
  Subject user1 = 
    SecurityUtil.getSubject(new UnixUserGroupInformation(USER1, GROUPS1));

  // Should succeed
  ServiceAuthorizationManager.authorize(user1, Protocol1.class);
  
  // Should fail
  Subject user2 = 
    SecurityUtil.getSubject(new UnixUserGroupInformation(USER2, GROUPS2));
  boolean failed = false;
  try {
    ServiceAuthorizationManager.authorize(user2, Protocol2.class);
  } catch (AuthorizationException ae) {
    failed = true;
  }
  assertTrue(failed);
}
 
Example 2
Source File: Server.java    From RDFS with Apache License 2.0 6 votes vote down vote up
private void processHeader() throws IOException {
  DataInputStream in =
    new DataInputStream(new ByteArrayInputStream(data.array()));
  header.readFields(in);
  try {
    String protocolClassName = header.getProtocol();
    if (protocolClassName != null) {
      protocol = getProtocolClass(header.getProtocol(), conf);
    }
  } catch (ClassNotFoundException cnfe) {
    throw new IOException("Unknown protocol: " + header.getProtocol());
  }

  // TODO: Get the user name from the GSS API for Kerberbos-based security
  // Create the user subject
  user = SecurityUtil.getSubject(header.getUgi());
}
 
Example 3
Source File: TestConfiguredPolicy.java    From hadoop-gpu with Apache License 2.0 6 votes vote down vote up
public void testConfiguredPolicy() throws Exception {
  Configuration conf = new Configuration();
  conf.set(KEY_1, AccessControlList.WILDCARD_ACL_VALUE);
  conf.set(KEY_2, USER1 + " " + GROUPS1[0]);
  
  ConfiguredPolicy policy = new ConfiguredPolicy(conf, new TestPolicyProvider());
  SecurityUtil.setPolicy(policy);
  
  Subject user1 = 
    SecurityUtil.getSubject(new UnixUserGroupInformation(USER1, GROUPS1));

  // Should succeed
  ServiceAuthorizationManager.authorize(user1, Protocol1.class);
  
  // Should fail
  Subject user2 = 
    SecurityUtil.getSubject(new UnixUserGroupInformation(USER2, GROUPS2));
  boolean failed = false;
  try {
    ServiceAuthorizationManager.authorize(user2, Protocol2.class);
  } catch (AuthorizationException ae) {
    failed = true;
  }
  assertTrue(failed);
}
 
Example 4
Source File: Server.java    From hadoop-gpu with Apache License 2.0 6 votes vote down vote up
private void processHeader() throws IOException {
  DataInputStream in =
    new DataInputStream(new ByteArrayInputStream(data.array()));
  header.readFields(in);
  try {
    String protocolClassName = header.getProtocol();
    if (protocolClassName != null) {
      protocol = getProtocolClass(header.getProtocol(), conf);
    }
  } catch (ClassNotFoundException cnfe) {
    throw new IOException("Unknown protocol: " + header.getProtocol());
  }
  
  // TODO: Get the user name from the GSS API for Kerberbos-based security
  // Create the user subject
  user = SecurityUtil.getSubject(header.getUgi());
}