java.lang.Object
com.erudika.para.server.security.SecurityUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic UserAuthentication
checkIfActive
(UserAuthentication userAuth, com.erudika.para.core.User user, boolean throwException) Checks if account is active.static boolean
checkIfUserCanModifyObject
(com.erudika.para.core.App app, com.erudika.para.core.ParaObject object) Check if a user can modify an object.static boolean
checkImplicitAppPermissions
(com.erudika.para.core.App app, com.erudika.para.core.ParaObject object) An app can edit itself or delete itself.static void
clearSession
(jakarta.servlet.http.HttpServletRequest req) Clears the session.static com.nimbusds.jwt.SignedJWT
generateIdToken
(com.erudika.para.core.User user, com.erudika.para.core.App app) Short-lived identity token, proving that a Para user has been successfully authenticated against an IDP.static com.nimbusds.jwt.SignedJWT
generateJWToken
(com.erudika.para.core.User user, com.erudika.para.core.App app) Generates a new JWT token.static com.nimbusds.jwt.SignedJWT
generateSuperJWToken
(com.erudika.para.core.App app) Generates a new "super" JWT token for apps.static com.erudika.para.core.App
getter.static com.erudika.para.core.App
getter.static String
getAppidFromAuthRequest
(jakarta.servlet.http.HttpServletRequest request) getter.static com.erudika.para.core.App
Extracts a App object from the security context.static com.erudika.para.core.User
Extracts a User object from the security context.static com.erudika.para.core.User
getAuthenticatedUser
(org.springframework.security.core.Authentication auth) Extracts a User object from the security context.getHostUrlAliasesForReturn
(com.erudika.para.core.App app) getter.static String
getHostUrlFromQueryStringOrStateParam
(Set<String> hostUrlAliases, jakarta.servlet.http.HttpServletRequest request) getter.static com.erudika.para.core.App
Returns the current authenticatedApp
object.static String
getRedirectUrl
(jakarta.servlet.http.HttpServletRequest request) getter.static boolean
isNotAnApp
(String type) checker.static boolean
isValidJWToken
(String secret, com.nimbusds.jwt.SignedJWT jwt) Validates a JWT token.static boolean
isValidSignature
(jakarta.servlet.http.HttpServletRequest incoming, String secretKey) Validates the signature of the request.
-
Method Details
-
getAuthenticatedUser
public static com.erudika.para.core.User getAuthenticatedUser()Extracts a User object from the security context.- Returns:
- an authenticated user or null if a user is not authenticated
-
getAuthenticatedUser
public static com.erudika.para.core.User getAuthenticatedUser(org.springframework.security.core.Authentication auth) Extracts a User object from the security context.- Parameters:
auth
- the authentication object- Returns:
- an authenticated user or null if a user is not authenticated
-
getAuthenticatedApp
public static com.erudika.para.core.App getAuthenticatedApp()Extracts a App object from the security context.- Returns:
- an authenticated app or null if a app is not authenticated
-
getAppFromJWTAuthentication
public static com.erudika.para.core.App getAppFromJWTAuthentication()getter.- Returns:
- returns the current app associated with the authenticated user
-
getAppFromLdapAuthentication
public static com.erudika.para.core.App getAppFromLdapAuthentication()getter.- Returns:
- returns the current app associated with the authenticated user
-
getPrincipalApp
public static com.erudika.para.core.App getPrincipalApp()Returns the current authenticatedApp
object.- Returns:
- an App object or null
-
checkImplicitAppPermissions
public static boolean checkImplicitAppPermissions(com.erudika.para.core.App app, com.erudika.para.core.ParaObject object) An app can edit itself or delete itself. It can't read, edit, overwrite or delete other apps, unless it is the root app.- Parameters:
app
- an appobject
- another object- Returns:
- true if app passes the check
-
isNotAnApp
checker.- Parameters:
type
- some type- Returns:
- true if type of object is not "app"
-
checkIfUserCanModifyObject
public static boolean checkIfUserCanModifyObject(com.erudika.para.core.App app, com.erudika.para.core.ParaObject object) Check if a user can modify an object. If there's no user principal found, this returns true.- Parameters:
app
- app in contextobject
- some object- Returns:
- true if user is the owner/creator of the object.
-
clearSession
public static void clearSession(jakarta.servlet.http.HttpServletRequest req) Clears the session. Deletes cookies and clears the security context.- Parameters:
req
- HTTP request
-
isValidJWToken
Validates a JWT token.- Parameters:
secret
- secret used for generating the tokenjwt
- token to validate- Returns:
- true if token is valid
-
generateSuperJWToken
public static com.nimbusds.jwt.SignedJWT generateSuperJWToken(com.erudika.para.core.App app) Generates a new "super" JWT token for apps.- Parameters:
app
- the app object- Returns:
- a new JWT or null
-
generateJWToken
public static com.nimbusds.jwt.SignedJWT generateJWToken(com.erudika.para.core.User user, com.erudika.para.core.App app) Generates a new JWT token.- Parameters:
user
- a User object belonging to the appapp
- the app object- Returns:
- a new JWT or null
-
generateIdToken
public static com.nimbusds.jwt.SignedJWT generateIdToken(com.erudika.para.core.User user, com.erudika.para.core.App app) Short-lived identity token, proving that a Para user has been successfully authenticated against an IDP. Works with the passwordless auth filter.- Parameters:
user
- user objectapp
- app object- Returns:
- a signed JWT or null
-
checkIfActive
public static UserAuthentication checkIfActive(UserAuthentication userAuth, com.erudika.para.core.User user, boolean throwException) Checks if account is active.- Parameters:
userAuth
- user authentication objectuser
- user objectthrowException
- throw or not- Returns:
- the authentication object if
user.active == true
-
isValidSignature
public static boolean isValidSignature(jakarta.servlet.http.HttpServletRequest incoming, String secretKey) Validates the signature of the request.- Parameters:
incoming
- the incoming HTTP request containing a signaturesecretKey
- the app's secret key- Returns:
- true if the signature is valid
-
getRedirectUrl
getter.- Parameters:
request
- HTTP request- Returns:
- the URL with the correct protocol, read from X-Forwarded-Proto and CloudFront-Forwarded-Proto headers.
-
getAppidFromAuthRequest
getter.- Parameters:
request
- HTTP request- Returns:
- the appid if it's present in either the 'state' or 'appid' query parameters
-
getHostUrlAliasesForReturn
-
getHostUrlFromQueryStringOrStateParam
-