Skip to content

Commit 547e81c

Browse files
committed
merge master into branch
2 parents 0fd7c45 + 68316a7 commit 547e81c

File tree

6 files changed

+124
-4
lines changed

6 files changed

+124
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
66
- [ISSUE-144](https://github.com/SourceLabOrg/kafka-webview/issues/144) Make providing a TrustStore file when setting up a SSL enabled cluster optional. You might not want/need this option if your JVM is already configured to accept the SSL certificate served by the cluster, or if the cluster's certificate can be validated by a publically accessible CA.
77
- [PR-215](https://github.com/SourceLabOrg/kafka-webview/pull/215) Improve errors displayed when using the `test cluster` functionality.
88
- [PR-219](https://github.com/SourceLabOrg/kafka-webview/pull/219) Improve datatables for /cluster and /view to include paging, sorting, and filtering.
9+
- [PR-220](https://github.com/SourceLabOrg/kafka-webview/pull/220) Usernames/email addresses for locally defined users are no longer case-insensitive.
910

1011
## 2.5.1 (05/19/2020)
1112
- [ISSUE-209](https://github.com/SourceLabOrg/kafka-webview/issues/209) Expose HealthCheck and App Info endpoints without requiring authentication.

kafka-webview-ui/src/main/java/org/sourcelab/kafka/webview/ui/controller/configuration/user/UserController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public String update(
195195
model.addAttribute("isAdmin", isAdmin);
196196

197197
// Validate email doesn't already exist!
198-
final User existingUser = userRepository.findByEmail(userForm.getEmail());
198+
final User existingUser = userRepository.findByEmailIgnoreCase(userForm.getEmail());
199199
if ((userForm.exists() && existingUser != null && existingUser.getId() != userForm.getId())
200200
|| (!userForm.exists() && existingUser != null)) {
201201
bindingResult.addError(new FieldError(

kafka-webview-ui/src/main/java/org/sourcelab/kafka/webview/ui/controller/login/LoginController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public String lostPasswordFormSubmit(
113113
redirectAttributes.addFlashAttribute("FlashMessage", flashMessage);
114114

115115
// Retrieve User by Email
116-
final User user = userRepository.findByEmail(lostPasswordForm.getEmail());
116+
final User user = userRepository.findByEmailIgnoreCase(lostPasswordForm.getEmail());
117117
if (user != null) {
118118
// Do email reset request.
119119
//resetUserPasswordManager.requestPasswordReset(user);
@@ -158,7 +158,7 @@ public String resetPasswordFormSubmit(
158158
}
159159

160160
// Retrieve User by Email
161-
final User user = userRepository.findByEmail(resetPasswordForm.getEmail());
161+
final User user = userRepository.findByEmailIgnoreCase(resetPasswordForm.getEmail());
162162
boolean result = false;
163163
if (user != null) {
164164
// Attempt reset

kafka-webview-ui/src/main/java/org/sourcelab/kafka/webview/ui/manager/user/CustomUserDetailsService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public CustomUserDetailsService(final UserRepository userRepository) {
4444

4545
@Override
4646
public UserDetails loadUserByUsername(final String email) throws UsernameNotFoundException {
47-
final User user = userRepository.findByEmail(email);
47+
final User user = userRepository.findByEmailIgnoreCase(email);
4848
if (user == null) {
4949
throw new UsernameNotFoundException("User not found.");
5050
}

kafka-webview-ui/src/main/java/org/sourcelab/kafka/webview/ui/repository/UserRepository.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,18 @@ public interface UserRepository extends CrudRepository<User, Long> {
4343

4444
/**
4545
* Find user by email address.
46+
* NOTE: Case sensitive!
4647
* @param email Email to lookup user by
4748
* @return User or null if none found.
49+
* @deprecated probably want to use findByEmailIgnoreCase()
4850
*/
4951
User findByEmail(String email);
52+
53+
/**
54+
* Find user by email address.
55+
* NOTE: Case insensitive!
56+
* @param email Email to lookup user by
57+
* @return User or null if none found.
58+
*/
59+
User findByEmailIgnoreCase(String email);
5060
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2017, 2018, 2019 SourceLab.org (https://github.com/SourceLabOrg/kafka-webview/)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package org.sourcelab.kafka.webview.ui.manager.user;
26+
27+
import org.junit.Test;
28+
import org.junit.runner.RunWith;
29+
import org.sourcelab.kafka.webview.ui.model.User;
30+
import org.sourcelab.kafka.webview.ui.tools.UserTestTools;
31+
import org.springframework.beans.factory.annotation.Autowired;
32+
import org.springframework.boot.test.context.SpringBootTest;
33+
import org.springframework.security.core.userdetails.UserDetails;
34+
import org.springframework.security.core.userdetails.UsernameNotFoundException;
35+
import org.springframework.test.context.junit4.SpringRunner;
36+
37+
import static org.junit.Assert.assertEquals;
38+
import static org.junit.Assert.assertNotNull;
39+
import static org.junit.Assert.assertTrue;
40+
41+
@SpringBootTest
42+
@RunWith(SpringRunner.class)
43+
public class CustomUserDetailsServiceTest {
44+
45+
@Autowired
46+
private UserTestTools userTestTools;
47+
48+
/**
49+
* Instance under test.
50+
*/
51+
@Autowired
52+
private CustomUserDetailsService customUserDetailsService;
53+
54+
/**
55+
* Verify what happens if you attempt to load a user which does not exist.
56+
*/
57+
@Test(expected = UsernameNotFoundException.class)
58+
public void smokeTest_invalidUser() {
59+
final String email = "Does-not-exist@example.com";
60+
customUserDetailsService.loadUserByUsername(email);
61+
}
62+
63+
/**
64+
* Test loading using the same case.
65+
*/
66+
@Test
67+
public void smokeTest_loadValidUser_sameCase() {
68+
// Setup user.
69+
final String userEmail = "test" + System.currentTimeMillis() + "@example.com";
70+
final User user = userTestTools.createUser();
71+
user.setEmail(userEmail);
72+
userTestTools.save(user);
73+
74+
// Attempt to load
75+
final UserDetails userDetails = customUserDetailsService.loadUserByUsername(userEmail);
76+
77+
// Verify
78+
assertNotNull("Result should be non-null", userDetails);
79+
assertTrue("Should be a CustomUserDetails instance", userDetails instanceof CustomUserDetails);
80+
assertEquals("Should have correct email", userEmail, userDetails.getUsername());
81+
assertEquals("Should have correct id", user.getId(), ((CustomUserDetails) userDetails).getUserId());
82+
assertNotNull("Should have a user model", ((CustomUserDetails) userDetails).getUserModel());
83+
}
84+
85+
/**
86+
* Test loading using insensitive case.
87+
*/
88+
@Test
89+
public void smokeTest_loadValidUser_differentCasing() {
90+
// Setup user.
91+
final String userEmail = "test" + System.currentTimeMillis() + "@example.com";
92+
final User user = userTestTools.createUser();
93+
user.setEmail(userEmail);
94+
userTestTools.save(user);
95+
96+
// Setup lookup email to have a different case.
97+
final String lookupEmail = userEmail.toUpperCase();
98+
99+
// Attempt to load using different case.
100+
final UserDetails userDetails = customUserDetailsService.loadUserByUsername(lookupEmail);
101+
102+
// Verify
103+
assertNotNull("Result should be non-null", userDetails);
104+
assertTrue("Should be a CustomUserDetails instance", userDetails instanceof CustomUserDetails);
105+
assertEquals("Should have correct email", userEmail, userDetails.getUsername());
106+
assertEquals("Should have correct id", user.getId(), ((CustomUserDetails) userDetails).getUserId());
107+
assertNotNull("Should have a user model", ((CustomUserDetails) userDetails).getUserModel());
108+
}
109+
}

0 commit comments

Comments
 (0)