简体   繁体   English

当Neos中的节点或方法被拒绝访问时,如何显示自定义404页面?

[英]How can I show a custom 404 page when access is denied to a node or method in Neos?

We're making a forum where access is supposed to be denied by unregistered users. 我们正在建立一个论坛,在该论坛中未注册用户应拒绝访问。 I want to show a proper error message - not an exception - for users that are not allowed there. 我想为不允许在那里的用户显示适当的错误消息-不是异常。 How do I achieve this in Neos 2.0? 如何在Neos 2.0中实现这一目标?

Both read and write access should be denied. 读写访问均应被拒绝。 Maybe it's easier to deny access to the node where the forum is? 也许拒绝访问论坛所在的节点更容易? But wouldn't that need hard-coding of node path? 但是那不需要对节点路径进行硬编码吗?

Current Policy.yaml : 当前Policy.yaml

privilegeTargets:

  'TYPO3\Flow\Security\Authorization\Privilege\Method\MethodPrivilege':

    'My.Package:PostControllerLoggedInActions':
        matcher: 'method(My\Package\PostController->(index|new|create)Action(.*))'

roles:

  'TYPO3.Flow:Everybody':
    privileges:
      -
        privilegeTarget: 'My.Package:PostControllerLoggedInActions'
        permission: DENY

  'My.Package:User':
    privileges:
      -
        privilegeTarget: 'My.Package:PostControllerLoggedInActions'
        permission: GRANT

Edit : Here are some slides about (among other things) how to create a custom 404 page: https://speakerdeck.com/aertmann/tasty-recipes-for-every-day-neos 编辑 :这是一些有关(除其他事项外)如何创建自定义404页面的幻灯片: https : //speakerdeck.com/aertmann/tasty-recipes-for-every-day-neos

Edit 2 : Use Flow exception handler? 编辑2 :使用Flow异常处理程序?

You can try to set it in your root Configuration/Settings.yaml . 您可以尝试在根Configuration/Settings.yaml You can do it by status code (like in example) or exception class: 您可以通过状态代码(例如示例)或异常类来实现:

TYPO3:
  Flow:
# you have already persistence
# and maybe other stuff under flow
# just add it below them but still under TYPO3.Flow
    error:
      exceptionHandler:
        renderingGroups:
          accessRestricted:
            matchingStatusCodes: [ 401, 403]
            options:
              templatePathAndFilename: 'resource://TYPO3.Neos/Private/Templates/Error/Index.html'
              layoutRootPath: 'resource://TYPO3.Neos/Private/Layouts/'
              format: 'html'
              variables:
                errorTitle: 'Restricted Area'
                errorDescription: 'Go home boy.'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM