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

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2017
Merged

Conversation

maidmaid
Copy link
Contributor

@maidmaid maidmaid commented Dec 28, 2016

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 symfony/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"]}
}

@maidmaid
Copy link
Contributor Author

maidmaid commented Dec 28, 2016

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

@linaori
Copy link
Contributor

linaori commented Dec 29, 2016

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

lyrixx commented Dec 29, 2016

@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
Contributor Author

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 key authenticated

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

'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
Copy link
Contributor Author

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."?

Copy link
Contributor Author

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
Contributor Author

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 allows to 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 being public is an extension point which we would have to maintain.

Copy link
Contributor Author

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-grekas nicolas-grekas added this to the 3.x milestone Jan 2, 2017
@xabbuh
Copy link
Member

xabbuh commented Jan 10, 2017

You need to add the security/core package as a dependency to the require-dev section in the composer.json file of MonologBridge.

$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 be RoleInterface

Copy link
Contributor Author

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 from getRoles.

Copy link
Contributor Author

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
Contributor Author

I updated the composer.json @xabbuh.

@maidmaid
Copy link
Contributor Author

maidmaid commented Apr 3, 2017

AppVeyor break tests are related?

@sstok
Copy link
Contributor

sstok commented Apr 7, 2017

AppVeyor Failure seems unrelated.

@maidmaid maidmaid changed the base branch from master to 3.4 May 20, 2017 06:42
@maidmaid maidmaid force-pushed the userprocessor branch 4 times, most recently from ac46318 to ef3e18c Compare June 5, 2017 22:43
@maidmaid maidmaid force-pushed the userprocessor branch 2 times, most recently from 9210609 to 26b9d1f Compare July 1, 2017 09:16
@maidmaid
Copy link
Contributor Author

PR ready to merge since some time :)

@lyrixx
Copy link
Member

lyrixx commented Jul 12, 2017

👍

@@ -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",
Copy link
Member

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
Contributor Author

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-grekas nicolas-grekas Jul 12, 2017

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-grekas nicolas-grekas merged commit 3763515 into symfony:3.4 Jul 12, 2017
nicolas-grekas added a commit that referenced this pull request Jul 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
@maidmaid maidmaid deleted the userprocessor branch July 12, 2017 13:12
This was referenced Oct 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.