当前位置: 首页 > news >正文

京东电子商务网站建设目的在线学习建设网站

京东电子商务网站建设目的,在线学习建设网站,众筹网站开发价格,求职网pdf secured最近#xff0c;Grails用户邮件列表中的一个用户想知道在定义Secured注释时如何减少重复 。 在Java批注中指定属性的规则非常严格#xff0c;因此我看不到直接执行他所要求的方法的方法。 使用Groovy并没有真正的帮助#xff0c;因为Groovy类中的注释大部分与Ja… pdf secured 最近Grails用户邮件列表中的一个用户想知道在定义Secured注释时如何减少重复 。 在Java批注中指定属性的规则非常严格因此我看不到直接执行他所要求的方法的方法。 使用Groovy并没有真正的帮助因为Groovy类中的注释大部分与Java中的注释几乎相同数组值的语法除外。 当然Groovy现在支持注释中的闭包但这需要在插件中进行代码更改。 但是后来我想到了Jeff Brown最近在缓存插件中所做的一些工作。 Spring的缓存抽象API包括三个注释。 Cacheable CacheEvict和CachePut 。 我们正在考虑支持比这些注释所允许的更多的配置选项但是由于您无法对注释进行子类化因此我们决定使用AST转换来查找这些注释的版本当前具有与Spring注释相同的属性并进行转换有效的Spring注释。 因此我查看了Jeff的代码 它最终成为解决此问题的基础。 无法使用代码外部化权限列表因为您无法控制编译顺序。 因此我最终得到了一个不完美但可以使用的解决方案–我在项目根目录中寻找一个属性文件 roles.properties 。 格式很简单–密钥是每个权限列表的名称值是权限名称的列表以逗号分隔。 这是一个例子 adminsROLE_ADMIN, ROLE_SUPERADMIN switchUserROLE_SWITCH_USER editorsROLE_EDITOR, ROLE_ADMIN 这些键是用于新Authorities批注的值 package grails.plugins.springsecurity.annotation; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.codehaus.groovy.transform.GroovyASTTransformationClass; /** * author Burt Beckwith */ Target ({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE}) Retention (RetentionPolicy.RUNTIME) Inherited Documented GroovyASTTransformationClass ( grails.plugins.springsecurity.annotation.AuthoritiesTransformation ) public interface Authorities { /** * The property file key; the property value will be a * comma-delimited list of role names. * return the key */ String value(); } 例如这是一个使用新注释的控制器 Authorities ( admins ) class SecureController { Authorities ( editors ) def someAction() { ... } } 这等效于此控制器如果使用Authorities反编译则会看到两个注释 Secured ([ ROLE_ADMIN , ROLE_SUPERADMIN ]) class SecureController { Secured ([ ROLE_EDITOR , ROLE_ADMIN ]) def someAction() { ... } } AST转换类使用属性文件中指定的角色名称查找Authorities批注加载属性文件并添加新的Secured批注不会删除Authorities批注 package grails.plugins.springsecurity.annotation; import grails.plugins.springsecurity.Secured; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Properties; import org.codehaus.groovy.ast.ASTNode; import org.codehaus.groovy.ast.AnnotatedNode; import org.codehaus.groovy.ast.AnnotationNode; import org.codehaus.groovy.ast.ClassNode; import org.codehaus.groovy.ast.expr.ConstantExpression; import org.codehaus.groovy.ast.expr.Expression; import org.codehaus.groovy.ast.expr.ListExpression; import org.codehaus.groovy.control.CompilePhase; import org.codehaus.groovy.control.SourceUnit; import org.codehaus.groovy.transform.ASTTransformation; import org.codehaus.groovy.transform.GroovyASTTransformation; import org.springframework.util.StringUtils; /** * author Burt Beckwith */ GroovyASTTransformation (phaseCompilePhase.CANONICALIZATION) public class AuthoritiesTransformation implements ASTTransformation { protected static final ClassNode SECURED new ClassNode(Secured. class ); public void visit(ASTNode[] astNodes, SourceUnit sourceUnit) { try { ASTNode firstNode astNodes[ 0 ]; ASTNode secondNode astNodes[ 1 ]; if (!(firstNode instanceof AnnotationNode) || !(secondNode instanceof AnnotatedNode)) { throw new RuntimeException( Internal error: wrong types: firstNode.getClass().getName() / secondNode.getClass().getName()); } AnnotationNode rolesAnnotationNode (AnnotationNode) firstNode; AnnotatedNode annotatedNode (AnnotatedNode) secondNode; AnnotationNode secured createAnnotation(rolesAnnotationNode); if (secured ! null ) { annotatedNode.addAnnotation(secured); } } catch (Exception e) { // TODO e.printStackTrace(); } } protected AnnotationNode createAnnotation(AnnotationNode rolesNode) throws IOException { Expression value rolesNode.getMembers().get( value ); if (!(value ConstantExpression)) { (!(value instanceof ConstantExpression)) { // TODO System.out.println( annotation Authorities value isnt a ConstantExpression: value); return null ; } String fieldName value.getText(); String[] authorityNames getAuthorityNames(fieldName); if (authorityNames null ) { return null ; } return buildAnnotationNode(authorityNames); } protected AnnotationNode buildAnnotationNode(String[] names) { AnnotationNode securedAnnotationNode new AnnotationNode(SECURED); ListExpression nameExpressions new ArrayListExpression(); for (String authorityName : names) { nameExpressions.add( new ConstantExpression(authorityName)); } securedAnnotationNode.addMember( value , new ListExpression(nameExpressions)); return securedAnnotationNode; } protected String[] getAuthorityNames(String fieldName) throws IOException { Properties properties new Properties(); File propertyFile new File( roles.properties ); if (!propertyFile.exists()) { // TODO System.out.println( Property file roles.properties not found ); return null ; } properties.load( new FileReader(propertyFile)); Object value properties.getProperty(fieldName); if (value null ) { // TODO System.out.println( No value for property fieldName No value for property fieldName ); return null ; } ListString names new ArrayListString(); String[] nameArray StringUtils.commaDelimitedListToStringArray( value.toString()) for (String auth : nameArray) { auth auth.trim(); if (auth.length() 0 ) { names.add(auth); } } return names.toArray( new String[names.size()]); } } 我可能会在某个时候将其包含在插件中-我已提醒您创建了JIRA问题 -但现在您可以将这两个类复制到应用程序的src / java文件夹中并在项目根目录中创建一个roles.properties文件。 每当您要添加或删除条目或从条目添加或删除角色名称时请更新属性文件运行grails clean和grails compile以确保使用最新值。 参考在An Solipsists博客上由我们的JCG合作伙伴 Burt Beckwith 使您的Spring Security Secured注释更加干燥 。 翻译自: https://www.javacodegeeks.com/2012/06/make-your-spring-security-secured.htmlpdf secured
http://www.zqtcl.cn/news/761721/

相关文章:

  • 越南做网站网站建设以及运营方面
  • 广西建网站哪家好网站关闭与域名备案
  • 网站开发版本号婚庆网站建设策划案费用预算
  • 厦门建设网站制作中山市哪家公司做网站
  • 网站路径wordpress制作电商网站
  • 江西网站开发哪家专业装饰设计公司网站
  • 企业网站策划实训Wordpress 主题简化
  • 做网站点击挣钱不兰州工程建设信息网站
  • 网站说服力 营销...免费看片网站
  • 深圳招聘网站大全制作网站软件下载
  • 网站建设说明哈尔滨网站建设渠道
  • 一 网站建设管理基本情况设计类的网站
  • wordpress产品编辑如何优化wordpress
  • 网站后台更新缓存失败网站平台规划方案
  • 网站开发需求分析主要内容saas建站系统是怎么实现的
  • 做qq头像的网站有哪些wordpress怎么部署到虚拟linux服务器
  • 征求网站建设企业网站建设word
  • 市民服务中心网站建设小型公众号开发
  • 服装网站建设策划书论文基层建设刊物网站
  • 网站建设合同技术开发合同范本wordpress备份和还原
  • 物流信息平台网站建设一流本科专业建设点网站
  • 天猫网站建设的目标是什么装潢设计软件
  • 电商网站首页图片网站功能模块建设
  • 邮件服务器是不是网站服务器黄江网站建设公司
  • 科技部网站方案网页设计网站设计欣赏
  • 自贡建设机械网站网站策划与运营课程认知
  • 公司做网站该注意哪些廊坊seo
  • 网站开发目录高尔夫 wordpress
  • 三只松鼠网站建设不做网站做百家号
  • 石家庄网站关键词推广淘宝网站建设设计模板