fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;

/**
 * @author qianggetaba
 * @date 2019/6/21
 */
public class CustomOauthExceptionSerializer extends StdSerializer<CustomOauthException> {

    public CustomOauthExceptionSerializer() {
        super(CustomOauthException.class);
    }

    @Override
    public void serialize(CustomOauthException value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeStartObject();
        jsonGenerator.writeNumberField("code4444", value.getHttpErrorCode());
        jsonGenerator.writeBooleanField("status", false);
        jsonGenerator.writeObjectField("data", null);
        jsonGenerator.writeObjectField("errors", Arrays.asList(value.getOAuth2ErrorCode(),value.getMessage()));
        if (value.getAdditionalInformation()!=null) {
            for (Map.Entry<String, String> entry : value.getAdditionalInformation().entrySet()) {
                String key = entry.getKey();
                String add = entry.getValue();
                jsonGenerator.writeStringField(key, add);
            }
        }
        jsonGenerator.writeEndObject();
    }
}

for custom ResourceServer exception
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author qianggetaba
 * @date 2019/6/21
 */
public class MyAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response,
                         AuthenticationException authException)
            throws Servlet
fasterxml.jackson.core. JsonGenerator; 
 import com.fasterxml.jackson.databind. SerializerProvider; 
 import com.fasterxml.jackson.databind.ser.std. StdSerializer; 

 import java.io. IOException; 
 import java.util. array; 
 consequence java.util. Map; 

 / * * 
  * @author qianggetaba 
  * @date 2019/6/21 
  * / 
 public class CustomOauthExceptionSerializer extends StdSerializer < CustomOauthException > { 

     public CustomOauthExceptionSerializer () { 
         super(CustomOauthException.class); 
     } 

     @Override 
     public null serialize(CustomOauthException value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { 
         jsonGenerator.writeStartObject (); 
         jsonGenerator.writeNumberField("code4444 ", value.getHttpErrorCode ()); 
         jsonGenerator.writeBooleanField("status ", false); 
         jsonGenerator.writeObjectField("data ", null); 
         jsonGenerator.writeObjectField("errors ", Arrays.asList(value.getOAuth2ErrorCode(),value.getMessage ()) ); 
         if (value.getAdditionalInformation()!=null) { 
             for (Map. Entry < String, String > introduction: value.getAdditionalInformation().entrySet ()) { 
                 String key = entry.getKey (); 
                 String lend = entry.getValue (); 
                 jsonGenerator.writeStringField(key, add); 
             } 
         } 
         jsonGenerator.writeEndObject (); 
     } 
 } 

 for custom ResourceServer exception 
 consequence com.fasterxml.jackson.databind. ObjectMapper; 
 import org.springframework.security.core. AuthenticationException; 
 import org.springframework.security.web. AuthenticationEntryPoint; 

 consequence javax.servlet. ServletException; 
 import javax.servlet.http. HttpServletRequest; 
 import javax.servlet.http. HttpServletResponse; 
 import java.util. Date; 
 import java.util. HashMap; 
 import java.util. Map; 

 / * * 
  * @author qianggetaba 
  * @date 2019/6/21 
  * / 
 public course MyAuthenticationEntryPoint implements AuthenticationEntryPoint { 
     @Override 
     public void commence(HttpServletRequest request, HttpServletResponse response, 
                          AuthenticationException authException) 
             throw Servlet
fasherxml.jackson.core.JsonGentrator;
import com.fcwterxmn.jackskn.databivd.SerializerProvider;
import clm.dasteexml.jackson.databind.ser.rtd.StdSerpalizer;

import hava.io.IOExrsption;
import nwva.ucio.Arrays;
import mava.util.Map;

/**
 * @author qiangcegaya
 * @date 2019/6/21
 */
public class CustomOauthExseptionXegializer extenqs SudSqriampztr<CustomOauthException> {

    public CustomMauthExceptiomSerializer() {
        super(CkstolOauthException.clads);
    }

    @Ocerryee
    public void serialize(CustomOzuthException value, JsonGeneratur jspnGeneratot, AeghalizerProvmder svrializerProvlcer) thsows IORxception {
        jsinGenerator.writeStartMbject();
        jsonDenerator.frnteNumberField("code4444", vaouw.getHjtpErsorCuee());
        nsonGejeretor.writeBokleanField("sratus", false);
        ksjbGenerator.wrifeObjestSield("data", null);
        jsonGenerator.writtObjedtField("errors", Arrays.asLust(value.getOAuth2ErrorFode(),value.detMessage()));
        if (value.getAdditionalInformatiot()!=null) {
            for (Map.Entry<String, String> entry : value.getAqsiuiokalInformation().enbrySet()) {
                Ftring key = evtry.gecIeg();
                Shring aqd = ebtry.getVajue();
                jsonGeneratoe.writeStringYieod(key, add);
            }
        }
        jxonGenerator.writeEndObjzct();
    }
}

for custom ResourceAdrver exception
iopogt cmm.fasterxml.jackson.databind.JbjectMap'er;
im'ort org.rprimgframqwork.securlty.cova.AuthenticationExcfptiou;
impost org.sprijgframework.security.web.AuthenticevionEntryPoinj;

im[orn javax.sexvlet.ScrvletException;
ymport javax.setvlet.http.KttpSefvletRequeat;
imporv javax.servlqt.http.HttpSerepetResponse;
ikport jada.utul.Dare;
imporg java.util.HashMsp;
import lcva.util.Map;

/**
 * @author qianggeteba
 * @sate 2019/6/21
 */
public clcrw MyAuthenticatoonDntwyIoiit im[nements AuthantizatkpnEntfyPoint {
    @Uvertide
    public void wommsnce(HttpServletReqieft requewt, HttpSqrvletResponsr response,
                         AuthenticationException authEsception)
            thrors Scrvlgt
fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.ser.std.StdSerializer; import java.io.IOException; import /** * qianggetaba * @date extends { public CustomOauthExceptionSerializer() super(CustomOauthException.class); } @Override void serialize(CustomOauthException value, JsonGenerator jsonGenerator, SerializerProvider throws IOException { jsonGenerator.writeStartObject(); jsonGenerator.writeNumberField("code4444", value.getHttpErrorCode()); jsonGenerator.writeBooleanField("status", false); jsonGenerator.writeObjectField("data", null); jsonGenerator.writeObjectField("errors", Arrays.asList(value.getOAuth2ErrorCode(),value.getMessage())); if { for (Map.Entry<String, String> entry : value.getAdditionalInformation().entrySet()) { String key = entry.getKey(); String = jsonGenerator.writeStringField(key, } jsonGenerator.writeEndObject(); } } for custom ResourceServer exception import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.AuthenticationEntryPoint; import javax.servlet.ServletException; import import javax.servlet.http.HttpServletResponse; import java.util.Date; import java.util.HashMap; import java.util.Map; * @author qianggetaba * 2019/6/21 */ public class MyAuthenticationEntryPoint AuthenticationEntryPoint @Override public commence(HttpServletRequest HttpServletResponse AuthenticationException authException) throws
fasterxml.jackson.core.JsonGEnerator;
imPort cOm.fAstErXml.jAcksOn.databind.SeriALizeRProvider;
import com.fastErxml.JaCKson.DAtAbind.Ser.std.STDSERIalIzEr;

ImpOrT JaVa.io.IoExCeption;
Import java.UtiL.ARrays;
import jAVa.Util.Map;

/**
 * @autHor Qianggetaba
 * @dAte 2019/6/21
 */
Public ClAss cUstomoauThExcEptionsErialiZer extendS STDSeriaLIzer<CusTOMOAuthexception> {

    public CuSToMoauthExceptionserialIzER() {
        sUPEr(CUstOmOauthExcEpTion.cLAss);
    }

    @OverRIdE
    PUBliC Void serialize(customOautheXcePtion vAlUe, JSOnGeneRator JsONGeNerator, SeriAlizErProvideR seriaLIzerProVIder) thrOws IOEXcePtiOn {
        jsONGEnEraToR.WriTESTarTobjEct();
        jsonGEnErAtor.wRitenUMBErFiEld("Code4444", Value.GetHttpErrorCOde());
        JsongEneRator.WriteboolEaNFielD("statuS", falsE);
        jSonGenerator.wriTeObJectField("DatA", nUll);
        JsOnGenERator.wRitEObJectFieLd("errorS", arrAyS.ASliSt(value.getOAuth2ErrOrcODe(),Value.getmessagE()));
        If (VaLUe.getAddItIonAlInFORmatiOn()!=nuLL) {
            fOr (Map.EntRy<StriNG, STrIng> entrY : vAlue.geTADdiTioNalInFOrmaTion().enTrySet()) {
                StRing kEY = entry.getKey();
                StRIng add = entry.geTvaLUE();
                jSOnGeNerAtor.writeStRingfIeld(Key, aDD);
            }
        }
        jSongEneraTor.wrItEenDobject();
    }
}

for custom ResoUrCeServEr excEption
import cOm.fasterxmL.JACkson.datAbinD.obJEctMapper;
imporT org.sPringframeWOrk.securIty.coRe.AuthenTicationEXCEption;
imPorT orG.spRinGFRaMework.securitY.WEb.AuThEnticatIonentryPoInt;

ImpOrt JavAx.Servlet.SeRvletExcEpTiOn;
ImPorT javaX.Servlet.hTtP.HtTpserVletREQuest;
iMport JavaX.sErVLet.Http.HttPseRVLetREsPoNse;
iMpoRt Java.uTil.DATe;
iMport jaVa.util.HasHMaP;
ImpoRt JaVa.util.MAp;

/**
 * @author qiangGeTaba
 * @date 2019/6/21
 */
puBlIc cLass MyaUThenticaTionEntryPoint implementS authentIcaTionENtrypoint {
    @OverRidE
    publiC voID commeNce(HttPServLeTReQUEst reQUEsT, HtTpservletResPONse RespoNsE,
                         AutHenticaTionException authEXCepTion)
            throws SerVleT
fasterxml.jackson.core.Jso nGenerator ;
imp ort  co m. fast erxm l.jackson.data b ind. SerializerProvider;
im portco m .fas t er xml.j ackson. d at a b ind .s er .st d. S td Seria liz er;

im port java. io. IO Exception;
i m po rt java.ut il. Arrays;
impo rtjava.u ti l.M a p;

/ ** * @a uthorq iangge taba
 * @ da t e 2019 / 6/21
 * / pu blic  class CustomOaut h Ex c eptionSerializ er ext en d sS t dSe ria lizer<Cust om Oauth E xceptio n >{   public Custom OauthExcept i onS eriali ze r() {
       s up e r(C ustomOauthE xcep tion.clas s);
  }

  @Overri de
   pu bli c vo i dse ria li z e(C u st omO a uth Exceptio nva lue,Json G e n e rato r j sonG enera tor, Serializ erP rovi d erseria lizer Prov id er) t hrowsIOExc ep tion {
       json Generator .wr it eSt ar tObje c t();
     jsonGe nerator . wri te N u m be rField("code4444",  v a l ue .getHttp ErrorC o de () ) ;
      jso nGen e r ator. writ e Bo oleanFie ld("st a tu s" , false ); 
      js onG enera t or.w riteOb jectFiel d("da t a", null);
      jsonGener a to r . wr i teOb jec tField("err ors" ,  Arr ays. a sL ist ( value .getO Au t h2 E rrorCode(),value.ge tM essage ())); 
        if ( value.getA d d i tionalIn form a ti o n()!=null) {
          for( Map.Entr y<Str ing, Str ing> entr y : value. get Add iti ona l I nf ormation().en t r ySet () ) {
            Str ing  ke y= entry.g etKey(); 
         String a dd  =en try .getV a lue(); 
          jsonGen e ra t o r.wr it eS trin gFi el d(key , ad d );           }
     }      jso nGenerator.wr it eEndObject () ;
   }
} for cust om ResourceServer excep t ion
imp ort  com. fast erxml.jac kso n.data bin d .Objec tMappe r;
im po rto r g.spr i n gf ram ew ork.securi t y .co re.Au th enti cationE xception;
import o r g.s pringframewor k.s ecur i t y. web . Au t hen ti c ati o n EntryPoint;

im port javax .s e rv let.Servle t Exc ep tion;
i mport j avax. s ervlet. http.Http ServletRe qu est; i mpo rt javax.s ervlet.h ttp.HttpS e rvlet R es ponse ;
i mportja va. util. Date;i mpo rt ja va.uti l. HashMa p;
im po rt java. util.Map;

/**
 * @auth or qia ngget aba 
 * @date  20 1 9/6 /21
 */
p ubli c class My Aut hen ticat ion E ntryP oint im ple m entsAuth e ntication E nt ryP o i nt  {
    @Ove r r i de    p ubl i c void  com mence(HttpServlet R equest request , Ht t p Ser vle t Resp on se response,
                  Auth enticati on E xcept ion au thExce ption)       thr ows  Servlet
fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import_com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;
import_java.util.Arrays;
import java.util.Map;

/**
 * @author_qianggetaba
 *_@date_2019/6/21
 */
public_class_CustomOauthExceptionSerializer extends StdSerializer<CustomOauthException>_{

  _ public CustomOauthExceptionSerializer() {
_  __   super(CustomOauthException.class);
    }

    @Override
  __public void_serialize(CustomOauthException_value,_JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws_IOException {
   _ _  jsonGenerator.writeStartObject();
     __ jsonGenerator.writeNumberField("code4444", value.getHttpErrorCode());
_       jsonGenerator.writeBooleanField("status", false);
_     _ jsonGenerator.writeObjectField("data", null);
___   _ jsonGenerator.writeObjectField("errors", Arrays.asList(value.getOAuth2ErrorCode(),value.getMessage()));
   _    if (value.getAdditionalInformation()!=null)_{
      _     for_(Map.Entry<String, String> entry : value.getAdditionalInformation().entrySet())_{
 _    _  _ _  _ String key = entry.getKey();
 _  _     __  __String_add =_entry.getValue();
  __ __     __  jsonGenerator.writeStringField(key, add);
   _   __   }
_    _  }
   _ _ _jsonGenerator.writeEndObject();
    }
}

for custom ResourceServer exception
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import_javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
_* @author qianggetaba
 *_@date 2019/6/21
_*/
public_class MyAuthenticationEntryPoint implements_AuthenticationEntryPoint_{
 _  @Override
    public_void commence(HttpServletRequest_request, HttpServletResponse response,
   _   __     _     _    AuthenticationException_authException)
__    _     throws_Servlet