-
Notifications
You must be signed in to change notification settings - Fork 810
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #496 from apache/fix/double_evaluations_2_5
Fixes double evaluations
- Loading branch information
Showing
52 changed files
with
1,686 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...main/java/com/opensymphony/xwork2/security/DefaultNotExcludedAcceptedPatternsChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.opensymphony.xwork2.security; | ||
|
||
import com.opensymphony.xwork2.inject.Inject; | ||
|
||
import java.util.Set; | ||
import java.util.regex.Pattern; | ||
|
||
public class DefaultNotExcludedAcceptedPatternsChecker implements NotExcludedAcceptedPatternsChecker { | ||
private ExcludedPatternsChecker excludedPatterns; | ||
private AcceptedPatternsChecker acceptedPatterns; | ||
|
||
|
||
@Inject | ||
public void setExcludedPatterns(ExcludedPatternsChecker excludedPatterns) { | ||
this.excludedPatterns = excludedPatterns; | ||
} | ||
|
||
@Inject | ||
public void setAcceptedPatterns(AcceptedPatternsChecker acceptedPatterns) { | ||
this.acceptedPatterns = acceptedPatterns; | ||
} | ||
|
||
@Override | ||
public IsAllowed isAllowed(String value) { | ||
IsExcluded isExcluded = isExcluded(value); | ||
if (isExcluded.isExcluded()) { | ||
return IsAllowed.no(isExcluded.getExcludedPattern()); | ||
} | ||
|
||
IsAccepted isAccepted = isAccepted(value); | ||
if (!isAccepted.isAccepted()) { | ||
return IsAllowed.no(isAccepted.getAcceptedPattern()); | ||
} | ||
|
||
return IsAllowed.yes(isAccepted.getAcceptedPattern()); | ||
} | ||
|
||
@Override | ||
public IsAccepted isAccepted(String value) { | ||
return acceptedPatterns.isAccepted(value); | ||
} | ||
|
||
@Override | ||
public void setAcceptedPatterns(String commaDelimitedPatterns) { | ||
acceptedPatterns.setAcceptedPatterns(commaDelimitedPatterns); | ||
} | ||
|
||
@Override | ||
public void setAcceptedPatterns(String[] patterns) { | ||
acceptedPatterns.setAcceptedPatterns(patterns); | ||
} | ||
|
||
@Override | ||
public void setAcceptedPatterns(Set<String> patterns) { | ||
acceptedPatterns.setAcceptedPatterns(patterns); | ||
} | ||
|
||
@Override | ||
public Set<Pattern> getAcceptedPatterns() { | ||
return acceptedPatterns.getAcceptedPatterns(); | ||
} | ||
|
||
@Override | ||
public IsExcluded isExcluded(String value) { | ||
return excludedPatterns.isExcluded(value); | ||
} | ||
|
||
@Override | ||
public void setExcludedPatterns(String commaDelimitedPatterns) { | ||
excludedPatterns.setExcludedPatterns(commaDelimitedPatterns); | ||
} | ||
|
||
@Override | ||
public void setExcludedPatterns(String[] patterns) { | ||
excludedPatterns.setExcludedPatterns(patterns); | ||
} | ||
|
||
@Override | ||
public void setExcludedPatterns(Set<String> patterns) { | ||
excludedPatterns.setExcludedPatterns(patterns); | ||
} | ||
|
||
@Override | ||
public Set<Pattern> getExcludedPatterns() { | ||
return excludedPatterns.getExcludedPatterns(); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
core/src/main/java/com/opensymphony/xwork2/security/NotExcludedAcceptedPatternsChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.opensymphony.xwork2.security; | ||
|
||
/** | ||
* Used across different places to check if given string is not excluded and is accepted | ||
* @see <a href="https://securitylab.github.com/research/apache-struts-double-evaluation/">here</a> | ||
* @since 2.5.27 | ||
*/ | ||
public interface NotExcludedAcceptedPatternsChecker extends ExcludedPatternsChecker, AcceptedPatternsChecker { | ||
|
||
/** | ||
* Checks if value doesn't match excluded pattern and matches accepted pattern | ||
* | ||
* @param value to check | ||
* @return object containing result of matched pattern and pattern itself | ||
*/ | ||
IsAllowed isAllowed(String value); | ||
|
||
final class IsAllowed { | ||
|
||
private final boolean allowed; | ||
private final String allowedPattern; | ||
|
||
public static IsAllowed yes(String allowedPattern) { | ||
return new IsAllowed(true, allowedPattern); | ||
} | ||
|
||
public static IsAllowed no(String allowedPattern) { | ||
return new IsAllowed(false, allowedPattern); | ||
} | ||
|
||
private IsAllowed(boolean allowed, String allowedPattern) { | ||
this.allowed = allowed; | ||
this.allowedPattern = allowedPattern; | ||
} | ||
|
||
public boolean isAllowed() { | ||
return allowed; | ||
} | ||
|
||
public String getAllowedPattern() { | ||
return allowedPattern; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "IsAllowed { " + | ||
"allowed=" + allowed + | ||
", allowedPattern=" + allowedPattern + | ||
" }"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.