Skip to content
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

[Bug] Expire session when update user password #15219

Merged

Conversation

ruanwenjun
Copy link
Member

@ruanwenjun ruanwenjun commented Nov 24, 2023

Purpose of the pull request

When we delete or update the user's password, the old session will expire.

Brief change log

  • One user will bind to one session even if you use multiple ip.
  • When the user changed, will expire the exist session.

Verify this pull request

This pull request is code cleanup without any test coverage.

(or)

This pull request is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(or)

If your pull request contain incompatible change, you should also add it to docs/docs/en/guide/upgrede/incompatible.md

* session
*/
@Builder
@Data

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
Session.getIp
should be avoided because it has been deprecated.
super(sessionMapper);
}

public void deleteByUserId(Integer userId) {

Check notice

Code scanning / CodeQL

Missing Override annotation Note

This method overrides
SessionDao.deleteByUserId
; it is advisable to add an Override annotation.
@ruanwenjun ruanwenjun force-pushed the dev_wenjun_clearSessionWhenUserupdate branch 2 times, most recently from b738456 to 14af4de Compare November 24, 2023 08:42
@codecov-commenter
Copy link

codecov-commenter commented Nov 24, 2023

Codecov Report

Attention: 36 lines in your changes are missing coverage. Please review.

Comparison is base (0016b96) 38.00% compared to head (6894ede) 37.99%.

❗ Current head 6894ede differs from pull request most recent head 72c8885. Consider uploading reports for the commit 72c8885 to get more accurate results

Files Patch % Lines
...inscheduler/api/service/impl/UsersServiceImpl.java 27.77% 10 Missing and 3 partials ⚠️
...pache/dolphinscheduler/dao/repository/BaseDao.java 0.00% 6 Missing ⚠️
...lphinscheduler/api/controller/UsersController.java 0.00% 4 Missing ⚠️
...scheduler/api/service/impl/SessionServiceImpl.java 77.77% 2 Missing and 2 partials ⚠️
...nscheduler/dao/repository/impl/SessionDaoImpl.java 33.33% 3 Missing and 1 partial ⚠️
...duler/api/security/impl/AbstractAuthenticator.java 72.72% 1 Missing and 2 partials ⚠️
...uler/api/security/impl/ldap/LdapAuthenticator.java 0.00% 0 Missing and 1 partial ⚠️
...er/api/security/impl/sso/CasdoorAuthenticator.java 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                dev   #15219      +/-   ##
============================================
- Coverage     38.00%   37.99%   -0.02%     
+ Complexity     4644     4640       -4     
============================================
  Files          1279     1279              
  Lines         44539    44490      -49     
  Branches       4800     4794       -6     
============================================
- Hits          16927    16902      -25     
+ Misses        25759    25733      -26     
- Partials       1853     1855       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ruanwenjun ruanwenjun force-pushed the dev_wenjun_clearSessionWhenUserupdate branch 3 times, most recently from 23e360d to f9a702b Compare November 24, 2023 13:41
Comment on lines +44 to +45
// We will not bind session with ip
@Deprecated
Copy link
Contributor

Choose a reason for hiding this comment

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

👍


@Override
public List<Session> queryByUserId(Integer userId) {
return mybatisMapper.selectList(new QueryWrapper<>(Session.builder().userId(userId).build()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we avoid to use wrapper? Although this is a simple query looks fine, many complex query wrapper may be written later.
Use mapper.xml uniformly is a better way, WDYT?

Copy link
Member Author

@ruanwenjun ruanwenjun Nov 25, 2023

Choose a reason for hiding this comment

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

Agree with you, we shouldn't expose wrapper to service. I change this method to

/**
 * Query the entity by condition.
 */
List<Entity> queryByCondition(Entity queryCondition);

And add implementation in BaseDao

@Override
public List<ENTITY> queryByCondition(ENTITY queryCondition) {
    if (queryCondition == null) {
        throw new IllegalArgumentException("queryCondition can not be null");
    }
    return mybatisMapper.selectList(new QueryWrapper<>(queryCondition));
}

Then we can avoid using wrapper in dao, then we can use this method for simple query, and remove a lot of method like queryByCode, queryByName, queryByXX, for this kind of query we can directly use dao.queryByCondition(entity).

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems good.

@caishunfeng caishunfeng added improvement make more easy to user or prompt friendly 3.3.0 labels Nov 25, 2023
@caishunfeng caishunfeng changed the title Expire session when update user password [Improvement] Expire session when update user password Nov 25, 2023
@ruanwenjun ruanwenjun force-pushed the dev_wenjun_clearSessionWhenUserupdate branch 3 times, most recently from ae7522d to c09916c Compare November 25, 2023 03:00
@ruanwenjun ruanwenjun force-pushed the dev_wenjun_clearSessionWhenUserupdate branch from c09916c to 72c8885 Compare November 25, 2023 14:32
@ruanwenjun ruanwenjun changed the title [Improvement] Expire session when update user password [Bug] Expire session when update user password Nov 25, 2023
@ruanwenjun ruanwenjun added bug Something isn't working and removed improvement make more easy to user or prompt friendly labels Nov 25, 2023
Copy link

sonarcloud bot commented Nov 25, 2023

Please retry analysis of this Pull-Request directly on SonarCloud.

Copy link
Contributor

@caishunfeng caishunfeng left a comment

Choose a reason for hiding this comment

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

LGTM

@caishunfeng caishunfeng merged commit 12f8138 into apache:dev Nov 26, 2023
52 of 53 checks passed
@caishunfeng caishunfeng removed the 3.3.0 label Nov 26, 2023
@ruanwenjun ruanwenjun deleted the dev_wenjun_clearSessionWhenUserupdate branch November 27, 2023 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants