Class BootAuthenticator<E>

java.lang.Object
org.summerboot.jexpress.security.auth.BootAuthenticator<E>
Type Parameters:
E - authenticate(T metaData)
All Implemented Interfaces:
io.grpc.ServerInterceptor, Authenticator<E>
Direct Known Subclasses:
LDAPAuthenticator

public abstract class BootAuthenticator<E> extends Object implements Authenticator<E>, io.grpc.ServerInterceptor
Author:
Changski Tie Zheng Zhang 张铁铮, 魏泽北, 杜旺财, 杜富贵
  • Field Details

  • Constructor Details

    • BootAuthenticator

      public BootAuthenticator()
  • Method Details

    • signJWT

      public String signJWT(String username, String pwd, E metaData, int validForMinutes, ServiceContext context) throws NamingException
      Description copied from interface: Authenticator
      Success HTTP Status: 201 Created
      Specified by:
      signJWT in interface Authenticator<E>
      Parameters:
      username -
      pwd -
      metaData -
      validForMinutes -
      context -
      Returns:
      Throws:
      NamingException
    • signJWT

      public String signJWT(Caller caller, int validForMinutes, ServiceContext context)
      Description copied from interface: Authenticator
      Success HTTP Status: 201 Created
      Specified by:
      signJWT in interface Authenticator<E>
      Parameters:
      caller -
      validForMinutes -
      context -
      Returns:
    • authenticate

      protected abstract Caller authenticate(String usename, String password, E metaData, AuthenticatorListener listener, ServiceContext context) throws NamingException
      Parameters:
      usename -
      password -
      metaData -
      listener -
      context -
      Returns:
      Throws:
      NamingException
    • toJwt

      public io.jsonwebtoken.JwtBuilder toJwt(Caller caller, String txId)
      Convert Caller to auth token, override this method to implement customized token format
      Specified by:
      toJwt in interface Authenticator<E>
      Parameters:
      caller -
      txId -
      Returns:
      formatted auth token builder
    • parseJWT

      protected io.jsonwebtoken.Claims parseJWT(String jwt)
    • fromJwt

      protected Caller fromJwt(io.jsonwebtoken.Claims claims)
      Convert Caller back from auth token, override this method to implement customized token format
      Parameters:
      claims -
      Returns:
      Caller
    • getBearerToken

      protected String getBearerToken(io.netty.handler.codec.http.HttpHeaders httpRequestHeaders)
      Retrieve token based on RFC 6750 - The OAuth 2.0 Authorization Framework override this method to get customized token
      Parameters:
      httpRequestHeaders -
      Returns:
    • getBearerToken

      protected String getBearerToken(String authHeaderValue)
      Retrieve token based on RFC 6750 - The OAuth 2.0 Authorization Framework override this method to get customized token
      Parameters:
      authHeaderValue - "Bearer jwt"
      Returns:
    • verifyToken

      public Caller verifyToken(io.netty.handler.codec.http.HttpHeaders httpRequestHeaders, AuthTokenCache cache, Integer errorCode, ServiceContext context)
      Description copied from interface: Authenticator
      Success HTTP Status: 200 OK
      Specified by:
      verifyToken in interface Authenticator<E>
      Parameters:
      httpRequestHeaders -
      cache -
      errorCode -
      context -
      Returns:
    • verifyToken

      public Caller verifyToken(String authToken, AuthTokenCache cache, Integer errorCode, ServiceContext context)
      Specified by:
      verifyToken in interface Authenticator<E>
      Parameters:
      authToken -
      cache -
      errorCode -
      context -
      Returns:
    • customizedAuthorizationCheck

      public boolean customizedAuthorizationCheck(RequestProcessor processor, io.netty.handler.codec.http.HttpHeaders httpRequestHeaders, String httpRequestPath, ServiceContext context) throws Exception
      Description copied from interface: Authenticator
      Extra authorization checks before processing
      Specified by:
      customizedAuthorizationCheck in interface Authenticator<E>
      Parameters:
      processor -
      httpRequestHeaders -
      httpRequestPath -
      context -
      Returns:
      true if good to process request, otherwise false
      Throws:
      Exception
    • overrideVerifyTokenErrorCode

      protected Integer overrideVerifyTokenErrorCode()
    • logoutToken

      public void logoutToken(io.netty.handler.codec.http.HttpHeaders httpRequestHeaders, AuthTokenCache cache, ServiceContext context)
      Description copied from interface: Authenticator
      Success HTTP Status: 204 No Content
      Specified by:
      logoutToken in interface Authenticator<E>
      Parameters:
      httpRequestHeaders -
      cache -
      context -
    • logoutToken

      public void logoutToken(String authToken, AuthTokenCache cache, ServiceContext context)
      Description copied from interface: Authenticator
      Success HTTP Status: 204 No Content
      Specified by:
      logoutToken in interface Authenticator<E>
      Parameters:
      authToken -
      cache -
      context -
    • interceptCall

      public <ReqT, RespT> io.grpc.ServerCall.Listener<ReqT> interceptCall(io.grpc.ServerCall<ReqT,RespT> serverCall, io.grpc.Metadata metadata, io.grpc.ServerCallHandler<ReqT,RespT> serverCallHandler)
      gRPC JWT verification
      Specified by:
      interceptCall in interface io.grpc.ServerInterceptor
      Type Parameters:
      ReqT -
      RespT -
      Parameters:
      serverCall -
      metadata -
      serverCallHandler -
      Returns: