Symfony Security-检查服务构造函数中的用户角色

时间:2019-01-05 12:03:01

标签: symfony security

我需要检查用户是否对服务具有管理员权限。对于单个请求,可能会多次调用此服务中正在调用的函数。可以一次检查用户的角色并保存如下结果:

interface Resource {
  id: string;
}

interface ResourceState<T> {
  data: T;
  hash: string;
}

abstract class ResourceComponent<R extends Resource> {
  protected state: ResourceState<R> = {
    data: { // Type checking KO
      id: ''
    },
    hash: ''
  };
}

// Doesn't suit my use case
// abstract class ResourceComponent<Resource> {
//   protected state: ResourceState<Resource> = {
//     data: {
//       id: null
//     },
//     hash: ''
//   };
// }

interface Model extends Resource {
  name: string;
}

class ModelComponent extends ResourceComponent<Model> {
  constructor() {
    super();
    this.state.data.name = 'ModelComponent'; // Type checking OK
    this.state.data.age = 20; // Type checking OK
    console.log(this.state.data);
  }
}

const component = new ModelComponent();

当我在本地测试时,这似乎工作得很好。 我想知道此设置是否有问题,或者是否会导致奇怪/不需要的结果。

0 个答案:

没有答案