Perform all the magic required to get the proxyUser in a securitized grid

@return a UserGroupInformation object for the specified userToProxy, which will also contain
the logged in user's tokens
323685
private static UserGroupInformation createSecurityEnabledProxyUser(String userToProxy,
      String fileLocation, Logger log
  ) throws IOException {

    if (!new File(fileLocation).exists()) {
      throw new RuntimeException("hadoop token file doesn't exist.");
    }

    log.info("Found token file.  Setting " + HadoopSecurityManager.MAPREDUCE_JOB_CREDENTIALS_BINARY
        + " to " + fileLocation);
    System.setProperty(HadoopSecurityManager.MAPREDUCE_JOB_CREDENTIALS_BINARY, fileLocation);

    UserGroupInformation loginUser = null;

    loginUser = UserGroupInformation.getLoginUser();
    log.info("Current logged in user is " + loginUser.getUserName());

    UserGroupInformation proxyUser = UserGroupInformation.createProxyUser(userToProxy, loginUser);

    for (Token<?> token : loginUser.getTokens()) {
      proxyUser.addToken(token);
    }
    proxyUser.addCredentials(loginUser.getCredentials());
    return proxyUser;
  }
583900
def get_securitygroup(self, group_id, **kwargs):
        
        if 'mask' not in kwargs:
            kwargs['mask'] = (
                'id,'
                'name,'
                'description,'
                '''rules[id, remoteIp, remoteGroupId,
                         direction, ethertype, portRangeMin,
                         portRangeMax, protocol, createDate, modifyDate],'''
                '''networkComponentBindings[
                    networkComponent[
                        id,
                        port,
                        guest[
                            id,
                            hostname,
                            primaryBackendIpAddress,
                            primaryIpAddress
                        ]
                    ]
                ]'''
            )

        return self.security_group.getObject(id=group_id, **kwargs)
451581
protected function proxy() {
        if (!$this->context) {
            $this->context = new MemberContext(
                $this->version,
                $this->solution['accountSid'],
                $this->solution['queueSid'],
                $this->solution['callSid']
            );
        }

        return $this->context;
    }
1331419
protected function proxy() {
        if (!$this->context) {
            $this->context = new UserContext(
                $this->version,
                $this->solution['serviceSid'],
                $this->solution['sid']
            );
        }

        return $this->context;
    }
946161
@Builder(builderClassName = "ProxiedFileSystemFromKeytab", builderMethodName = "fromKeytab")
  private static FileSystem getProxiedFileSystemUsingKeytab(@NonNull final String userNameToProxyAs,
      final String superUserName, final Path superUserKeytabLocation, final URI fsURI, final Configuration conf,
      FileSystem referenceFS) throws IOException, ExecutionException {
    Preconditions.checkNotNull(userNameToProxyAs, "Must provide a user name to proxy as.");
    Preconditions.checkNotNull(superUserName, "Must provide a super user name.");
    Preconditions.checkNotNull(superUserKeytabLocation, "Must provide a keytab location.");
    URI actualURI = resolveUri(fsURI, conf, referenceFS);
    Configuration actualConfiguration = resolveConfiguration(conf, referenceFS);

    return USER_NAME_TO_FILESYSTEM_CACHE.get(getFileSystemKey(actualURI, userNameToProxyAs, referenceFS),
        new CreateProxiedFileSystemFromKeytab(userNameToProxyAs, superUserName, superUserKeytabLocation, actualURI,
            actualConfiguration, referenceFS));
  }
1112836
public static String getUser(String userName, UserGroupInformation ugi) {
        if (StringUtils.isNotEmpty(userName)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Returning userName {}", userName);
            }
            return userName;
        }

        if (ugi != null && StringUtils.isNotEmpty(ugi.getShortUserName())) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Returning ugi.getShortUserName {}", userName);
            }
            return ugi.getShortUserName();
        }

        try {
            return UserGroupInformation.getCurrentUser().getShortUserName();
        } catch (IOException e) {
            LOG.warn("Failed for UserGroupInformation.getCurrentUser() ", e);
            return System.getProperty("user.name");
        }
    }
1074979
@Override
    public Set<Node> getGroupsForUser(Node user) {
        Set<Node> groups = new TreeSet<>();
        try {
            String query = "(& (objectClass=" + groupObjectClass + ") (" + groupMemberAttribut + "=" + ((LdapUser) user).getDn() + "))";
            SearchResult searchResult;
            Attributes attributes;
            SearchControls controls = new SearchControls();
            controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
            NamingEnumeration<SearchResult> results = ctx.search("", query, controls);
            queryCount++;
            Node group;
            while (results.hasMore()) {
                searchResult = results.next();
                attributes = searchResult.getAttributes();
                group = getGroup(getAttributeOrNa(attributes, groupIdentifyer));
                group.setDn(searchResult.getNameInNamespace());
                groups.add(group);
            }
        } catch (NamingException ex) {
            handleNamingException(user, ex);
        }
        return groups;
    }
770267
public User getUser() {
        ClientResource resource = new ClientResource(Route.ME.url());
        resource.setChallengeResponse(this.auth.toChallenge());

        try {
            Representation repr = resource.get();
            return mapper.readValue(repr.getText(), User.class);
        } catch (IOException ex) {
            LEX4JLogger.log(Level.WARNING, "Could not retrieve user (me) correctly!");
            return null;
        }
    }
622700
public static synchronized UnixUserGroupInformation getUgiForUser(
      String userName) {
    long now = System.currentTimeMillis();
    long cutoffTime = now - ugiLifetime;
    CachedUgi cachedUgi = ugiCache.get(userName);
    if (cachedUgi != null && cachedUgi.getInitTime() > cutoffTime)
      return cachedUgi.getUgi();
    UnixUserGroupInformation ugi = null;
    try {
      ugi = getUgi(userName);
    } catch (IOException e) {
      return null;
    }
    if (ugiCache.size() > CLEANUP_THRESHOLD) { // remove expired ugi's first
      for (Iterator<Map.Entry<String, CachedUgi>> it = ugiCache.entrySet()
          .iterator(); it.hasNext();) {
        Map.Entry<String, CachedUgi> e = it.next();
        if (e.getValue().getInitTime() < cutoffTime) {
          it.remove();
        }
      }
    }
    ugiCache.put(ugi.getUserName(), new CachedUgi(ugi, now));
    return ugi;
  }
762544
public SecurityProvider getSecurityProvider() {
        checkState(InitializedState.INITIALIZED, InitializedState.INITIALIZED);
        List<SecurityProvider> securityProviders = aggregatedModule.getSecurityProviders();
        return new AggregatedSecurityProvider(securityProviders);
    }
525830
public GetUsersTopArtistsRequest.Builder getUsersTopArtists() {
    return new GetUsersTopArtistsRequest.Builder(accessToken)
            .setDefaults(httpManager, scheme, host, port);
  }
965287
@Override
    public Set<Node> getUsersForGroup(Node group) {
		Set<Node> users = new TreeSet<>();
		try {
			String query = "(" + groupIdentifyer + "=" + group.getName() + ")";
			SearchResult searchResult;
			Attributes attributes;
			SearchControls controls = new SearchControls();
			controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
			NamingEnumeration<SearchResult> results = ctx.search("", query, controls);
			Node user;
			while (results.hasMore()) {
				searchResult = results.next();
				attributes = searchResult.getAttributes();
				NamingEnumeration<?> members = attributes.get(groupMemberAttribut).getAll();
				while (members.hasMoreElements()) {
					String memberDN = (String) members.nextElement();
					String uid = getIdentifyerValueFromDN(memberDN);
					user = getUser(uid);
					user.setDn(memberDN);
					users.add(user);
				}
			}
		} catch (NamingException ex) {
			handleNamingException(group, ex);
		}
		return users;
	}
946875
public static systemgroup_systemuser_binding[] get(nitro_service service, String groupname) throws Exception{
		systemgroup_systemuser_binding obj = new systemgroup_systemuser_binding();
		obj.set_groupname(groupname);
		systemgroup_systemuser_binding response[] = (systemgroup_systemuser_binding[]) obj.get_resources(service);
		return response;
	}
1105063
public String getAuthorityMinusUserinfo()
    throws URIException {
        if (this.cachedAuthorityMinusUserinfo == null) {
            String tmp = getAuthority();
            if (tmp != null && tmp.length() > 0) {
            	int index = tmp.indexOf('@');
                if (index >= 0 && index < tmp.length()) {
                    tmp = tmp.substring(index + 1);
                }
            }
            this.cachedAuthorityMinusUserinfo = tmp;
            coalesceHostAuthorityStrings();
        }
        return this.cachedAuthorityMinusUserinfo;
	}
49490
public static UserInfo getUserInfo(final String userId) {

        if (userId == null) {
            throw new IllegalArgumentException("null userName");
        }

        try {
            Class<?> accessor = Class.forName("com.sap.security.um.service.UserManagementAccessor");
            if (accessor != null) {
                Object users = MethodUtils.invokeExactStaticMethod(accessor, "getUserProvider", null);
                if (users != null) {
                    Object user = MethodUtils.invokeExactMethod(users, "getUser", userId);
                    if (user != null) {
                        // get user name and email
                        return new User(
                                userId,
                                (String) MethodUtils.invokeExactMethod(user, "getAttribute", "firstname"),
                                (String) MethodUtils.invokeExactMethod(user, "getAttribute", "lastname"),
                                (String) MethodUtils.invokeExactMethod(user, "getAttribute", "email"));

                    }
                }
            }
        } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            log.warn(e.getMessage());
        }
        return new User(userId, "", "", "");
    }
460568
public List<SecurityUserBean> getUsers() {
        List<SecurityUserBean> users = new ArrayList<SecurityUserBean>();
        for (DuracloudUserDetails user : this.usersTable.values()) {
            SecurityUserBean bean = createUserBean(user);
            users.add(bean);
        }
        return users;
    }
1201877
public SipPrincipal getUserPrincipal() {
		if(this.userPrincipal == null) {
			if(this.getSipSession() != null) {
				this.userPrincipal = this.getSipSession().getUserPrincipal();
			}
		}
		return this.userPrincipal;
	}