66import java .util .concurrent .locks .Lock ;
77import java .util .concurrent .locks .ReentrantLock ;
88
9- import jakarta .servlet .http .HttpSession ;
10-
119import com .enonic .app .oidcidprovider .mapper .ContextMapper ;
1210import com .enonic .xp .portal .PortalRequest ;
1311import com .enonic .xp .script .bean .BeanContext ;
1917public class PortalRequestBean
2018 implements ScriptBean
2119{
22- private static final String AUTO_LOGIN_FAILED_ATTRIBUTE = PortalRequestBean . class . getName () + ".autoLoginFailed" ;
20+ private static final Lock LOCK = new ReentrantLock () ;
2321
24- private static final String CONTEXT_KEY = "com.enonic.app.oidcidprovider.context" ;
22+ private String contextSessionKey ;
2523
26- private static final String ID_TOKEN_KEY = "com.enonic.app.oidcidprovider.idtoken" ;
24+ private String idTokenSessionKey ;
2725
28- private static final Lock LOCK = new ReentrantLock () ;
26+ private String autoLoginAttr ;
2927
3028 private PortalRequest portalRequest ;
3129
@@ -41,8 +39,8 @@ public void storeContext( final String state, final String nonce, final String o
4139 {
4240 final var contextMap = new ConcurrentHashMap <String , Map <String , String >>();
4341
44- final HttpSession session = portalRequest .getRawRequest ().getSession ( true );
45- Map <String , Map <String , String >> existingContextMap = (Map ) session .getAttribute ( CONTEXT_KEY );
42+ final var session = portalRequest .getRawRequest ().getSession ( true );
43+ Map <String , Map <String , String >> existingContextMap = (Map ) session .getAttribute ( contextSessionKey );
4644
4745 if ( existingContextMap != null )
4846 {
@@ -54,7 +52,7 @@ public void storeContext( final String state, final String nonce, final String o
5452
5553 contextMap .put ( state , context .asMap () );
5654
57- session .setAttribute ( CONTEXT_KEY , Collections .unmodifiableMap ( contextMap ) );
55+ session .setAttribute ( contextSessionKey , Collections .unmodifiableMap ( contextMap ) );
5856 }
5957 finally
6058 {
@@ -68,15 +66,15 @@ public ContextMapper removeContext( final String state )
6866 LOCK .lock ();
6967 try
7068 {
71- final HttpSession session = portalRequest .getRawRequest ().getSession ( false );
69+ final var session = portalRequest .getRawRequest ().getSession ( false );
7270
7371 if ( session == null )
7472 {
7573 throw new WebException ( HttpStatus .UNAUTHORIZED , "No session" );
7674 }
7775
78- final Map <String , Map <String , String >> contextMap = (Map ) session .getAttribute ( CONTEXT_KEY );
79- session .removeAttribute ( CONTEXT_KEY );
76+ final Map <String , Map <String , String >> contextMap = (Map ) session .getAttribute ( contextSessionKey );
77+ session .removeAttribute ( contextSessionKey );
8078
8179 if ( contextMap == null )
8280 {
@@ -106,29 +104,32 @@ public ContextMapper removeContext( final String state )
106104
107105 public void storeIdToken ( final String idToken )
108106 {
109- final HttpSession session = portalRequest .getRawRequest ().getSession ( true );
110- session .setAttribute ( ID_TOKEN_KEY , idToken );
107+ final var session = portalRequest .getRawRequest ().getSession ( true );
108+ session .setAttribute ( idTokenSessionKey , idToken );
111109 }
112110
113111 public String getIdToken ()
114112 {
115- final HttpSession session = portalRequest .getRawRequest ().getSession ( false );
116- return session != null ? (String ) session .getAttribute ( ID_TOKEN_KEY ) : null ;
113+ final var session = portalRequest .getRawRequest ().getSession ( false );
114+ return session != null ? (String ) session .getAttribute ( idTokenSessionKey ) : null ;
117115 }
118116
119117 public void autoLoginFailed ()
120118 {
121- this .portalRequest .getRawRequest ().setAttribute ( AUTO_LOGIN_FAILED_ATTRIBUTE , Boolean .TRUE );
119+ this .portalRequest .getRawRequest ().setAttribute ( autoLoginAttr , Boolean .TRUE );
122120 }
123121
124122 public boolean isAutoLoginFailed ()
125123 {
126- return Boolean .TRUE .equals ( this .portalRequest .getRawRequest ().getAttribute ( AUTO_LOGIN_FAILED_ATTRIBUTE ) );
124+ return Boolean .TRUE .equals ( this .portalRequest .getRawRequest ().getAttribute ( autoLoginAttr ) );
127125 }
128126
129127 @ Override
130128 public void initialize ( final BeanContext context )
131129 {
130+ this .contextSessionKey = context .getApplicationKey () + ".context" ;
131+ this .idTokenSessionKey = context .getApplicationKey () + ".idtoken" ;
132+ this .autoLoginAttr = context .getApplicationKey () + ".autoLoginFailed" ;
132133 this .portalRequest = context .getBinding ( PortalRequest .class ).get ();
133134 }
134135}
0 commit comments