3636import act .handler .event .ResultEvent ;
3737import act .i18n .I18n ;
3838import act .security .CSRFProtector ;
39- import act .session .CookieSessionMapper ;
40- import act .session .DefaultSessionCodec ;
41- import act .session .HeaderTokenSessionMapper ;
42- import act .session .SessionCodec ;
39+ import act .session .*;
4340import act .util .*;
4441import act .view .TemplatePathResolver ;
4542import act .view .View ;
@@ -119,9 +116,13 @@ public AppConfig<T> app(App app) {
119116 }
120117
121118 public void preloadConfigurations () {
119+ // ensure JWT get evaluated first to set
120+ // default value for dependency settings
121+ jwt ();
122+
122123 for (Method method : AppConfig .class .getDeclaredMethods ()) {
123124 boolean isPublic = Modifier .isPublic (method .getModifiers ());
124- if (isPublic && 0 == method .getParameterTypes ().length && void . class != method . getReturnType () && Void . class != method .getReturnType ( )) {
125+ if (isPublic && 0 == method .getParameterTypes ().length && ! "preloadConfigurations" . equals ( method .getName () )) {
125126 $ .invokeVirtual (this , method );
126127 }
127128 }
@@ -934,6 +935,37 @@ private void _mergeI18nEnabled(AppConfig conf) {
934935 i18nEnabled = conf .i18nEnabled ;
935936 }
936937 }
938+
939+ private Boolean jwt ;
940+ protected T jwt (boolean enabled ) {
941+ jwt = enabled ;
942+ return me ();
943+ }
944+ public boolean jwt () {
945+ if (null == jwt ) {
946+ jwt = get (JWT , false );
947+ if (jwt ) {
948+ if (!hasConfiguration (SESSION_HEADER )) {
949+ sessionHeader ("Authorization" );
950+ }
951+ if (!hasConfiguration (SESSION_HEADER_PAYLOAD_PREFIX )) {
952+ sessionHeaderPayloadPrefix ("Bearer " );
953+ }
954+ if (!hasConfiguration (SESSION_MAPPER )) {
955+ sessionMapper (new HeaderTokenSessionMapper (this ));
956+ }
957+ if (!hasConfiguration (SESSION_CODEC )) {
958+ sessionCodec (new JsonWebTokenSessionCodec (this ));
959+ }
960+ }
961+ }
962+ return jwt ;
963+ }
964+ private void _mergeJWT (AppConfig config ) {
965+ if (!hasConfiguration (JWT )) {
966+ jwt = config .jwt ;
967+ }
968+ }
937969
938970 private String localeParamName ;
939971 protected T localeParamName (String name ) {
@@ -1963,9 +1995,8 @@ private void _mergeSessionEncrpt(AppConfig config) {
19631995
19641996 private act .session .SessionMapper sessionMapper = null ;
19651997
1966- protected T sessionMapper (act .session .SessionMapper sessionMapper ) {
1998+ protected void sessionMapper (act .session .SessionMapper sessionMapper ) {
19671999 this .sessionMapper = sessionMapper ;
1968- return me ();
19692000 }
19702001
19712002 public act .session .SessionMapper sessionMapper () {
@@ -1983,9 +2014,8 @@ private void _mergeSessionMapper(AppConfig config) {
19832014
19842015 private SessionCodec sessionCodec = null ;
19852016
1986- protected T sessionCodec (SessionCodec codec ) {
2017+ protected void sessionCodec (SessionCodec codec ) {
19872018 this .sessionCodec = $ .notNull (codec );
1988- return me ();
19892019 }
19902020
19912021 public SessionCodec sessionCodec () {
@@ -2001,6 +2031,25 @@ private void _mergeSessionCodec(AppConfig config) {
20012031 }
20022032 }
20032033
2034+ private String sessionHeader ;
2035+ private boolean sessionHeaderSet ;
2036+ protected void sessionHeader (String header ) {
2037+ this .sessionHeader = header ;
2038+ this .sessionHeaderSet = true ;
2039+ }
2040+ public String sessionHeader () {
2041+ if (!sessionHeaderSet ) {
2042+ sessionHeader = get (SESSION_HEADER , null );
2043+ sessionHeaderSet = true ;
2044+ }
2045+ return sessionHeader ;
2046+ }
2047+ private void _mergeSessionHeader (AppConfig conf ) {
2048+ if (!hasConfiguration (SESSION_HEADER )) {
2049+ sessionHeader = conf .sessionHeader ;
2050+ sessionHeaderSet = conf .sessionHeaderSet ;
2051+ }
2052+ }
20042053
20052054 private String sessionHeaderPrefix ;
20062055 protected T sessionHeaderPrefix (String prefix ) {
@@ -2015,9 +2064,8 @@ public String sessionHeaderPrefix() {
20152064 }
20162065
20172066 private String sessionHeaderPayloadPrefix = null ;
2018- protected T sessionHeaderPayloadPrefix (String prefix ) {
2067+ protected void sessionHeaderPayloadPrefix (String prefix ) {
20192068 this .sessionHeaderPayloadPrefix = prefix ;
2020- return me ();
20212069 }
20222070 public String sessionHeaderPayloadPrefix () {
20232071 if (null == sessionHeaderPayloadPrefix ) {
0 commit comments