Skip to content

Commit

Permalink
Merge pull request #3048 from GDLMadushanka/basicAuth
Browse files Browse the repository at this point in the history
Add changes to allow colon in password
  • Loading branch information
GDLMadushanka authored Dec 8, 2023
2 parents 40b20ef + 381564f commit 8414f44
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,6 @@ public class Constants {

// Searching constants
public static final String SEARCH_KEY = "searchKey";
public static final Character BASIC_AUTH_SEPARATOR_CHAR = ':';

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import static org.wso2.micro.integrator.management.apis.Constants.ROLE;
import static org.wso2.micro.integrator.management.apis.Constants.SEARCH_KEY;
import static org.wso2.micro.integrator.management.apis.Constants.STATUS;
import static org.wso2.micro.integrator.management.apis.Constants.BASIC_AUTH_SEPARATOR_CHAR;
/**
* Resource for a retrieving and adding users.
* <p>
Expand Down Expand Up @@ -187,13 +188,17 @@ private JSONObject handlePost(MessageContext messageContext,
JsonObject payload = Utils.getJsonPayload(axis2MessageContext);
boolean isAdmin = false;
if (payload.has(USER_ID) && payload.has(PASSWORD)) {
String user = payload.get(USER_ID).getAsString();
// validate username
if (user == null || user.isEmpty() || user.indexOf(BASIC_AUTH_SEPARATOR_CHAR) != -1) {
throw new IOException("Invalid username");
}
String[] roleList = null;
if (payload.has(IS_ADMIN) && payload.get(IS_ADMIN).getAsBoolean()) {
String adminRole = Utils.getRealmConfiguration().getAdminRoleName();
roleList = new String[]{adminRole};
isAdmin = payload.get(IS_ADMIN).getAsBoolean();
}
String user = payload.get(USER_ID).getAsString();
String domain = null;
if (payload.has(DOMAIN) ) {
domain = payload.get(DOMAIN).getAsString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ boolean processAuthRequestWithFileBasedUserStore(MessageContext messageContext,
private String[] extractDetails(String token) {

String decodedCredentials = new String(new Base64().decode(token.getBytes()));
String[] usernamePasswordArray = decodedCredentials.split(":");
if (usernamePasswordArray.length != 2) {
// everything before the first colon can be considered as the username
// since RFC-2617 specifies that username cannot contain a colon.
String[] usernamePasswordArray = decodedCredentials.split(":",2);
if (usernamePasswordArray.length < 2) {
return new String[] {};
}
return new String[] { usernamePasswordArray[0], usernamePasswordArray[1] };
Expand Down

0 comments on commit 8414f44

Please sign in to comment.