Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[MonologBridge] Add TokenProcessor#21086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nicolas-grekas merged 1 commit intosymfony:3.4frommaidmaid:userprocessor
Jul 12, 2017

Conversation

maidmaid
Copy link
Contributor

@maidmaidmaidmaid commentedDec 28, 2016
edited by nicolas-grekas
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed ticketsn/a
LicenseMIT
Doc PRsymfony/symfony-docs#8156

TokenProcessor is an out-of-the-box class that adds token in extra info log, like this:

[2016-12-29 14:48:09] app.INFO: admin connected! [] {"token":{    "username":"admin",    "authenticated":true,    "roles":["ROLE_ADMIN"]}}

linaori, sstok, ro0NL, and Simperfit reacted with thumbs up emoji
@maidmaid
Copy link
ContributorAuthor

maidmaid commentedDec 28, 2016
edited
Loading

If this feature will be merged, is it a good idea to register this processor inMonologBundle for all logs? Or else, maybe simply write a doc that explains its registration (containing something likethis)?

@linaori
Copy link
Contributor

Would this add the token to every log line? Because I don't want to see the token added 10x if my log contains 10 log lines to be honest.

The idea is great though, I'm using a custom formatter for the logging at the moment and I rather have this in the core.

@lyrixx
Copy link
Member

@iltar Yes it will. That's how processor works.

But:

  • This processor is not enabled by default
  • You can add process on specific channel and/or handler.

@maidmaid
Copy link
ContributorAuthor

I have improved token normalization that now is more json-like/readable:

[2016-12-29 14:48:09] app.INFO: admin connected! [] {"token":{    "username":"admin",    "auth.":true,    "roles":["ROLE_ADMIN"]}}

$records['extra']['token'] = (string) $token;
$records['extra']['token'] = array(
'username' => $token->getUsername(),
'auth.' => $token->isAuthenticated(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest to call this keyauthenticated

maidmaid reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

Indeed

@@ -25,6 +25,7 @@ public function __invoke(array $record)
'timestamp' => $record['datetime']->getTimestamp(),
'message' => $record['message'],
'priority' => $record['level'],

Copy link
Member

Choose a reason for hiding this comment

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

should be reverted

maidmaid reacted with thumbs up emoji
'auth.' => $token->isAuthenticated(),
'roles' => array_map(function (Role $role) {
return $role->getRole();
}, $token->getRoles()),
Copy link
Member

Choose a reason for hiding this comment

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

should be on one line

maidmaid reacted with thumbs up emoji
@maidmaid
Copy link
ContributorAuthor

Thank you for your review@fabpot and@iltar. Changes are done.

use Symfony\Component\Security\Core\Role\Role;

/**
* TokenProcessor adds token extra info.
Copy link
Member

Choose a reason for hiding this comment

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

"Adds the current security token to the log entry."?

maidmaid reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Indeed, it's better.

return $records;
}

public function isDeniedProcess()
Copy link
Member

Choose a reason for hiding this comment

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

Is this method really needed?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

In CLI mode,extra.token should not be added, for example in commands but not in tests. This method allowsto mock this behavior in tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

In CLI mode, extra.token should not be added

Why not?

Copy link
Member

Choose a reason for hiding this comment

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

I was more referring to this being a dedicated method while it could easily be inlined.

Copy link
Member

Choose a reason for hiding this comment

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

Furthermore, a method beingpublic is an extension point which we would have to maintain.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Indeed, this is not very helpful. I have removed this method.

@nicolas-grekasnicolas-grekas added this to the3.x milestoneJan 2, 2017
@xabbuh
Copy link
Member

You need to add thesecurity/core package as a dependency to therequire-dev section in thecomposer.json file of MonologBridge.

maidmaid reacted with thumbs up emoji

$records['extra']['token'] = array(
'username' => $token->getUsername(),
'authenticated' => $token->isAuthenticated(),
'roles' => array_map(function (Role $role) { return $role->getRole(); }, $token->getRoles()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should beRoleInterface

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

RoleInterface is now deprecated

Copy link
Contributor

Choose a reason for hiding this comment

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

And not yet removed, they are still returned fromgetRoles.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

👍 it's done

@maidmaid
Copy link
ContributorAuthor

I updated thecomposer.json@xabbuh.

@maidmaid
Copy link
ContributorAuthor

AppVeyor break tests are related?

@sstok
Copy link
Contributor

AppVeyor Failure seems unrelated.

@maidmaidmaidmaid changed the base branch frommaster to3.4May 20, 2017 06:42
@maidmaidmaidmaidforce-pushed theuserprocessor branch 4 times, most recently fromac46318 toef3e18cCompareJune 5, 2017 22:43
@maidmaidmaidmaidforce-pushed theuserprocessor branch 2 times, most recently from9210609 to26b9d1fCompareJuly 1, 2017 09:16
@maidmaid
Copy link
ContributorAuthor

PR ready to merge since some time :)

@lyrixx
Copy link
Member

👍

@@ -23,6 +23,7 @@
"require-dev": {
"symfony/console": "~2.8|~3.0|~4.0",
"symfony/event-dispatcher": "~2.8|~3.0|~4.0",
"symfony/security-core": "~2.8|~3.0",

Choose a reason for hiding this comment

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

missing|~4.0

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

RoleInterface is used here, and will be removed in 4.0.

Copy link
Member

@nicolas-grekasnicolas-grekasJul 12, 2017
edited
Loading

Choose a reason for hiding this comment

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

then I suggest to remove the type hint, it's purely internal and doesn't justify a deps limitation

@nicolas-grekas
Copy link
Member

Thank you@maidmaid.

@nicolas-grekasnicolas-grekas merged commit3763515 intosymfony:3.4Jul 12, 2017
nicolas-grekas added a commit that referenced this pull requestJul 12, 2017
This PR was merged into the 3.4 branch.Discussion----------[MonologBridge] Add TokenProcessor| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | n/a| License       | MIT| Doc PR        | n/a``TokenProcessor`` is an out-of-the-box class that adds token in extra info log, like this:```[2016-12-29 14:48:09] app.INFO: admin connected! [] {"token":{    "username":"admin",    "authenticated":true,    "roles":["ROLE_ADMIN"]}}```Commits-------3763515 Add TokenProcessor
@maidmaidmaidmaid deleted the userprocessor branchJuly 12, 2017 13:12
This was referencedOct 18, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@fabpotfabpotfabpot left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@ro0NLro0NLro0NL left review comments

@linaorilinaorilinaori left review comments

@xabbuhxabbuhxabbuh left review comments

@SimperfitSimperfitSimperfit approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
3.4
Development

Successfully merging this pull request may close these issues.

10 participants
@maidmaid@linaori@lyrixx@xabbuh@sstok@nicolas-grekas@fabpot@ro0NL@Simperfit@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp