class AmbariProxiedUserDetailsService implements UserDetailsService {

  boolean validateGroup(AmbariTProxyConfiguration tProxyConfiguration, String proxyUserName, UserEntity userEntity) {
    String allowedGroups = tProxyConfiguration.getAllowedGroups(proxyUserName);

    if (StringUtils.isNotEmpty(allowedGroups)) {
      Set<String> groupSpecs = Arrays.stream(allowedGroups.split("\\s*,\\s*"))
          .map(s -> s.trim().toLowerCase())
          .collect(toSet());

      if (groupSpecs.contains("*")) {
        return true;
      } else {
        Set<MemberEntity> memberEntities = userEntity.getMemberEntities();
        if (memberEntities != null) {
          for (MemberEntity memberEntity : memberEntities) {
            GroupEntity group = memberEntity.getGroup();
            if (group != null) {
              String groupName = group.getGroupName();
              if (StringUtils.isNotEmpty(groupName) && groupSpecs.contains(groupName.toLowerCase())) {
                return true;
              }
            }
          }
        }
      }
    }

    return false;
  }

    AmbariProxiedUserDetailsService(Configuration configuration, Users users);

}