-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Removing control characters from OAuth2 realm and logs #3136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
130 changes: 130 additions & 0 deletions
130
...h2/src/test/java/org/apache/cxf/rs/security/oauth2/services/AbstractTokenServiceTest.java
This file contains hidden or 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,130 @@ | ||
| /** | ||
| * 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 org.apache.cxf.rs.security.oauth2.services; | ||
|
|
||
| import jakarta.ws.rs.core.MultivaluedMap; | ||
| import org.apache.cxf.jaxrs.impl.MetadataMap; | ||
| import org.apache.cxf.rs.security.oauth2.common.Client; | ||
| import org.apache.cxf.rs.security.oauth2.common.OAuthError; | ||
| import org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException; | ||
| import org.apache.cxf.rs.security.oauth2.utils.OAuthConstants; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.assertSame; | ||
| import static org.junit.Assert.assertThrows; | ||
|
|
||
| public class AbstractTokenServiceTest { | ||
|
|
||
| @Test | ||
| public void testGetClientReportsInvalidClientWhenClientNotFound() { | ||
| TestTokenService service = new TestTokenService(); | ||
|
|
||
| InvalidClientException ex = assertThrows(InvalidClientException.class, | ||
| () -> service.callGetClient("missing-client", "secret", new MetadataMap<>())); | ||
|
|
||
| assertNotNull(ex.getError()); | ||
| assertEquals(OAuthConstants.INVALID_CLIENT, ex.getError().getError()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testInvalidClientInvalidCharactersHandled() { | ||
| TestTokenService service = new TestTokenService(); | ||
|
|
||
| String clientId = "alice\r\n\r\n\r\n[FAKE]+Admin+login+successful"; | ||
| InvalidClientException ex = assertThrows(InvalidClientException.class, | ||
| () -> service.callGetClient(clientId, "secret", new MetadataMap<>())); | ||
|
|
||
| assertNotNull(ex.getError()); | ||
| assertEquals(OAuthConstants.INVALID_CLIENT, ex.getError().getError()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetClientReportsCustomErrorWhenProviderThrowsIt() { | ||
| TestTokenService service = new TestTokenService(); | ||
| OAuthError customError = new OAuthError(OAuthConstants.UNAUTHORIZED_CLIENT); | ||
| service.setException(new OAuthServiceException(customError)); | ||
|
|
||
| InvalidClientException ex = assertThrows(InvalidClientException.class, | ||
| () -> service.callGetClient("client", "secret", new MetadataMap<>())); | ||
|
|
||
| assertSame(customError, ex.getError()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetClientReturnsClientWhenFound() { | ||
| TestTokenService service = new TestTokenService(); | ||
| Client expected = new Client("client", "secret", true); | ||
| service.setClient(expected); | ||
|
|
||
| Client actual = service.callGetClient("client", "secret", new MetadataMap<>()); | ||
| assertSame(expected, actual); | ||
| } | ||
|
|
||
| private static final class TestTokenService extends AbstractTokenService { | ||
| private Client client; | ||
| private OAuthServiceException exception; | ||
|
|
||
| Client callGetClient(String clientId, String clientSecret, MultivaluedMap<String, String> params) { | ||
| return getClient(clientId, clientSecret, params); | ||
| } | ||
|
|
||
| void setClient(Client client) { | ||
| this.client = client; | ||
| } | ||
|
|
||
| void setException(OAuthServiceException exception) { | ||
| this.exception = exception; | ||
| } | ||
|
|
||
| @Override | ||
| protected Client getValidClient(String clientId, String clientSecret, MultivaluedMap<String, String> params) | ||
| throws OAuthServiceException { | ||
| if (exception != null) { | ||
| throw exception; | ||
| } | ||
| return client; | ||
| } | ||
|
|
||
| @Override | ||
| protected void reportInvalidClient() { | ||
| throw new InvalidClientException(new OAuthError(OAuthConstants.INVALID_CLIENT)); | ||
| } | ||
|
|
||
| @Override | ||
| protected void reportInvalidClient(OAuthError error) { | ||
| throw new InvalidClientException(error); | ||
| } | ||
| } | ||
|
|
||
| private static class InvalidClientException extends RuntimeException { | ||
| private static final long serialVersionUID = 1L; | ||
| private final OAuthError error; | ||
|
|
||
| InvalidClientException(OAuthError error) { | ||
| this.error = error; | ||
| } | ||
|
|
||
| OAuthError getError() { | ||
| return error; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
74 changes: 74 additions & 0 deletions
74
rt/rs/security/oauth-parent/oauth2/src/test/resources/logging.properties
This file contains hidden or 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,74 @@ | ||
| # | ||
| # | ||
| # 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. | ||
| # | ||
| # | ||
| ############################################################ | ||
| # Default Logging Configuration File | ||
| # | ||
| # You can use a different file by specifying a filename | ||
| # with the java.util.logging.config.file system property. | ||
| # For example java -Djava.util.logging.config.file=myfile | ||
| ############################################################ | ||
|
|
||
| ############################################################ | ||
| # Global properties | ||
| ############################################################ | ||
|
|
||
| # "handlers" specifies a comma separated list of log Handler | ||
| # classes. These handlers will be installed during VM startup. | ||
| # Note that these classes must be on the system classpath. | ||
| # By default we only configure a ConsoleHandler, which will only | ||
| # show messages at the INFO and above levels. | ||
| #handlers= java.util.logging.ConsoleHandler | ||
|
|
||
| # To also add the FileHandler, use the following line instead. | ||
| #handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler | ||
|
|
||
| # Default global logging level. | ||
| # This specifies which kinds of events are logged across | ||
| # all loggers. For any given facility this global level | ||
| # can be overriden by a facility specific level | ||
| # Note that the ConsoleHandler also has a separate level | ||
| # setting to limit messages printed to the console. | ||
| .level= INFO | ||
|
|
||
| ############################################################ | ||
| # Handler specific properties. | ||
| # Describes specific configuration info for Handlers. | ||
| ############################################################ | ||
|
|
||
| # default file output is in user's home directory. | ||
| java.util.logging.FileHandler.pattern = %h/java%u.log | ||
| java.util.logging.FileHandler.limit = 50000 | ||
| java.util.logging.FileHandler.count = 1 | ||
| java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter | ||
|
|
||
| # Limit the message that are printed on the console to INFO and above. | ||
| java.util.logging.ConsoleHandler.level = INFO | ||
| java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter | ||
|
|
||
|
|
||
| ############################################################ | ||
| # Facility specific properties. | ||
| # Provides extra control for each logger. | ||
| ############################################################ | ||
|
|
||
| # For example, set the com.xyz.foo logger to only log SEVERE | ||
| # messages: | ||
| #com.xyz.foo.level = SEVERE |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.