Class ControllerBase

java.lang.Object
com.aducid.web.controller.ControllerBase
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.web.context.ServletContextAware
Direct Known Subclasses:
AuthenticationController

public class ControllerBase
extends java.lang.Object
implements org.springframework.web.context.ServletContextAware

Controller base, which contains essential ADUCID Web Platform methods. There are also predefined authentication post processing methods, which should be overridden if you want to call custom business logic:

When working with ADUCID Web Platform, some exceptions can occur:

  • AducidStatusException - AIM status exception
  • AducidClientException - ADUCID Client API exception
  • AducidWebException - ADUCID Web Platform exception

There is limited set of exception wrappings supported:

  • AducidStatusException => AducidClientException
  • AducidStatusException => AducidClientException => AducidWebException

Exceptions AducidClientException and AducidWebException can also occur standalone. Exceptions architecture fully supports localization. There are interfaces:

  • Localizable - forces exception to support localization message key and message arguments
  • Descriptive - forces exception constructor message to support localization message key and default message

In case of ADUCID Web Platform, there is pair AducidWebException and WebStatus. AducidWebException implements Localizable interface and WebStatus implements Descriptive interface. All error message are automatically localized, if possible. Error messages are read from error resource bundles.

Created 12. 10. 2015 15:39:46

Author:
Radek Jira
  • Constructor Summary

    Constructors 
    Constructor Description
    ControllerBase()  
  • Method Summary

    Modifier and Type Method Description
    protected void afterCheck​(javax.servlet.http.HttpServletRequest httpRequest, java.lang.String id, com.aducid.principal.AducidPrincipal principal)
    Method called after check.
    protected java.lang.String afterError​(javax.servlet.http.HttpServletRequest httpRequest, java.lang.String id, java.lang.String redirect)
    Method called after error.
    protected java.lang.String appendId​(java.lang.String url, java.lang.String id)
    Appends identifier.
    protected void beforeErrorRedirect​(javax.servlet.http.HttpServletRequest httpRequest, java.lang.String id, com.aducid.sdk.enums.Status realStatus, AducidWebException webException, java.lang.Exception originalException, java.lang.String localizedMessage, java.lang.String realErrorPage)
    Method called before error redirect.
    protected java.lang.String beforeLoggedInRedirect​(javax.servlet.http.HttpServletRequest httpRequest, java.lang.String id, java.lang.String redirect)
    Method called before logged in redirect.
    protected java.lang.String beforeLogoutRedirect​(javax.servlet.http.HttpServletRequest httpRequest, java.lang.String id, java.lang.String redirect)
    Method called before logout redirect.
    void checkAnnotationConsistency()
    Checks annotation consistency.
    protected void forwardToAducidResourcesPage​(javax.servlet.http.HttpServletRequest httpRequest, javax.servlet.http.HttpServletResponse httpResponse, java.lang.String page)
    Forwards to /aducid-resources application.
    protected java.lang.String generateId()
    Generates identifier.
    java.lang.String getAducidBinder()
    Returns ADUCID Binder application context.
    java.lang.String getAducidResources()
    Returns ADUCID Resources application URL.
    protected com.aducid.sdk.AducidAdvancedClient getAdvancedClient()
    Returns ADUCID advanced client instance.
    java.lang.String getAimUrl()
    Returns AIM URL.
    protected com.aducid.sdk.pojo.RequestOperationArguments getClientArguments​(java.lang.String path, java.lang.Boolean generateQrCodePicture, javax.servlet.http.HttpServletRequest httpRequest)
    Returns client arguments.
    protected com.aducid.sdk.pojo.RequestOperationArguments getClientArguments​(java.lang.String id, java.lang.String path, java.lang.Boolean generateQrCodePicture, javax.servlet.http.HttpServletRequest httpRequest)
    Returns client arguments.
    protected com.aducid.sdk.pojo.RequestOperationArguments getClientArguments​(java.lang.String id, java.lang.String path, java.lang.String pushPeigId, java.lang.String tlsCertId, java.lang.String peigCssId, java.lang.String peigCssValue, java.lang.Boolean generateQrCodePicture, javax.servlet.http.HttpServletRequest httpRequest)
    Returns client arguments.
    java.lang.String getErrorPage()
    Returns error page.
    protected com.aducid.sdk.json.AducidJsonClient getJsonClient()
    Returns ADUCID JSON client instance.
    protected java.lang.String getLocalizedError​(java.lang.Exception exception, java.util.Locale locale)
    Returns localized error message.
    protected java.lang.String getLocalizedLocalizable​(com.aducid.sdk.common.Localizable localizable, java.util.Locale locale)
    Returns localized localizable message.
    protected java.lang.String getLocalizedStatusable​(com.aducid.sdk.common.Statusable statusable, java.util.Locale locale)
    Returns localized statusable message.
    protected com.aducid.sdk.pojo.RequestOperationArguments getPushClientArguments​(java.lang.String path, java.lang.String pushPeigId, java.lang.Boolean generateQrCodePicture, javax.servlet.http.HttpServletRequest httpRequest)
    Returns push client arguments.
    protected java.lang.String getRealAuthId​(java.lang.String id, java.lang.String authId, java.lang.String authKey, javax.servlet.http.HttpServletRequest httpRequest)
    Returns real authentication identifier.
    protected java.lang.String getRealErrorPage​(javax.servlet.http.HttpServletRequest httpRequest, java.lang.String id)
    Returns real error page.
    protected java.lang.String getRealPeigTypePicture​(java.lang.String peigTypePicture)
    Returns real PEIG type picture.
    protected com.aducid.sdk.enums.Status getRealStatus​(javax.servlet.http.HttpServletRequest httpRequest, java.lang.String id, com.aducid.sdk.enums.Status defaultStatus)
    Returns real status.
    protected com.aducid.sdk.pojo.GetPSLAttributesResponse getResult​(java.lang.String id, java.lang.String authId, java.lang.String authKey, javax.servlet.http.HttpServletRequest httpRequest)
    Returns result.
    protected com.aducid.sdk.pojo.GetPSLAttributesResponse getResultNoLFCheck​(java.lang.String id, java.lang.String authId, java.lang.String authKey, javax.servlet.http.HttpServletRequest httpRequest)
    Returns result without local factor success check.
    protected java.lang.String getRootRedirect​(javax.servlet.http.HttpServletRequest httpRequest)
    Returns root redirect.
    javax.servlet.ServletContext getServletContext()
    Returns servlet context.
    protected com.aducid.sdk.AducidClient getSimpleClient()
    Returns ADUCID simple client instance.
    protected java.lang.String getUrl​(javax.servlet.http.HttpServletRequest request)
    Builds URL from request.
    protected java.lang.String getUrl​(javax.servlet.http.HttpServletRequest request, java.lang.String path)
    Builds URL from request and path.
    protected java.lang.String getUrl​(javax.servlet.http.HttpServletRequest request, java.lang.String contextPath, java.lang.String path)
    Builds URL from request, context path and path.
    protected com.aducid.sdk.pojo.GetPSLAttributesResponse getVerificationResult​(java.lang.String id, java.lang.String authId, java.lang.String authKey, javax.servlet.http.HttpServletRequest httpRequest)
    Returns verification result.
    protected com.aducid.sdk.pojo.GetPSLAttributesResponse getVerifyMessageResult​(java.lang.String id, java.lang.String authId, java.lang.String authKey, javax.servlet.http.HttpServletRequest httpRequest)
    Returns verify message result.
    protected WebRequestOperationResult getWebResult​(com.aducid.sdk.pojo.RequestOperationResult clientResult, javax.servlet.http.HttpServletRequest httpRequest)
    Returns web result.
    protected boolean isJson​(javax.servlet.http.HttpServletRequest httpRequest)
    Checks JSON method call.
    protected org.springframework.web.servlet.ModelAndView processWebError​(AducidWebException webException, javax.servlet.http.HttpServletRequest httpRequest, java.util.Locale locale)
    Processes ADUCID Web Platform exception.
    protected void removeErrorFromSession​(javax.servlet.http.HttpServletRequest httpRequest, java.lang.String id)
    Removes error from session.
    protected void setErrorToRequest​(javax.servlet.http.HttpServletRequest httpRequest, java.lang.String id)
    Sets error to request.
    void setServletContext​(javax.servlet.ServletContext servletContext)

    Methods inherited from class java.lang.Object

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

  • Method Details

    • setServletContext

      public void setServletContext​(javax.servlet.ServletContext servletContext)
      Specified by:
      setServletContext in interface org.springframework.web.context.ServletContextAware
    • getServletContext

      public javax.servlet.ServletContext getServletContext()

      Returns servlet context.

      Returns:
      servlet context
    • getAimUrl

      public java.lang.String getAimUrl()

      Returns AIM URL.

      Returns:
      AIM URL
    • getErrorPage

      public java.lang.String getErrorPage()

      Returns error page.

      Returns:
      error page
    • getAducidResources

      public java.lang.String getAducidResources()

      Returns ADUCID Resources application URL.

      Returns:
      ADUCID Resources application URL
    • getAducidBinder

      public java.lang.String getAducidBinder()

      Returns ADUCID Binder application context.

      Returns:
      ADUCID Binder application context.
    • checkAnnotationConsistency

      @PostConstruct public void checkAnnotationConsistency()

      Checks annotation consistency. Method mapping have to have the same name as method name. It is required by error processing when making decision about error type - classic HTTP response or JSON data structure.

    • afterCheck

      protected void afterCheck​(javax.servlet.http.HttpServletRequest httpRequest, java.lang.String id, com.aducid.principal.AducidPrincipal principal) throws AducidWebException

      Method called after check. Method should be overridden, if you want to call custom business logic.

      Parameters:
      httpRequest - HTTP request
      id - identifier
      principal - principal
      Throws:
      AducidWebException - when error occurs during web controller call
    • afterError

      protected java.lang.String afterError​(javax.servlet.http.HttpServletRequest httpRequest, java.lang.String id, java.lang.String redirect)

      Method called after error. Method should be overridden, if you want to call custom business logic.

      Parameters:
      httpRequest - HTTP request
      id - identifier
      redirect - original redirect
      Returns:
      URL, where to redirect user after unsuccessful login
    • beforeLoggedInRedirect

      protected java.lang.String beforeLoggedInRedirect​(javax.servlet.http.HttpServletRequest httpRequest, java.lang.String id, java.lang.String redirect) throws AducidWebException

      Method called before logged in redirect. Method should be overridden, if you want to call custom business logic.

      Parameters:
      httpRequest - HTTP request
      id - identifier
      redirect - original redirect
      Returns:
      URL, where to redirect user instead of original redirect
      Throws:
      AducidWebException - when error occurs during web controller call
    • beforeLogoutRedirect

      protected java.lang.String beforeLogoutRedirect​(javax.servlet.http.HttpServletRequest httpRequest, java.lang.String id, java.lang.String redirect) throws AducidWebException

      Method called before logout redirect. Method should be overridden, if you want to call custom business logic.

      Parameters:
      httpRequest - HTTP request
      id - identifier
      redirect - original redirect
      Returns:
      URL, where to redirect user instead of original redirect
      Throws:
      AducidWebException - when error occurs during web controller call
    • beforeErrorRedirect

      protected void beforeErrorRedirect​(javax.servlet.http.HttpServletRequest httpRequest, java.lang.String id, com.aducid.sdk.enums.Status realStatus, AducidWebException webException, java.lang.Exception originalException, java.lang.String localizedMessage, java.lang.String realErrorPage)

      Method called before error redirect. Method should be overridden, if you want to call custom business logic.

      Parameters:
      httpRequest - HTTP request
      id - identifier
      realStatus - real status
      webException - ADUCID Web Platform exception
      originalException - original exception
      localizedMessage - localized message
      realErrorPage - real error page
    • getPushClientArguments

      protected com.aducid.sdk.pojo.RequestOperationArguments getPushClientArguments​(java.lang.String path, java.lang.String pushPeigId, java.lang.Boolean generateQrCodePicture, javax.servlet.http.HttpServletRequest httpRequest) throws AducidWebException

      Returns push client arguments.

      Parameters:
      path - path
      pushPeigId - push PEIG identifier
      generateQrCodePicture - generate QR code picture flag value
      httpRequest - HTTP request
      Returns:
      request operation arguments
      Throws:
      AducidWebException - when error occurs during web controller call
    • getClientArguments

      protected com.aducid.sdk.pojo.RequestOperationArguments getClientArguments​(java.lang.String path, java.lang.Boolean generateQrCodePicture, javax.servlet.http.HttpServletRequest httpRequest)

      Returns client arguments.

      Parameters:
      path - path
      generateQrCodePicture - generate QR code picture flag value
      httpRequest - HTTP request
      Returns:
      request operation arguments
    • getClientArguments

      protected com.aducid.sdk.pojo.RequestOperationArguments getClientArguments​(java.lang.String id, java.lang.String path, java.lang.Boolean generateQrCodePicture, javax.servlet.http.HttpServletRequest httpRequest)

      Returns client arguments.

      Parameters:
      id - identifier
      path - path
      generateQrCodePicture - generate QR code picture flag value
      httpRequest - HTTP request
      Returns:
      request operation arguments
    • getClientArguments

      protected com.aducid.sdk.pojo.RequestOperationArguments getClientArguments​(java.lang.String id, java.lang.String path, java.lang.String pushPeigId, java.lang.String tlsCertId, java.lang.String peigCssId, java.lang.String peigCssValue, java.lang.Boolean generateQrCodePicture, javax.servlet.http.HttpServletRequest httpRequest)

      Returns client arguments.

      Parameters:
      id - identifier
      path - path
      pushPeigId - push PEIG identifier
      tlsCertId - TLS certificate identifier
      peigCssId - PEIG CSS identifier
      peigCssValue - PEIG CSS value
      generateQrCodePicture - generate QR code picture flag value
      httpRequest - HTTP request
      Returns:
      request operation arguments
    • getWebResult

      protected WebRequestOperationResult getWebResult​(com.aducid.sdk.pojo.RequestOperationResult clientResult, javax.servlet.http.HttpServletRequest httpRequest)

      Returns web result.

      Parameters:
      clientResult - client result
      httpRequest - HTTP request
      Returns:
      web request operation result
    • getRealAuthId

      protected java.lang.String getRealAuthId​(java.lang.String id, java.lang.String authId, java.lang.String authKey, javax.servlet.http.HttpServletRequest httpRequest) throws AducidWebException

      Returns real authentication identifier.

      Parameters:
      id - identifier
      authId - authentication identifier
      authKey - authentication key
      httpRequest - HTTP request
      Returns:
      real authentication identifier
      Throws:
      AducidWebException - when error occurs during web controller call
    • getResult

      protected com.aducid.sdk.pojo.GetPSLAttributesResponse getResult​(java.lang.String id, java.lang.String authId, java.lang.String authKey, javax.servlet.http.HttpServletRequest httpRequest) throws AducidWebException

      Returns result.

      Parameters:
      id - identifier
      authId - authentication identifier
      authKey - authentication key
      httpRequest - HTTP request
      Returns:
      result
      Throws:
      AducidWebException - when error occurs during web controller call
    • getResultNoLFCheck

      protected com.aducid.sdk.pojo.GetPSLAttributesResponse getResultNoLFCheck​(java.lang.String id, java.lang.String authId, java.lang.String authKey, javax.servlet.http.HttpServletRequest httpRequest) throws AducidWebException

      Returns result without local factor success check.

      Parameters:
      id - identifier
      authId - authentication identifier
      authKey - authentication key
      httpRequest - HTTP request
      Returns:
      result
      Throws:
      AducidWebException - when error occurs during web controller call
    • getVerifyMessageResult

      protected com.aducid.sdk.pojo.GetPSLAttributesResponse getVerifyMessageResult​(java.lang.String id, java.lang.String authId, java.lang.String authKey, javax.servlet.http.HttpServletRequest httpRequest) throws AducidWebException

      Returns verify message result.

      Parameters:
      id - identifier
      authId - authentication identifier
      authKey - authentication key
      httpRequest - HTTP request
      Returns:
      result
      Throws:
      AducidWebException - when error occurs during web controller call
    • getVerificationResult

      protected com.aducid.sdk.pojo.GetPSLAttributesResponse getVerificationResult​(java.lang.String id, java.lang.String authId, java.lang.String authKey, javax.servlet.http.HttpServletRequest httpRequest) throws AducidWebException

      Returns verification result.

      Parameters:
      id - identifier
      authId - authentication identifier
      authKey - authentication key
      httpRequest - HTTP request
      Returns:
      result
      Throws:
      AducidWebException - when error occurs during web controller call
    • getLocalizedError

      protected java.lang.String getLocalizedError​(java.lang.Exception exception, java.util.Locale locale)

      Returns localized error message.

      Parameters:
      exception - common exception
      locale - locale
      Returns:
      localized error message
    • getLocalizedLocalizable

      protected java.lang.String getLocalizedLocalizable​(com.aducid.sdk.common.Localizable localizable, java.util.Locale locale)

      Returns localized localizable message.

      Parameters:
      localizable - localizable exception
      locale - locale
      Returns:
      localized localizable message
    • getLocalizedStatusable

      protected java.lang.String getLocalizedStatusable​(com.aducid.sdk.common.Statusable statusable, java.util.Locale locale)

      Returns localized statusable message.

      Parameters:
      statusable - statusable exception
      locale - locale
      Returns:
      localized statusable message
    • getJsonClient

      protected com.aducid.sdk.json.AducidJsonClient getJsonClient() throws AducidWebException

      Returns ADUCID JSON client instance.

      Returns:
      ADUCID JSON client instance
      Throws:
      AducidWebException - when error occurs during web controller call
    • getAdvancedClient

      protected com.aducid.sdk.AducidAdvancedClient getAdvancedClient() throws AducidWebException

      Returns ADUCID advanced client instance.

      Returns:
      ADUCID advanced client instance
      Throws:
      AducidWebException - when error occurs during web controller call
    • getSimpleClient

      protected com.aducid.sdk.AducidClient getSimpleClient() throws AducidWebException

      Returns ADUCID simple client instance.

      Returns:
      ADUCID simple client instance
      Throws:
      AducidWebException - when error occurs during web controller call
    • getUrl

      protected java.lang.String getUrl​(javax.servlet.http.HttpServletRequest request)

      Builds URL from request.

      Parameters:
      request - HTTP request
      Returns:
      URL
    • getUrl

      protected java.lang.String getUrl​(javax.servlet.http.HttpServletRequest request, java.lang.String path)

      Builds URL from request and path.

      Parameters:
      request - HTTP request
      path - path
      Returns:
      URL
    • getUrl

      protected java.lang.String getUrl​(javax.servlet.http.HttpServletRequest request, java.lang.String contextPath, java.lang.String path)

      Builds URL from request, context path and path.

      Parameters:
      request - HTTP request
      contextPath - context path
      path - path
      Returns:
      URL
    • getRealPeigTypePicture

      protected java.lang.String getRealPeigTypePicture​(java.lang.String peigTypePicture)

      Returns real PEIG type picture.

      Parameters:
      peigTypePicture - PEIG type picture
      Returns:
      real PEIG type picture
    • forwardToAducidResourcesPage

      protected void forwardToAducidResourcesPage​(javax.servlet.http.HttpServletRequest httpRequest, javax.servlet.http.HttpServletResponse httpResponse, java.lang.String page) throws AducidWebException

      Forwards to /aducid-resources application.

      Parameters:
      httpRequest - HTTP request
      httpResponse - HTTP response
      page - page
      Throws:
      AducidWebException - when error occurs during web controller call
    • isJson

      protected boolean isJson​(javax.servlet.http.HttpServletRequest httpRequest)

      Checks JSON method call.

      Parameters:
      httpRequest - HTTP request
      Returns:
      true, if method call is JSON
    • getRootRedirect

      protected java.lang.String getRootRedirect​(javax.servlet.http.HttpServletRequest httpRequest)

      Returns root redirect.

      Parameters:
      httpRequest - HTTP request
      Returns:
      root redirect
    • getRealErrorPage

      protected java.lang.String getRealErrorPage​(javax.servlet.http.HttpServletRequest httpRequest, java.lang.String id)

      Returns real error page.

      Parameters:
      httpRequest - HTTP request
      id - identifier
      Returns:
      real error page
    • getRealStatus

      protected com.aducid.sdk.enums.Status getRealStatus​(javax.servlet.http.HttpServletRequest httpRequest, java.lang.String id, com.aducid.sdk.enums.Status defaultStatus)

      Returns real status.

      Parameters:
      httpRequest - HTTP request
      id - identifier
      defaultStatus - default status
      Returns:
      real status
    • processWebError

      @ExceptionHandler(AducidWebException.class) protected org.springframework.web.servlet.ModelAndView processWebError​(AducidWebException webException, javax.servlet.http.HttpServletRequest httpRequest, java.util.Locale locale)

      Processes ADUCID Web Platform exception.

      Parameters:
      webException - ADUCID Web Platform exception
      httpRequest - HTTP request
      locale - locale
      Returns:
      model and view
    • removeErrorFromSession

      protected void removeErrorFromSession​(javax.servlet.http.HttpServletRequest httpRequest, java.lang.String id)

      Removes error from session.

      Parameters:
      httpRequest - HTTP request
      id - identifier
    • setErrorToRequest

      protected void setErrorToRequest​(javax.servlet.http.HttpServletRequest httpRequest, java.lang.String id)

      Sets error to request.

      Parameters:
      httpRequest - HTTP request
      id - identifier
    • generateId

      protected java.lang.String generateId()

      Generates identifier.

      Returns:
      identifier
    • appendId

      protected java.lang.String appendId​(java.lang.String url, java.lang.String id)

      Appends identifier.

      Parameters:
      url - URL
      id - identifier
      Returns:
      URL with identifier