-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Remove default password * admin role check fix * remove tmp admin
- Loading branch information
Showing
17 changed files
with
228 additions
and
27 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
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
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
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
68 changes: 68 additions & 0 deletions
68
...-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/utils/PasswordGeneratorUtil.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,68 @@ | ||
/* | ||
* Copyright 1999-2024 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed 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.alibaba.nacos.plugin.auth.impl.utils; | ||
|
||
import java.security.SecureRandom; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* RandomPasswordGenerator . | ||
* | ||
* @author : huangtianhui | ||
*/ | ||
public class PasswordGeneratorUtil { | ||
|
||
private static final String LOWER_CASE = "abcdefghijklmnopqrstuvwxyz"; | ||
|
||
private static final String UPPER_CASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
|
||
private static final String DIGITS = "0123456789"; | ||
|
||
private static final String SPECIAL_CHARS = "!@#$%&"; | ||
|
||
private static final int PASSWORD_LENGTH = 8; | ||
|
||
/** | ||
* generateRandomPassword. | ||
* @return | ||
*/ | ||
public static String generateRandomPassword() { | ||
SecureRandom random = new SecureRandom(); | ||
|
||
List<Character> pwdChars = new ArrayList<>(); | ||
|
||
pwdChars.add(LOWER_CASE.charAt(random.nextInt(LOWER_CASE.length()))); | ||
pwdChars.add(UPPER_CASE.charAt(random.nextInt(UPPER_CASE.length()))); | ||
pwdChars.add(DIGITS.charAt(random.nextInt(DIGITS.length()))); | ||
pwdChars.add(SPECIAL_CHARS.charAt(random.nextInt(SPECIAL_CHARS.length()))); | ||
|
||
// Fill the rest of the password with random characters from all categories | ||
String allCharacters = LOWER_CASE + UPPER_CASE + DIGITS + SPECIAL_CHARS; | ||
while (pwdChars.size() < PASSWORD_LENGTH) { | ||
pwdChars.add(allCharacters.charAt(random.nextInt(allCharacters.length()))); | ||
} | ||
|
||
// Shuffle to avoid predictable order | ||
Collections.shuffle(pwdChars, random); | ||
|
||
// Build the final password string | ||
return pwdChars.stream().map(String::valueOf).collect(Collectors.joining()); | ||
} | ||
} |
Oops, something went wrong.