3737/// java-identity-provider/idp-conf-impl/src/main/resources/net/shibboleth/idp/flows/saml/saml-abstract-flow.xml.
3838public final class FabricationWebflowListener extends AbstractInitializableComponent implements FlowExecutionListener {
3939
40+ private static final String ANDRVOTR_FABRICATION_TOKEN_OK = "andrvotr_fabrication_token_ok" ;
41+
4042 private final @ Nonnull Logger log = LoggerFactory .getLogger (FabricationWebflowListener .class );
4143
4244 private Config config ;
@@ -71,7 +73,7 @@ public void requestSubmitted(RequestContext context) {
7173 (HttpServletRequest ) context .getExternalContext ().getNativeRequest ();
7274
7375 // If the request does not have the Andrvotr-Internal-Fabrication-Token header, do nothing.
74- String token = request .getHeader ("Andrvotr-Internal-Fabrication-Token" );
76+ String token = request .getHeader (Constants . HEADER_ANDRVOTR_INTERNAL_FABRICATION_TOKEN );
7577 if (token == null ) {
7678 log .debug ("no Andrvotr-Internal-Fabrication-Token - ignoring request" );
7779 return ;
@@ -82,7 +84,7 @@ public void requestSubmitted(RequestContext context) {
8284 // info in Andrvotr-Internal-Fabrication-Trace. But just in case.)
8385 try {
8486 String content = dataSealer .unwrap (token );
85- if (!"andrvotr-fabrication-token" .equals (content )) {
87+ if (!Constants . ANDRVOTR_FABRICATION_TOKEN_VALUE .equals (content )) {
8688 throw new Exception ("wrong unwrapped value" );
8789 }
8890 } catch (Exception e ) {
@@ -93,8 +95,8 @@ public void requestSubmitted(RequestContext context) {
9395 }
9496
9597 log .info ("started {} as a nested request inside andrvotr/fabricate" , request .getRequestURI ());
96- context .getRequestScope ().put ("andrvotr_fabrication_token_ok" , new Object ());
97- addTrace (context , "@Start" );
98+ context .getRequestScope ().put (ANDRVOTR_FABRICATION_TOKEN_OK , new Object ());
99+ addTrace (context , Constants . TRACE_START );
98100 }
99101
100102 @ Override
@@ -103,15 +105,16 @@ public void eventSignaled(RequestContext context, Event event) {
103105 (HttpServletRequest ) context .getExternalContext ().getNativeRequest ();
104106
105107 // If the request does not have the Andrvotr-Internal-Fabrication-Token header, do nothing.
106- if (!context .getRequestScope ().contains ("andrvotr_fabrication_token_ok" )) return ;
108+ if (!context .getRequestScope ().contains (ANDRVOTR_FABRICATION_TOKEN_OK )) return ;
107109
108110 // If we're leaving the "DecodeMessage" state with the "proceed" event (not an error), check whether our
109111 // configuration allows connections from the front entity ID (sent by HttpController in a header) to the back
110112 // entity ID (found in the decoded SAML message).
111- if ("DecodeMessage" .equals (context .getCurrentState ().getId ()) && "proceed" .equals (event .getId ())) {
112- addTrace (context , "@AllowedConnectionCheck" );
113+ if (Constants .STATE_DECODE_MESSAGE .equals (context .getCurrentState ().getId ())
114+ && Constants .EVENT_PROCEED .equals (event .getId ())) {
115+ addTrace (context , Constants .TRACE_ALLOWED_CONNECTION_CHECK );
113116
114- String frontID = request .getHeader ("Andrvotr-Internal-Fabrication-Front" );
117+ String frontID = request .getHeader (Constants . HEADER_ANDRVOTR_INTERNAL_FABRICATION_FRONT );
115118
116119 // RelyingPartyContext is created by the "InitializeRelyingPartyContextFromSAMLPeer" action which runs
117120 // during the "DecodeMessage" state.
@@ -123,23 +126,23 @@ public void eventSignaled(RequestContext context, Event event) {
123126 || Strings .isNullOrEmpty (backID )
124127 || !config .isAllowedConnection (frontID , backID )) {
125128 log .error ("forbidden andrvotr connection: front={} back={}" , frontID , backID );
126- addTrace (context , "@AllowedConnectionCheckFail" );
129+ addTrace (context , Constants . TRACE_ALLOWED_CONNECTION_CHECK_FAILURE );
127130 throw new RuntimeException ("Andrvotr fabricate failed - this connection is not allowed" );
128131 }
129132
130133 log .info ("allowed andrvotr connection: front={} back={}" , frontID , backID );
131- addTrace (context , "@AllowedConnectionCheckSuccess" );
134+ addTrace (context , Constants . TRACE_ALLOWED_CONNECTION_CHECK_SUCCESS );
132135 }
133136 }
134137
135138 @ Override
136139 public void stateEntered (RequestContext context , StateDefinition previousState , StateDefinition state ) {
137140 // If the request does not have the Andrvotr-Internal-Fabrication-Token header, do nothing.
138- if (!context .getRequestScope ().contains ("andrvotr_fabrication_token_ok" )) return ;
141+ if (!context .getRequestScope ().contains (ANDRVOTR_FABRICATION_TOKEN_OK )) return ;
139142
140143 // When moving from "HandleOutboundMessage" to "end", it is expected that the response is already sent, and we
141144 // can't add response headers anymore. Avoid the warning in addTrace.
142- if ("end" .equals (state .getId ())) return ;
145+ if (Constants . STATE_END .equals (state .getId ())) return ;
143146
144147 // Save all entered states in a response header for troubleshooting.
145148 addTrace (context , state .getId ());
@@ -151,7 +154,7 @@ private void addTrace(RequestContext context, String value) {
151154
152155 if (!response .isCommitted ()) {
153156 log .debug ("adding Andrvotr-Internal-Fabrication-Trace: {}" , value );
154- response .addHeader ("Andrvotr-Internal-Fabrication-Trace" , value );
157+ response .addHeader (Constants . HEADER_ANDRVOTR_INTERNAL_FABRICATION_TRACE , value );
155158 } else {
156159 log .warn ("response already committed, cannot add trace '{}'" , value );
157160 }
0 commit comments