11/*
2- * Copyright 2004-2020 the original author or authors.
2+ * Copyright 2004-2024 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1515 */
1616package org .springframework .webflow .security ;
1717
18- import java .lang .reflect .Constructor ;
1918import java .util .ArrayList ;
2019import java .util .Collection ;
2120import java .util .List ;
2221
23- import org .springframework .beans .DirectFieldAccessor ;
2422import org .springframework .security .access .AccessDecisionManager ;
2523import org .springframework .security .access .AccessDecisionVoter ;
2624import org .springframework .security .access .ConfigAttribute ;
3129import org .springframework .security .access .vote .UnanimousBased ;
3230import org .springframework .security .core .Authentication ;
3331import org .springframework .security .core .context .SecurityContextHolder ;
34- import org .springframework .util .ClassUtils ;
3532import org .springframework .webflow .definition .FlowDefinition ;
3633import org .springframework .webflow .definition .StateDefinition ;
3734import org .springframework .webflow .definition .TransitionDefinition ;
4643 */
4744public class SecurityFlowExecutionListener implements FlowExecutionListener {
4845
49- private static final boolean SPRING_SECURITY_3_PRESENT = ClassUtils .hasConstructor (AffirmativeBased .class );
50-
5146 private AccessDecisionManager accessDecisionManager ;
5247
5348 /**
@@ -100,9 +95,7 @@ protected void decide(SecurityRule rule, Object object) {
10095 if (accessDecisionManager != null ) {
10196 accessDecisionManager .decide (authentication , object , configAttributes );
10297 } else {
103- AccessDecisionManager manager = (SPRING_SECURITY_3_PRESENT ?
104- createManagerWithSpringSecurity3 (rule ) : createManager (rule ));
105- manager .decide (authentication , object , configAttributes );
98+ createManager (rule ).decide (authentication , object , configAttributes );
10699 }
107100 }
108101
@@ -118,28 +111,6 @@ private AbstractAccessDecisionManager createManager(SecurityRule rule) {
118111 }
119112 }
120113
121- private AbstractAccessDecisionManager createManagerWithSpringSecurity3 (SecurityRule rule ) {
122- List <AccessDecisionVoter > voters = new ArrayList <>();
123- voters .add (new RoleVoter ());
124- Class <?> managerType ;
125- if (rule .getComparisonType () == SecurityRule .COMPARISON_ANY ) {
126- managerType = AffirmativeBased .class ;
127- } else if (rule .getComparisonType () == SecurityRule .COMPARISON_ALL ) {
128- managerType = UnanimousBased .class ;
129- } else {
130- throw new IllegalStateException ("Unknown SecurityRule match type: " + rule .getComparisonType ());
131- }
132- try {
133- Constructor <?> constructor = managerType .getConstructor ();
134- AbstractAccessDecisionManager manager = (AbstractAccessDecisionManager ) constructor .newInstance ();
135- new DirectFieldAccessor (manager ).setPropertyValue ("decisionVoters" , voters );
136- return manager ;
137- }
138- catch (Throwable ex ) {
139- throw new IllegalStateException ("Failed to initialize AccessDecisionManager" , ex );
140- }
141- }
142-
143114 /**
144115 * Convert SecurityRule into a form understood by Spring Security
145116 * @param rule the rule to convert
0 commit comments