Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Allow custom exception message for @Security annotation #311

Closed
wants to merge 1 commit into from
Closed

Allow custom exception message for @Security annotation #311

wants to merge 1 commit into from

Conversation

scaytrase
Copy link

Custom exception messages are essential to generate customized exception and error page views. Default message is not always acceptable to be displayed to the end user at least because of disclosing security expression used to restrict access.

@ghost
Copy link

ghost commented Sep 4, 2014

+1 Waiting for this feature

P.S. The message should be translable

@scaytrase
Copy link
Author

I think you can always make it translable with manually providing translation key instead of actual message and writing custom exception handler template with calling trans on exception.message. Hardcoding tranlsations can make this more complicated, I think.

{% extends '::base.html.twig' %}

{% block title %}{{ status_code }} - {{ status_text }}{% endblock %}

{% block body %}
    <h1 class="page-header">Error!</h1>

    <div class="jumbotron">
        <h2 class="text-center">{{ status_code }} - {{ status_text }}
            <br/>
            <small>{{ exception.message | trans }}</small>
        </h2>
        <div class="text-center">
            <button onclick="history.go(-1)" class="btn btn-success">Go back</button>
        </div>
    </div>
{% endblock %}

@apfelbox
Copy link
Contributor

Related to #196

@pleerock
Copy link

+1

1 similar comment
@sobit
Copy link
Contributor

sobit commented Dec 26, 2014

+1

The message parameter allows you to customize the text shown to the user at the exception or error pages::

/**
* @Security("is_granted('POST_SHOW', post)",message="You have no rights to view this post.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space after comma

@mkurzeja
Copy link

+1

1 similar comment
@klobermajer
Copy link

+1

@baptistedonaux
Copy link

+1 When is it available ?

@juandows
Copy link

+1

@scaytrase
Copy link
Author

I assume a year was enough to make any suggestions or discussions. Nevertheless no reaction, so closing

@scaytrase scaytrase closed this Jun 10, 2015
@acorbel
Copy link

acorbel commented Jul 31, 2015

+1

@fracsi
Copy link

fracsi commented Nov 10, 2015

+1
Very useful addition

@fre5h
Copy link

fre5h commented Jan 23, 2016

+1

@basepack
Copy link

basepack commented Sep 7, 2016

+1

Please reopen it..

@felipyamorim
Copy link

+1

2 similar comments
@maks-rafalko
Copy link

+1

@iVariable
Copy link

+1

@catchamonkey
Copy link

Can this be re-opened? First time i've come to use security via the annotation and this is immediately needed.
Thanks :)

@mahmoodbazdar
Copy link

+1

3 similar comments
@czeslav87
Copy link

+1

@artggd
Copy link

artggd commented Jun 6, 2017

+1

@Priyank780
Copy link

+1

@redox63
Copy link

redox63 commented Jul 17, 2017

+10

@felipyamorim
Copy link

can reopen ?

@alexis-mrc
Copy link

+1

1 similar comment
@tarlepp
Copy link
Contributor

tarlepp commented Aug 31, 2017

+1

@scaytrase
Copy link
Author

Created #501 as a replacement, thanks for your upvotes

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet