Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring MVC/Security无静态基于角色的身份验证_Spring_Spring Mvc_Authentication_Spring Security_Spring Annotations - Fatal编程技术网

Spring MVC/Security无静态基于角色的身份验证

Spring MVC/Security无静态基于角色的身份验证,spring,spring-mvc,authentication,spring-security,spring-annotations,Spring,Spring Mvc,Authentication,Spring Security,Spring Annotations,我没有通过xml实现基于SpringMVC的java应用程序。如何为每个控制器方法设置基于rol的身份验证 我不想像下面的代码那样,静态角色名facultyMember: @PreAuthorize("hasRole('facultyMember')") public Newsletter getFacultyNews() { } 尽管将访问服务的权限设置为动态权限似乎有些奇怪,但您可以尝试使用外部属性文件: 在应用程序上下文中: <bean id="myProp" class="org

我没有通过xml实现基于SpringMVC的java应用程序。如何为每个控制器方法设置基于rol的身份验证

我不想像下面的代码那样,静态角色名
facultyMember

@PreAuthorize("hasRole('facultyMember')")
public Newsletter getFacultyNews() { }

尽管将访问服务的权限设置为动态权限似乎有些奇怪,但您可以尝试使用外部属性文件:

在应用程序上下文中:

<bean id="myProp" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="locations">
         <list>
              <value>file:///pathToExternalPropertyFile/myProp.properties</value>
           </list>
    </property>
</bean>

那你怎么不授权呢?我想在运行时更改授权。例如:x person authorized controller方法,之后我将更改为not authorized此方法。角色只不过是权限(尽管名称可能会误导)。角色基本上只是权限的集合。为什么要更改访问应用程序某部分所需的权限?这应该是相当静态的。问题是,例如,当我们决定进行更改时,也许应该允许助教阅读教员通讯,我们也必须进入代码进行更改:
@PreAuthorize(“hasRole('facultyMember')或hasRole('TeachingAsistant'))公共通讯getFacultyNews(){…}
这是新版本的原因。我不想这样做。请检查我编辑的答案,它可以由外部文件控制
@Value("#{myProp['dynamicRole']}")
private String dynamicRole;

@PreAuthorize("hasRole('"+dynamicRole +"')")
public Newsletter getFacultyNews() { }