java.lang.Object
com.fredriksonsound.iot_backoffice_auth.service.AuthService
All Implemented Interfaces:
IAuthService

@Component
@Service
public class AuthService
extends java.lang.Object
implements IAuthService
AuthService implementation
  • Constructor Summary

    Constructors 
    Constructor Description
    AuthService()  
  • Method Summary

    Modifier and Type Method Description
    boolean deleteRefreshToken​(java.lang.String id)
    Deletes a specified access token by id
    Pair<java.lang.String,​java.lang.String> generateAndSaveTokens​(java.lang.String email)
    Generates a new access token and refresh token.
    java.lang.String refresh​(java.lang.String access, java.lang.String refreshId)
    Generates a new access token given an expired accesstoken and a refresh token id
    boolean validateAccessFor​(java.lang.String accessToken, java.lang.String subject)
    Validates whether a tokens access-level (authToken.subject) is valid for accessing the resource (subject)
    boolean validateUserPassword​(java.lang.String email, java.lang.String password)
    Checks that a given password matches a given user email

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • validateUserPassword

      public boolean validateUserPassword​(java.lang.String email, java.lang.String password)
      Checks that a given password matches a given user email
      Specified by:
      validateUserPassword in interface IAuthService
      Parameters:
      email - the users email
      password - the password
      Returns:
      true if match, false if not match
    • generateAndSaveTokens

      public Pair<java.lang.String,​java.lang.String> generateAndSaveTokens​(java.lang.String email)
      Generates a new access token and refresh token.
      Specified by:
      generateAndSaveTokens in interface IAuthService
      Parameters:
      email - the email of the user
      Returns:
      and access token and a refresh token id.
    • deleteRefreshToken

      public boolean deleteRefreshToken​(java.lang.String id)
      Deletes a specified access token by id
      Specified by:
      deleteRefreshToken in interface IAuthService
      Parameters:
      id - the access token identifier
      Returns:
      true if the deletion was a success
    • validateAccessFor

      public boolean validateAccessFor​(java.lang.String accessToken, java.lang.String subject) throws ValidationError
      Validates whether a tokens access-level (authToken.subject) is valid for accessing the resource (subject)
      Specified by:
      validateAccessFor in interface IAuthService
      Parameters:
      accessToken - the accesstoken provided
      subject - the subject to match
      Returns:
      true if match and valid token
      Throws:
      ValidationError - on invalid or expired token or nonmatching user
    • refresh

      public java.lang.String refresh​(java.lang.String access, java.lang.String refreshId) throws ValidationError
      Generates a new access token given an expired accesstoken and a refresh token id
      Specified by:
      refresh in interface IAuthService
      Parameters:
      access - the expired accessToken to refresh
      refreshId - the matching refreshtoken identifier
      Returns:
      a new access token
      Throws:
      ValidationError - if invalid parameters