use of com.google.common.annotations.VisibleForTesting in project hadoop by apache.
the class DelegationTokenAuthenticationHandler method initTokenManager.
@VisibleForTesting
@SuppressWarnings("unchecked")
public void initTokenManager(Properties config) {
Configuration conf = new Configuration(false);
for (Map.Entry entry : config.entrySet()) {
conf.set((String) entry.getKey(), (String) entry.getValue());
}
String tokenKind = conf.get(TOKEN_KIND);
if (tokenKind == null) {
throw new IllegalArgumentException("The configuration does not define the token kind");
}
tokenKind = tokenKind.trim();
tokenManager = new DelegationTokenManager(conf, new Text(tokenKind));
tokenManager.init();
}
use of com.google.common.annotations.VisibleForTesting in project hadoop by apache.
the class DelegationTokenAuthenticationHandler method initJsonFactory.
@VisibleForTesting
public void initJsonFactory(Properties config) {
boolean hasFeature = false;
JsonFactory tmpJsonFactory = new JsonFactory();
for (Map.Entry entry : config.entrySet()) {
String key = (String) entry.getKey();
if (key.startsWith(JSON_MAPPER_PREFIX)) {
JsonGenerator.Feature feature = JsonGenerator.Feature.valueOf(key.substring(JSON_MAPPER_PREFIX.length()));
if (feature != null) {
hasFeature = true;
boolean enabled = Boolean.parseBoolean((String) entry.getValue());
tmpJsonFactory.configure(feature, enabled);
}
}
}
if (hasFeature) {
jsonFactory = tmpJsonFactory;
}
}
use of com.google.common.annotations.VisibleForTesting in project hadoop by apache.
the class ShellBasedUnixGroupsMapping method resolveFullGroupNames.
/**
* Split group names into a linked list.
*
* @param groupNames a string representing the user's group names
* @return a linked list of group names
*/
@VisibleForTesting
protected List<String> resolveFullGroupNames(String groupNames) {
StringTokenizer tokenizer = new StringTokenizer(groupNames, Shell.TOKEN_SEPARATOR_REGEX);
List<String> groups = new LinkedList<String>();
while (tokenizer.hasMoreTokens()) {
groups.add(tokenizer.nextToken());
}
return groups;
}
use of com.google.common.annotations.VisibleForTesting in project hadoop by apache.
the class SecureIOUtils method forceSecureOpenFSDataInputStream.
/**
* Same as openFSDataInputStream except that it will run even if security is
* off. This is used by unit tests.
*/
@VisibleForTesting
protected static FSDataInputStream forceSecureOpenFSDataInputStream(File file, String expectedOwner, String expectedGroup) throws IOException {
final FSDataInputStream in = rawFilesystem.open(new Path(file.getAbsolutePath()));
boolean success = false;
try {
Stat stat = NativeIO.POSIX.getFstat(in.getFileDescriptor());
checkStat(file, stat.getOwner(), stat.getGroup(), expectedOwner, expectedGroup);
success = true;
return in;
} finally {
if (!success) {
in.close();
}
}
}
use of com.google.common.annotations.VisibleForTesting in project hadoop by apache.
the class SecureIOUtils method forceSecureOpenForRead.
/**
* Same as openForRead() except that it will run even if security is off.
* This is used by unit tests.
*/
@VisibleForTesting
protected static FileInputStream forceSecureOpenForRead(File f, String expectedOwner, String expectedGroup) throws IOException {
FileInputStream fis = new FileInputStream(f);
boolean success = false;
try {
Stat stat = NativeIO.POSIX.getFstat(fis.getFD());
checkStat(f, stat.getOwner(), stat.getGroup(), expectedOwner, expectedGroup);
success = true;
return fis;
} finally {
if (!success) {
fis.close();
}
}
}
Aggregations