Skip to content
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

Improve debug logs and usage of class variables #3092

Open
wants to merge 1 commit into
base: 4.7.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -426,26 +426,8 @@ public String[] doListUsers(String filter, int maxItemLimit) throws UserStoreExc
return new String[0];
}

int givenMax = UserCoreConstants.MAX_USER_ROLE_LIST;

int searchTime = UserCoreConstants.MAX_SEARCH_TIME;

try {
givenMax = Integer.parseInt(realmConfig
.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_MAX_USER_LIST));
} catch (Exception e) {
givenMax = UserCoreConstants.MAX_USER_ROLE_LIST;
}

try {
searchTime = Integer.parseInt(realmConfig
.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_MAX_SEARCH_TIME));
} catch (Exception e) {
searchTime = UserCoreConstants.MAX_SEARCH_TIME;
}

if (maxItemLimit < 0 || maxItemLimit > givenMax) {
maxItemLimit = givenMax;
if (maxItemLimit < 0 || maxItemLimit > maximumUserNameListLength) {
maxItemLimit = maximumUserNameListLength;
}

String displayNameAttribute = realmConfig.getUserStoreProperty(JDBCUserStoreConstants.DISPLAY_NAME_ATTRIBUTE);
Expand Down Expand Up @@ -491,7 +473,7 @@ public String[] doListUsers(String filter, int maxItemLimit) throws UserStoreExc
}
prepStmt.setMaxRows(maxItemLimit);
try {
prepStmt.setQueryTimeout(searchTime);
prepStmt.setQueryTimeout(queryTimeout);
} catch (Exception e) {
// this can be ignored since timeout method is not implemented
log.debug(e);
Expand Down Expand Up @@ -694,29 +676,20 @@ private void setPSRestrictions(PreparedStatement ps, int maxItemLimit) throws SQ

int givenMax = UserCoreConstants.MAX_USER_ROLE_LIST;

int searchTime = UserCoreConstants.MAX_SEARCH_TIME;

try {
givenMax =
Integer.parseInt(realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_MAX_ROLE_LIST));
} catch (Exception e) {
givenMax = UserCoreConstants.MAX_USER_ROLE_LIST;
}

try {
searchTime =
Integer.parseInt(realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_MAX_SEARCH_TIME));
} catch (Exception e) {
searchTime = UserCoreConstants.MAX_SEARCH_TIME;
}

if (maxItemLimit < 0 || maxItemLimit > givenMax) {
maxItemLimit = givenMax;
}

ps.setMaxRows(maxItemLimit);
try {
ps.setQueryTimeout(searchTime);
ps.setQueryTimeout(queryTimeout);
} catch (Exception e) {
// this can be ignored since timeout method is not implemented
log.debug(e);
Expand Down Expand Up @@ -3107,27 +3080,13 @@ public String[] getUserListFromProperties(String property, String value, String
prepStmt.setInt(5, tenantId);
}

int givenMax;
int searchTime;
int maxItemLimit = MAX_ITEM_LIMIT_UNLIMITED;
try {
givenMax = Integer.parseInt(realmConfig
.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_MAX_USER_LIST));
} catch (Exception e) {
givenMax = UserCoreConstants.MAX_USER_ROLE_LIST;
}
try {
searchTime = Integer.parseInt(realmConfig
.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_MAX_SEARCH_TIME));
} catch (Exception e) {
searchTime = UserCoreConstants.MAX_SEARCH_TIME;
}
if (maxItemLimit < 0 || maxItemLimit > givenMax) {
maxItemLimit = givenMax;
if (maxItemLimit < 0 || maxItemLimit > maximumUserNameListLength) {
maxItemLimit = maximumUserNameListLength;
}
prepStmt.setMaxRows(maxItemLimit);
try {
prepStmt.setQueryTimeout(searchTime);
prepStmt.setQueryTimeout(queryTimeout);
} catch (Exception e) {
// this can be ignored since timeout method is not implemented
log.debug(e);
Expand Down Expand Up @@ -3714,31 +3673,15 @@ protected PaginatedSearchResult doListUsers(String filter, int limit, int offset
String sqlStmt;
PreparedStatement prepStmt = null;
ResultSet rs = null;
int givenMax;
int searchTime;

PaginatedSearchResult result = new PaginatedSearchResult();

if (limit == 0) {
return result;
}

try {
givenMax = Integer.parseInt(realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig
.PROPERTY_MAX_USER_LIST));
} catch (Exception e) {
givenMax = UserCoreConstants.MAX_USER_ROLE_LIST;
}

try {
searchTime = Integer.parseInt(realmConfig
.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_MAX_SEARCH_TIME));
} catch (Exception e) {
searchTime = UserCoreConstants.MAX_SEARCH_TIME;
}

if (limit < 0 || limit > givenMax) {
limit = givenMax;
if (limit < 0 || limit > maximumUserNameListLength) {
limit = maximumUserNameListLength;
}

try {
Expand Down Expand Up @@ -3804,7 +3747,7 @@ protected PaginatedSearchResult doListUsers(String filter, int limit, int offset
}

try {
prepStmt.setQueryTimeout(searchTime);
prepStmt.setQueryTimeout(queryTimeout);
} catch (Exception e) {
// this can be ignored since timeout method is not implemented
log.debug(e);
Expand Down Expand Up @@ -4720,35 +4663,49 @@ private String getExternalRoleListSqlStatement(String caseSensitiveUsernameQuery
private int getMaxUserNameListLength() {

int maxUserList;
try {
maxUserList = Integer.parseInt(realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig
.PROPERTY_MAX_USER_LIST));
} catch (Exception e) {
// The user store property might not be configured. Therefore logging as debug.
if (StringUtils.isEmpty(realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig
.PROPERTY_MAX_USER_LIST))) {
if (log.isDebugEnabled()) {
log.debug("Unable to get the " + UserCoreConstants.RealmConfig.PROPERTY_MAX_USER_LIST +
log.debug(UserCoreConstants.RealmConfig.PROPERTY_MAX_USER_LIST + " is not defined in the realm " +
"configuration. The default value: " + UserCoreConstants.MAX_USER_ROLE_LIST + " is used " +
"instead.");
}
maxUserList = UserCoreConstants.MAX_USER_ROLE_LIST;
} else {
try {
maxUserList = Integer.parseInt(realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig
.PROPERTY_MAX_USER_LIST));
} catch (NumberFormatException e) {
log.warn("Unable to get the " + UserCoreConstants.RealmConfig.PROPERTY_MAX_USER_LIST +
" from the realm configuration. The default value: " + UserCoreConstants.MAX_USER_ROLE_LIST +
" is used instead.", e);
maxUserList = UserCoreConstants.MAX_USER_ROLE_LIST;
}
maxUserList = UserCoreConstants.MAX_USER_ROLE_LIST;
}
return maxUserList;
}

private int getSQLQueryTimeoutLimit() {

int searchTime;
try {
searchTime = Integer.parseInt(realmConfig
.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_MAX_SEARCH_TIME));
} catch (Exception e) {
// The user store property might not be configured. Therefore logging as debug.
if (StringUtils.isEmpty(realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig
.PROPERTY_MAX_SEARCH_TIME))) {
if (log.isDebugEnabled()) {
log.debug("Unable to get the " + UserCoreConstants.RealmConfig.PROPERTY_MAX_SEARCH_TIME +
log.debug(UserCoreConstants.RealmConfig.PROPERTY_MAX_SEARCH_TIME + " is not defined in the realm " +
"configuration. The default value: " + UserCoreConstants.MAX_SEARCH_TIME + " is used " +
"instead.");
}
searchTime = UserCoreConstants.MAX_SEARCH_TIME;
} else {
try {
searchTime = Integer.parseInt(realmConfig
.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_MAX_SEARCH_TIME));
} catch (NumberFormatException e) {
log.warn("Unable to get the " + UserCoreConstants.RealmConfig.PROPERTY_MAX_SEARCH_TIME +
" from the realm configuration. The default value: " + UserCoreConstants.MAX_SEARCH_TIME +
" is used instead.", e);
searchTime = UserCoreConstants.MAX_SEARCH_TIME;
}
searchTime = UserCoreConstants.MAX_SEARCH_TIME;
}
return searchTime;
}
Expand Down