-
Notifications
You must be signed in to change notification settings - Fork 657
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
Add environment variable support for user-mgt configuration #2343
base: 4.5.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,4 +126,32 @@ public static String getCarbonHome() { | |
} | ||
return carbonHome; | ||
} | ||
|
||
public static String replaceSystemProperty(String text) { | ||
int indexOfStartingChars = -1; | ||
int indexOfClosingBrace; | ||
|
||
// The following condition deals with properties. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Multiline comments should be used if the comment spans over a single line. |
||
// Properties are specified as ${system.property}, | ||
// and are assumed to be System properties | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Each sentence must conclude with an apostrophe. |
||
while (indexOfStartingChars < text.indexOf("${") | ||
&& (indexOfStartingChars = text.indexOf("${")) != -1 | ||
&& (indexOfClosingBrace = text.indexOf('}')) != -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we validate the pattern of "${system.property}" using a regex? |
||
String sysProp = text.substring(indexOfStartingChars + 2, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can also be handled using a regex pattern which will improve the readability. |
||
indexOfClosingBrace); | ||
String propValue = System.getProperty(sysProp); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 142-146 can be simplified using Optionals. |
||
if (propValue == null) { | ||
propValue = System.getenv(sysProp); | ||
} | ||
if (propValue != null) { | ||
text = text.substring(0, indexOfStartingChars) + propValue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a StringBuilder to avoid multiple concatenations. |
||
+ text.substring(indexOfClosingBrace + 1); | ||
} | ||
if (sysProp.equals("carbon.home") && propValue != null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a constant for "carbon.home" |
||
&& propValue.equals(".")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use StringUtils.equals to avoid the explicit null check of "propValue". |
||
text = new File(".").getAbsolutePath() + File.separator + text; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a StringBuilder to avoid multiple concatenations. |
||
} | ||
} | ||
return text; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
import org.osgi.framework.BundleContext; | ||
import org.wso2.carbon.CarbonConstants; | ||
import org.wso2.carbon.CarbonException; | ||
import org.wso2.carbon.base.CarbonBaseUtils; | ||
import org.wso2.carbon.user.api.RealmConfiguration; | ||
import org.wso2.carbon.user.core.UserCoreConstants; | ||
import org.wso2.carbon.user.core.UserStoreException; | ||
|
@@ -181,6 +182,9 @@ private static void addPropertyElements(OMFactory factory, OMElement parent, Str | |
Map.Entry<String, String> entry = ite.next(); | ||
String name = entry.getKey(); | ||
String value = entry.getValue(); | ||
if (value != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Abstract the null check inside the replaceSystemProperty() method. |
||
value = CarbonBaseUtils.replaceSystemProperty(value); | ||
} | ||
OMElement propElem = factory.createOMElement(new QName( | ||
UserCoreConstants.RealmConfig.LOCAL_NAME_PROPERTY)); | ||
OMAttribute propAttr = factory.createOMAttribute( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a java doc comment.