forked from axelor/axelor-open-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for unauthorized users inside security filter directly
Fixes RM-63350 Signed-off-by: Pierre Belloy <[email protected]>
- Loading branch information
1 parent
32f4a71
commit d5e89b7
Showing
8 changed files
with
87 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 0 additions & 73 deletions
73
axelor-core/src/main/java/com/axelor/auth/AuthObserver.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
axelor-core/src/main/java/com/axelor/auth/pac4j/AxelorUserAuthorizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Axelor Business Solutions | ||
* | ||
* Copyright (C) 2005-2023 Axelor (<http://axelor.com>). | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.axelor.auth.pac4j; | ||
|
||
import com.axelor.auth.AuthSessionService; | ||
import com.axelor.auth.AuthUtils; | ||
import com.axelor.auth.db.User; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
import org.apache.shiro.SecurityUtils; | ||
import org.pac4j.core.authorization.authorizer.Authorizer; | ||
import org.pac4j.core.context.WebContext; | ||
import org.pac4j.core.context.session.SessionStore; | ||
import org.pac4j.core.profile.UserProfile; | ||
|
||
@Singleton | ||
public class AxelorUserAuthorizer implements Authorizer { | ||
|
||
public static final String USER_AUTHORIZER_NAME = "AxelorUserAuthorizer"; | ||
|
||
private AuthSessionService authSessionService; | ||
|
||
@Inject | ||
public AxelorUserAuthorizer(AuthSessionService authSessionService) { | ||
this.authSessionService = authSessionService; | ||
} | ||
|
||
@Override | ||
public boolean isAuthorized( | ||
WebContext context, SessionStore sessionStore, List<UserProfile> profiles) { | ||
User user = AuthUtils.getUser(); | ||
if (user == null) { | ||
return false; | ||
} | ||
if (!isAllowed(user)) { | ||
removeSession(); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private boolean isAllowed(User user) { | ||
final LocalDateTime loginDate = | ||
authSessionService.getLoginDate(AuthUtils.getSubject().getSession()); | ||
return AuthUtils.isActive(user) | ||
&& (user.getPasswordUpdatedOn() == null | ||
|| loginDate != null && !loginDate.isBefore(user.getPasswordUpdatedOn())); | ||
} | ||
|
||
private void removeSession() { | ||
try { | ||
SecurityUtils.getSubject().logout(); | ||
} catch (Exception e) { | ||
// ignore | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: Check for unauthorized users inside security filter directly | ||
type: security |