accessToken = twitterConnection.getOAuthAccessToken (requestToken,editPinCode.getText().toString()); oHelper.storeAccessToken(accessToken); Log.i("Access Token:", accessToken.getToken()); Log.i("Access Secret:", accessToken.getTokenSecret()); long userID = accessToken.getUserId(); User user = twitterConnection.showUser(userID); user.getName();
public class UserValidator implements Validator { @Override public boolean supports(Class clazz) { return User.class.equals(clazz); } @Override public void validate(Object target, Errors errors) { User user = (User) target; if(user.getName() == null) { errors.rejectValue("name", "your_error_code"); } // do "complex" validation here } }
/** * @return the userName for the current logged-in user. * @throws IOException if the underlying user cannot be obtained */ public String getCurrentUserName() throws IOException { User user = getCurrent(); return user == null ? null : user.getName(); }
@Override public String run() throws IOException { User u = User.getCurrent(); return u.getName(); } };
@Override public String run() throws Exception { return User.getCurrent().getName(); } });
@Override public String run() { try { return User.getCurrent().getName(); } catch (IOException e) { result = "empty"; } return result; } });
public static void configureSuperuser(Configuration conf) throws IOException { // The secure minicluster creates separate service principals based on the // current user's name, one for each slave. We need to add all of these to // the superuser list or security won't function properly. We expect the // HBase service account(s) to have superuser privilege. String currentUser = User.getCurrent().getName(); StringBuilder sb = new StringBuilder(); sb.append("admin,"); sb.append(currentUser); // Assumes we won't ever have a minicluster with more than 5 slaves for (int i = 0; i < 5; i++) { sb.append(','); sb.append(currentUser); sb.append(".hfs."); sb.append(i); } conf.set("hbase.superuser", sb.toString()); }
@Override public Object run() throws Exception { int numRows = 3; // Making the assumption that the test table won't split between the range byte[][][] hfileRanges = { { { (byte) 0 }, { (byte) 9 } } }; Path bulkLoadBasePath = new Path(dir, new Path(User.getCurrent().getName())); new BulkLoadHelper(bulkLoadBasePath).initHFileData(TEST_FAMILY, TEST_QUALIFIER, hfileRanges, numRows, FS_PERMISSION_ALL).bulkLoadHFile(TEST_TABLE); return null; } };
@Override public Object run() throws Exception { FileSystem fs = TEST_UTIL.getTestFileSystem(); fs.mkdirs(testDataDir); fs.setPermission(testDataDir, FS_PERMISSION_ALL); // Making the assumption that the test table won't split between the range byte[][][] hfileRanges = { { { (byte) 0 }, { (byte) 9 } } }; Path bulkLoadBasePath = new Path(testDataDir, new Path(User.getCurrent().getName())); new BulkLoadHelper(bulkLoadBasePath) .initHFileData(TEST_FAMILY, TEST_QUALIFIER, hfileRanges, 3, filePermission) .bulkLoadHFile(TEST_TABLE); return null; } }
private void addLabels() throws Exception { try { VisibilityClient.addLabels(util.getConnection(), labels.split(COMMA)); VisibilityClient.setAuths(util.getConnection(), labels.split(COMMA), USER.getName()); } catch (Throwable t) { throw new IOException(t); } }
public static UserInformation toProtoUserInfo(User user) { UserInformation.Builder userInfoPB = UserInformation.newBuilder(); userInfoPB.setEffectiveUser(user.getName()); if (user.getUGI().getRealUser() != null) { userInfoPB.setRealUser(user.getUGI().getRealUser().getUserName()); } return userInfoPB.build(); }
private void addLabelsAndAuths() throws Exception { try { VisibilityClient.addLabels(util.getConnection(), LABELS); VisibilityClient.setAuths(util.getConnection(), new String[] { CONFIDENTIAL, TOPSECRET, SECRET, PRIVATE }, USER1.getName()); VisibilityClient.setAuths(util.getConnection(), new String[] { PUBLIC }, USER2.getName()); } catch (Throwable t) { throw new IOException(t); } }
@Test public void testBasicAttributes() throws Exception { Configuration conf = HBaseConfiguration.create(); User user = User.createUserForTesting(conf, "simple", new String[]{"foo"}); assertEquals("Username should match", "simple", user.getName()); assertEquals("Short username should match", "simple", user.getShortName()); // don't test shortening of kerberos names because regular Hadoop doesn't support them }
private void addLabels() throws Exception { try { VisibilityClient.addLabels(util.getConnection(), LABELS); VisibilityClient.setAuths(util.getConnection(), LABELS, User.getCurrent().getName()); } catch (Throwable t) { throw new IOException(t); } } }
@Override public Object run() throws IOException, InterruptedException{ String nestedName = user.runAs(action); assertEquals("Nest name should match nested user", "testuser", nestedName); assertEquals("Current name should match current user", "testuser2", User.getCurrent().getName()); return null; } });
@Override public void setUpCluster() throws Exception { util = getTestingUtil(null); Configuration conf = util.getConfiguration(); VisibilityTestUtil.enableVisiblityLabels(conf); conf.set("hbase.superuser", User.getCurrent().getName()); conf.setBoolean("dfs.permissions", false); USER = User.createUserForTesting(conf, userName, new String[] {}); super.setUpCluster(); addLabels(); }
@Override public void setUpCluster() throws Exception { util = getTestingUtil(null); Configuration conf = util.getConfiguration(); VisibilityTestUtil.enableVisiblityLabels(conf); conf.set("hbase.superuser", "admin," + User.getCurrent().getName()); super.setUpCluster(); addLabels(); }
@Test public void testAuthUtilLogin() throws Exception { String clientKeytab = getClientKeytabForTesting(); String clientPrincipal = getClientPrincipalForTesting(); Configuration conf = getSecuredConfiguration(); conf.set(AuthUtil.HBASE_CLIENT_KEYTAB_FILE, clientKeytab); conf.set(AuthUtil.HBASE_CLIENT_KERBEROS_PRINCIPAL, clientPrincipal); UserGroupInformation.setConfiguration(conf); User user = AuthUtil.loginClient(conf); assertTrue(user.isLoginFromKeytab()); assertEquals(CLIENT_NAME, user.getShortName()); assertEquals(getClientPrincipalForTesting(), user.getName()); } }
@BeforeClass public static void provisionCluster() throws Exception { conf = util.getConfiguration(); SUPERUSER = User.createUserForTesting(conf, "admin", new String[] { "supergroup" }); conf.set("hbase.superuser", "admin,"+User.getCurrent().getName()); VisibilityTestUtil.enableVisiblityLabels(conf); conf.setClass(VisibilityUtils.VISIBILITY_LABEL_GENERATOR_CLASS, SimpleScanLabelGenerator.class, ScanLabelGenerator.class); util.startMiniCluster(); // Wait for the labels table to become available util.waitTableEnabled(VisibilityConstants.LABELS_TABLE_NAME.getName(), 50000); createLabels(); }
@BeforeClass public static void setupBeforeClass() throws Exception { // setup configuration conf = TEST_UTIL.getConfiguration(); VisibilityTestUtil.enableVisiblityLabels(conf); String currentUser = User.getCurrent().getName(); conf.set("hbase.superuser", "admin,"+currentUser); TEST_UTIL.startMiniCluster(2); // Wait for the labels table to become available TEST_UTIL.waitTableEnabled(LABELS_TABLE_NAME.getName(), 50000); SUPERUSER = User.createUserForTesting(conf, "admin", new String[] { "supergroup" }); NORMAL_USER = User.createUserForTesting(conf, "user1", new String[] {}); NORMAL_USER1 = User.createUserForTesting(conf, "user2", new String[] {}); addLabels(); }