标签: access-protection

我们能否增加这种面向密钥的访问保护模式的可重用性?

我们是否可以增加这种面向密钥的访问保护模式的可重用性:

class SomeKey { 
    friend class Foo;
    // more friends... ?
    SomeKey() {} 
    // possibly non-copyable too
};

class Bar {
public:
    void protectedMethod(SomeKey); // only friends of SomeKey have access
};
Run Code Online (Sandbox Code Playgroud)

为了避免持续的误解,这种模式不同于律师 - 客户的习惯用语:

  • 它可以比律师 - 客户更简洁(因为它不涉及通过第三类代理)
  • 它可以允许授权访问权限
  • ...但它对原始类也更具侵入性(每个方法一个虚拟参数)

(在这个问题中提出了一个侧面讨论,因此我打开了这个问题.)

c++ design-patterns idioms friend access-protection

26
推荐指数
1
解决办法
4417
查看次数

如何命名这种面向密钥的访问保护模式?

显然,这种面向密钥的访问保护模式:

class SomeKey { 
    friend class Foo;
    SomeKey() {} 
    // possibly non-copyable too
};

class Bar {
public:
    void protectedMethod(SomeKey); // only friends of SomeKey have access
};
Run Code Online (Sandbox Code Playgroud)

......还没有一个已知的名字,因此我想找到一个好的名字,所以我们可以在不断言的情况下参考它.建议?

它应该是:

  • 简洁
  • 传达访问保护的意图
  • 理想情况下不需要代理(?)

c++ design-patterns idioms friend access-protection

18
推荐指数
2
解决办法
2656
查看次数

如何防止直接访问图像?

我想创建一个包含许多图像的网站.但我想防止直接访问图像,例如直接链接到图像而无需访问网站.

这样做的首选方法是什么?有利有弊的替代方案是什么?

我有一些想法(我不知道它们是否可行):

  • 文件权限
  • PHP会话
  • 临时文件名或URL
  • HTTP重定向?

也许这在许多网站上都没有实践过?例如,我试图访问Facebook上的私人照片,但没有登录,但我仍然可以访问照片.

该平台可能是一台带有NginX和PHP的Ubuntu机器.

security image hotlinking access-protection

17
推荐指数
3
解决办法
3万
查看次数

如何隐藏除T类之外的所有人的数据

我想要一个类型A,它将隐藏的数据输出到类型为T的对象,但是隐藏其他人的数据.我的C++编译器碰巧是GCC 4.4,但这并不重要.为什么这不起作用?

#include <iostream>

template <class T> class A {
  private:
    int n1;
  public:
    friend class T;
    A(const int n0 = 0) : n1(n0) {}
};

class B {
  public:
    int f(const A<B> a) const { return a.n1; }
    B() {}
};

int main() {
    const A<B> a(5);
    const B b;
    const int m = b.f(a);
    std::cout << m << "\n";
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

顺便说一下,这样可以正常工作,除了它无法隐藏数据:

#include <iostream>

template <class T> class A {
  private:
    int n1; …
Run Code Online (Sandbox Code Playgroud)

c++ templates information-hiding friend access-protection

5
推荐指数
1
解决办法
216
查看次数