Passer au contenu principal

Auth

Gathers Netuno's authentication operations, providers, encryption, and others.

if (_auth.isJWT() && _auth.isAdmin()) {
_log.info('Administrator logged with JWT Token!')
}


allProvidersConfig​


_auth.allProvidersConfig() : Values​

Description​

Gets all the authentication providers configuration.

How To Use​
// Gets the Authentication Providers Settings.
const allProvidersConfig = _auth.allProvidersConfig()
_log.info('Authentication Providers Configuration', allProvidersConfig)

Return​

( Values )

All authentication providers settings.


altchaAdminEnabled​


_auth.altchaAdminEnabled() : boolean​

Return​

( boolean )


_auth.altchaAdminEnabled(enabled: boolean) : Auth​

Attributes​
NAMETYPEDESCRIPTION
enabledboolean
Return​

( Auth )


altchaEnabled​


_auth.altchaEnabled() : boolean​

Return​

( boolean )


_auth.altchaEnabled(enabled: boolean) : Auth​

Attributes​
NAMETYPEDESCRIPTION
enabledboolean
Return​

( Auth )


attempt​


_auth.attempt() : boolean​

Return​

( boolean )


attemptReject​


_auth.attemptReject() : boolean​

Return​

( boolean )


_auth.attemptReject(reject: boolean) : Auth​

Attributes​
NAMETYPEDESCRIPTION
rejectboolean
Return​

( Auth )


attemptRejectWithData​


_auth.attemptRejectWithData() : Values​

Return​

( Values )


_auth.attemptRejectWithData(data: java.util.List<?>) : Auth​

Attributes​
NAMETYPEDESCRIPTION
datajava.util.List
Return​

( Auth )


_auth.attemptRejectWithData(data: Values | DataSchema | java.util.Map) : Auth​

Attributes​
NAMETYPEDESCRIPTION
datajava.util.Map
Return​

( Auth )


_auth.attemptRejectWithData(data: Values) : Auth​

Attributes​
NAMETYPEDESCRIPTION
dataValues
Return​

( Auth )


attemptsEnabled​


_auth.attemptsEnabled() : boolean​

Description​

Whether or not automatic blocking of failed authentication attempts is enabled.

Return​

( boolean )

Returns whether automatic blocking of consecutive failed authentication attempts is enabled.


_auth.attemptsEnabled(attemptsEnabled: boolean) : Auth​

Attributes​
NAMETYPEDESCRIPTION
attemptsEnabledboolean
Return​

( Auth )


attemptsInterval​


_auth.attemptsInterval() : int​

Description​

Number in minutes to set the time interval to perform account blocking.

Return​

( int )

Returns the number of minutes for the time interval for the locked account.


_auth.attemptsInterval(attemptsInterval: int) : Auth​

Attributes​
NAMETYPEDESCRIPTION
attemptsIntervalint
Return​

( Auth )


attemptsMaxFails​


_auth.attemptsMaxFails() : int​

Description​

Maximum number of consecutive failed authentication attempts to trigger account lockout.

Return​

( int )

Returns the maximum number of consecutive failed attempts to block authentication.


_auth.attemptsMaxFails(attemptsMaxFails: int) : Auth​

Attributes​
NAMETYPEDESCRIPTION
attemptsMaxFailsint
Return​

( Auth )


check​


_auth.check(password: string) : boolean​

Description​

Checks if the password is valid for the authenticated user.

How To Use​
if (_auth.check(_req.getString('pass'))) {
_log.info('Valid password!')
} else {
_log.info('Invalid password!')
}

Attributes​
NAMETYPEDESCRIPTION
passwordstringPassword.
Return​

( boolean )

Returns the result of validating authentication data.


_auth.check(username: string, password: string) : boolean​

Description​

Checks if the authentication data, user and password, are valid.

How To Use​
if (_auth.check(_req.getString('user'), _req.getString('pass'))) {
_log.info('Valid login!')
} else {
_log.info('Invalid login!')
}

Attributes​
NAMETYPEDESCRIPTION
usernamestringUsername.
passwordstringPassword.
Return​

( boolean )

Returns the result of the validating authentication data.


checkUserInJWTGroups​


_auth.checkUserInJWTGroups(userId: int) : boolean​

Attributes​
NAMETYPEDESCRIPTION
userIdint
Return​

( boolean )


crypt​


_auth.crypt(username: string, password: string) : string​

Description​

Generates a secure encrypted password for a given user.

How To Use​
// Generates the secure password to a user.
_log.info('Secure Password: '+ _auth.crypt('my-user', 'my-pass'))

Attributes​
NAMETYPEDESCRIPTION
usernamestringUsername.
passwordstringPassword.
Return​

( string )

Returns strong password encryption.


getAllProvidersConfig​


_auth.getAllProvidersConfig() : Values​

Description​

Gets all the authentication providers configuration.

How To Use​
// Gets the Authentication Providers Settings.
const allProvidersConfig = _auth.allProvidersConfig()
_log.info('Authentication Providers Configuration', allProvidersConfig)

Return​

( Values )

All authentication providers settings.


getAttemptRejectWithData​


_auth.getAttemptRejectWithData(data: Values) : Values​

Attributes​
NAMETYPEDESCRIPTION
dataValues
Return​

( Values )


getJWTAccessExpires​


_auth.getJWTAccessExpires() : int​

Description​

Sets the time of expiration of the token to the settings in configs.

Return​

( int )


getJWTGroups​


_auth.getJWTGroups() : Values​

Return​

( Values )


getJWTKey​


_auth.getJWTKey() : javax.crypto.SecretKey​

Return​

( javax.crypto.SecretKey )


getJWTRefreshExpires​


_auth.getJWTRefreshExpires() : int​

Description​

Updates the time of expiration of the token to the settings in configs.

Return​

( int )


getJWTSignInData​


_auth.getJWTSignInData() : Values​

Return​

( Values )


getProviderConfig​


_auth.getProviderConfig(providerCode: string) : Values​

Description​

Gets one specific authentication provider configuration.

How To Use​
// Gets authentication provider setting to each provider.
_log.info('Google Provider Configuration', _auth.providerConfig('google'))
_log.info('Microsoft Provider Configuration', _auth.providerConfig('microsoft'))
_log.info('GitHub Provider Configuration', _auth.providerConfig('github'))
_log.info('Discord Provider Configuration', _auth.providerConfig('discord'))
_log.info('LDAP Provider Configuration', _auth.providerConfig('ldap'))

Attributes​
NAMETYPEDESCRIPTION
providerCodestringName of the provider configuration key, which can be:
- google
- microsoft
- github
- discord
- ldap
Return​

( Values )

The authentication provider configuration.


getSignInAbortWithData​


_auth.getSignInAbortWithData(data: Values) : Values​

Attributes​
NAMETYPEDESCRIPTION
dataValues
Return​

( Values )


getSignInExtraData​


_auth.getSignInExtraData(data: Values) : Values​

Attributes​
NAMETYPEDESCRIPTION
dataValues
Return​

( Values )


isAdmin​


_auth.isAdmin() : boolean​

Description​

Checks if the user that is authenticated is administrator.

How To Use​
if (_auth.isAdmin()) {
_log.info('Admin logged in!')
}

Return​

( boolean )

If the user that is authenticated is an admin (administrator) returns true.


isAltchaAdminEnabled​


_auth.isAltchaAdminEnabled() : boolean​

Return​

( boolean )


isAltchaEnabled​


_auth.isAltchaEnabled() : boolean​

Return​

( boolean )


isAttempt​


_auth.isAttempt() : boolean​

Return​

( boolean )


isAttemptReject​


_auth.isAttemptReject() : boolean​

Return​

( boolean )


isAttemptsEnabled​


_auth.isAttemptsEnabled() : boolean​

Description​

Whether or not automatic blocking of failed authentication attempts is enabled.

Return​

( boolean )

Returns whether automatic blocking of consecutive failed authentication attempts is enabled.


isAttemptsInterval​


_auth.isAttemptsInterval() : int​

Description​

Number in minutes to set the time interval to perform account blocking.

Return​

( int )

Returns the number of minutes for the time interval for the locked account.


isAuthenticated​


_auth.isAuthenticated() : boolean​

Description​

Indicates whether there is someone authenticated processing the request.

How To Use​
if (_auth.isAuthenticated()) {
_log.info('There is someone authenticated.')
}

Return​

( boolean )

If someone is authenticated, it returns true.


isDev​


_auth.isDev() : boolean​

Description​

Checks if the user authenticated is a developer.

How To Use​
if (_auth.isDev()) {
_log.info('Developer logged in!')
}

Return​

( boolean )

if the user authenticated is a dev (developer) returns true.


isJWT​


_auth.isJWT() : boolean​

Description​

Indicates whether the user is authenticated with JSON Web Token.

How To Use​
if (_auth.isJWT()) {
_log.info('Logged in with JWT!')
}

Return​

( boolean )

If the user is authenticated with JSON Web Token returns true.


isJWTEnabled​


_auth.isJWTEnabled() : boolean​

Description​

Verify if the JWT is enable.

Return​

( boolean )

Returns if is enabled.


isProviderEnabled​


_auth.isProviderEnabled(providerCode: string) : boolean​

Description​

Checks whether the authentication provider is active.

How To Use​
// Checks enabled authentication providers.
_log.info('Google Provider Enabled', _auth.providerEnabled('google'))
_log.info('Microsoft Provider Enabled', _auth.providerEnabled('microsoft'))
_log.info('GitHub Provider Enabled', _auth.providerEnabled('github'))
_log.info('Discord Provider Enabled', _auth.providerEnabled('discord'))
_log.info('LDAP Provider Enabled', _auth.providerEnabled('ldap'))

Attributes​
NAMETYPEDESCRIPTION
providerCodestringName of the provider configuration key, which can be:
- google
- microsoft
- github
- discord
- ldap
Return​

( boolean )

If the authentication provider is active returns true.


isSession​


_auth.isSession() : boolean​

Description​

Indicates whether the user is authenticated with session.

How To Use​
if (_auth.isSession()) {
_log.info('Logged in with session!')
}

Return​

( boolean )

If the user is authenticated with JSON Web Token returns true.


isSignInAbort​


_auth.isSignInAbort() : boolean​

Return​

( boolean )


jwtAccessExpires​


_auth.jwtAccessExpires() : int​

Description​

Sets the time of expiration of the token to the settings in configs.

Return​

( int )


jwtCheckToken​


_auth.jwtCheckToken(token: string) : boolean​

Description​

This method verify the token.

Attributes​
NAMETYPEDESCRIPTION
tokenstringToken to be verify.
Return​

( boolean )

Returns the validation.


jwtCheckTokenDataExpiration​


_auth.jwtCheckTokenDataExpiration(dbToken: Values) : boolean​

Attributes​
NAMETYPEDESCRIPTION
dbTokenValues
Return​

( boolean )


jwtCreateAccessToken​


_auth.jwtCreateAccessToken(userId: int, contextData: Values) : Values​

Attributes​
NAMETYPEDESCRIPTION
userIdint
contextDataValues
Return​

( Values )


_auth.jwtCreateAccessToken(userId: Values) : Values​

Description​

This method access to the token of a user and returns the content.

Attributes​
NAMETYPEDESCRIPTION
userIdValuesId of user.
Return​

( Values )

Returns the content of the user inserted.


jwtDBRecord​


_auth.jwtDBRecord(token: string) : Values​

Attributes​
NAMETYPEDESCRIPTION
tokenstring
Return​

( Values )


jwtData​


_auth.jwtData() : Values​

Return​

( Values )


jwtEnabled​


_auth.jwtEnabled() : boolean​

Description​

Verify if the JWT is enable.

Return​

( boolean )

Returns if is enabled.


_auth.jwtEnabled(enabled: boolean) : Auth​

Attributes​
NAMETYPEDESCRIPTION
enabledboolean
Return​

( Auth )


jwtGroups​


_auth.jwtGroups() : Values​

Return​

( Values )


jwtInvalidateToken​


_auth.jwtInvalidateToken() : boolean​

Return​

( boolean )


_auth.jwtInvalidateToken(token: string) : boolean​

Attributes​
NAMETYPEDESCRIPTION
tokenstring
Return​

( boolean )


jwtKey​


_auth.jwtKey() : javax.crypto.SecretKey​

Return​

( javax.crypto.SecretKey )


jwtRefreshAccessToken​


_auth.jwtRefreshAccessToken(refreshToken: string) : Values​

Description​

Replaces an old token for the new on inserted.

Attributes​
NAMETYPEDESCRIPTION
refreshTokenstringReplace token.
Return​

( Values )

Returns the updated token.


jwtRefreshExpires​


_auth.jwtRefreshExpires() : int​

Description​

Updates the time of expiration of the token to the settings in configs.

Return​

( int )


jwtSignIn​


_auth.jwtSignIn(userId: int, contextData: Values) : Auth​

Attributes​
NAMETYPEDESCRIPTION
userIdint
contextDataValues
Return​

( Auth )


jwtSignInData​


_auth.jwtSignInData() : Values​

Return​

( Values )


jwtToken​


_auth.jwtToken() : string​

Description​

Verify if exists an authenticated token.

Return​

( string )

Returns the token.


jwtTokenCheck​


_auth.jwtTokenCheck() : boolean​

Description​

Verify if a token exists.

Return​

( boolean )

Returns the validation.


load​


_auth.load() : Auth​

Description​

Processes authentication settings.

How To Use​
// Loads authentication settings.
_auth.load()
Return​

( Auth )

Returns the default Auth resource.


logout​


_auth.logout() : Auth​

Description​

Signs out the user authenticated.

How To Use​
// Clears the authentication context.
_auth.logout()

Return​

( Auth )

Returns the default Auth resource.


providerConfig​


_auth.providerConfig(providerCode: string) : Values​

Description​

Gets one specific authentication provider configuration.

How To Use​
// Gets authentication provider setting to each provider.
_log.info('Google Provider Configuration', _auth.providerConfig('google'))
_log.info('Microsoft Provider Configuration', _auth.providerConfig('microsoft'))
_log.info('GitHub Provider Configuration', _auth.providerConfig('github'))
_log.info('Discord Provider Configuration', _auth.providerConfig('discord'))
_log.info('LDAP Provider Configuration', _auth.providerConfig('ldap'))

Attributes​
NAMETYPEDESCRIPTION
providerCodestringName of the provider configuration key, which can be:
- google
- microsoft
- github
- discord
- ldap
Return​

( Values )

The authentication provider configuration.


providerEnabled​


_auth.providerEnabled(providerCode: string) : boolean​

Description​

Checks whether the authentication provider is active.

How To Use​
// Checks enabled authentication providers.
_log.info('Google Provider Enabled', _auth.providerEnabled('google'))
_log.info('Microsoft Provider Enabled', _auth.providerEnabled('microsoft'))
_log.info('GitHub Provider Enabled', _auth.providerEnabled('github'))
_log.info('Discord Provider Enabled', _auth.providerEnabled('discord'))
_log.info('LDAP Provider Enabled', _auth.providerEnabled('ldap'))

Attributes​
NAMETYPEDESCRIPTION
providerCodestringName of the provider configuration key, which can be:
- google
- microsoft
- github
- discord
- ldap
Return​

( boolean )

If the authentication provider is active returns true.


setAltchaAdminEnabled​


_auth.setAltchaAdminEnabled(enabled: boolean) : Auth​

Attributes​
NAMETYPEDESCRIPTION
enabledboolean
Return​

( Auth )


setAltchaEnabled​


_auth.setAltchaEnabled(enabled: boolean) : Auth​

Attributes​
NAMETYPEDESCRIPTION
enabledboolean
Return​

( Auth )


setAttemptReject​


_auth.setAttemptReject(reject: boolean) : Auth​

Attributes​
NAMETYPEDESCRIPTION
rejectboolean
Return​

( Auth )


setAttemptRejectWithData​


_auth.setAttemptRejectWithData(data: java.util.List<?>) : Auth​

Attributes​
NAMETYPEDESCRIPTION
datajava.util.List
Return​

( Auth )


_auth.setAttemptRejectWithData(data: Values | DataSchema | java.util.Map) : Auth​

Attributes​
NAMETYPEDESCRIPTION
datajava.util.Map
Return​

( Auth )


_auth.setAttemptRejectWithData(data: Values) : Auth​

Attributes​
NAMETYPEDESCRIPTION
dataValues
Return​

( Auth )


setAttemptsEnabled​


_auth.setAttemptsEnabled(enabled: boolean) : Auth​

Attributes​
NAMETYPEDESCRIPTION
enabledboolean
Return​

( Auth )


setAttemptsInterval​


_auth.setAttemptsInterval(attemptsInterval: int) : Auth​

Attributes​
NAMETYPEDESCRIPTION
attemptsIntervalint
Return​

( Auth )


setJWTEnabled​


_auth.setJWTEnabled(enabled: boolean) : Auth​

Attributes​
NAMETYPEDESCRIPTION
enabledboolean
Return​

( Auth )


setJWTSignIn​


_auth.setJWTSignIn(userId: int, contextData: Values) : Auth​

Attributes​
NAMETYPEDESCRIPTION
userIdint
contextDataValues
Return​

( Auth )


setSignInAbort​


_auth.setSignInAbort(abort: boolean) : Auth​

Attributes​
NAMETYPEDESCRIPTION
abortboolean
Return​

( Auth )


setSignInAbortWithData​


_auth.setSignInAbortWithData(data: java.util.List<?>) : Auth​

Attributes​
NAMETYPEDESCRIPTION
datajava.util.List
Return​

( Auth )


_auth.setSignInAbortWithData(data: Values | DataSchema | java.util.Map) : Auth​

Attributes​
NAMETYPEDESCRIPTION
datajava.util.Map
Return​

( Auth )


_auth.setSignInAbortWithData(data: Values) : Auth​

Attributes​
NAMETYPEDESCRIPTION
dataValues
Return​

( Auth )


setSignInExtraData​


_auth.setSignInExtraData(data: java.util.List<?>) : Auth​

Attributes​
NAMETYPEDESCRIPTION
datajava.util.List
Return​

( Auth )


_auth.setSignInExtraData(data: Values | DataSchema | java.util.Map) : Auth​

Attributes​
NAMETYPEDESCRIPTION
datajava.util.Map
Return​

( Auth )


_auth.setSignInExtraData(data: Values) : Auth​

Attributes​
NAMETYPEDESCRIPTION
dataValues
Return​

( Auth )


signInAbort​


_auth.signInAbort() : boolean​

Return​

( boolean )


_auth.signInAbort(abort: boolean) : Auth​

Attributes​
NAMETYPEDESCRIPTION
abortboolean
Return​

( Auth )


signInAbortWithData​


_auth.signInAbortWithData() : Values​

Return​

( Values )


_auth.signInAbortWithData(data: java.util.List<?>) : Auth​

Attributes​
NAMETYPEDESCRIPTION
datajava.util.List
Return​

( Auth )


_auth.signInAbortWithData(data: Values | DataSchema | java.util.Map) : Auth​

Attributes​
NAMETYPEDESCRIPTION
datajava.util.Map
Return​

( Auth )


_auth.signInAbortWithData(data: Values) : Auth​

Attributes​
NAMETYPEDESCRIPTION
dataValues
Return​

( Auth )


signInExtraData​


_auth.signInExtraData() : Values​

Return​

( Values )


_auth.signInExtraData(data: java.util.List<?>) : Auth​

Attributes​
NAMETYPEDESCRIPTION
datajava.util.List
Return​

( Auth )


_auth.signInExtraData(data: Values | DataSchema | java.util.Map) : Auth​

Attributes​
NAMETYPEDESCRIPTION
datajava.util.Map
Return​

( Auth )


_auth.signInExtraData(data: Values) : Auth​

Attributes​
NAMETYPEDESCRIPTION
dataValues
Return​

( Auth )