Skip to content

Commit 4a0e5bb

Browse files
committed
RANGER-5061: checkstyle compliance updates - security-admin org.apache.ranger.common
1 parent 6099baa commit 4a0e5bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1602
-1604
lines changed

dev-support/checkstyle-suppressions.xml

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@
2525
<suppress files="AuditFileCacheProviderSpool.java" checks="TypeName"/>
2626
<suppress files="AuthzAuditEvent.java" checks="StaticVariableName"/>
2727
<suppress files="buildks.java" checks="TypeName"/>
28+
<suppress files="BaseDao.java" checks="StaticVariableName"/>
29+
<suppress files="ContextUtil.java" checks="HideUtilityClassConstructor"/>
30+
<suppress files="MapUtil.java" checks="HideUtilityClassConstructor"/>
31+
<suppress files="RangerAdminTagEnricher.java" checks="StaticVariableName"/>
32+
<suppress files="RangerCommonEnums.java" checks="HideUtilityClassConstructor"/>
33+
<suppress files="RangerConstants.java" checks="TypeName"/>
2834
<suppress files="RangerRolesUtil.java" checks="TypeName"/>
35+
<suppress files="SearchField.java" checks="TypeName"/>
36+
<suppress files="SortField.java" checks="TypeName"/>
2937
<suppress files="SPOOL_FILE_STATUS.java" checks="TypeName"/>
38+
<suppress files="TimedEventUtil.java" checks="HideUtilityClassConstructor"/>
3039
</suppressions>

security-admin/src/main/java/org/apache/ranger/common/AppConstants.java

+16-18
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.apache.ranger.common;
2121

2222
public class AppConstants extends RangerCommonEnums {
23-
2423
/***************************************************************
2524
* Enum values for AssetType
2625
**************************************************************/
@@ -663,7 +662,7 @@ public class AppConstants extends RangerCommonEnums {
663662

664663
public static final String Masked_String = "*****";
665664

666-
static public String getLabelFor_AssetType(int elementValue) {
665+
public static String getLabelFor_AssetType(int elementValue) {
667666
if (elementValue == 0) {
668667
return "Unknown"; //ASSET_UNKNOWN
669668
}
@@ -688,7 +687,7 @@ static public String getLabelFor_AssetType(int elementValue) {
688687
return null;
689688
}
690689

691-
static public String getLabelFor_PolicyType(int elementValue) {
690+
public static String getLabelFor_PolicyType(int elementValue) {
692691
if (elementValue == 0) {
693692
return "Inclusion"; //POLICY_INCLUSION
694693
}
@@ -698,7 +697,7 @@ static public String getLabelFor_PolicyType(int elementValue) {
698697
return null;
699698
}
700699

701-
static public String getLabelFor_XAAuditType(int elementValue) {
700+
public static String getLabelFor_XAAuditType(int elementValue) {
702701
if (elementValue == 0) {
703702
return "Unknown"; //XA_AUDIT_TYPE_UNKNOWN
704703
}
@@ -723,7 +722,7 @@ static public String getLabelFor_XAAuditType(int elementValue) {
723722
return null;
724723
}
725724

726-
static public String getLabelFor_ResourceType(int elementValue) {
725+
public static String getLabelFor_ResourceType(int elementValue) {
727726
if (elementValue == 0) {
728727
return "Unknown"; //RESOURCE_UNKNOWN
729728
}
@@ -760,7 +759,7 @@ static public String getLabelFor_ResourceType(int elementValue) {
760759
return null;
761760
}
762761

763-
static public String getLabelFor_XAGroupType(int elementValue) {
762+
public static String getLabelFor_XAGroupType(int elementValue) {
764763
if (elementValue == 0) {
765764
return "Unknown"; //XA_GROUP_UNKNOWN
766765
}
@@ -776,7 +775,7 @@ static public String getLabelFor_XAGroupType(int elementValue) {
776775
return null;
777776
}
778777

779-
static public String getLabelFor_XAPermForType(int elementValue) {
778+
public static String getLabelFor_XAPermForType(int elementValue) {
780779
if (elementValue == 0) {
781780
return "Unknown"; //XA_PERM_FOR_UNKNOWN
782781
}
@@ -789,7 +788,7 @@ static public String getLabelFor_XAPermForType(int elementValue) {
789788
return null;
790789
}
791790

792-
static public String getLabelFor_XAPermType(int elementValue) {
791+
public static String getLabelFor_XAPermType(int elementValue) {
793792
if (elementValue == 0) {
794793
return "Unknown"; //XA_PERM_TYPE_UNKNOWN
795794
}
@@ -931,7 +930,7 @@ static public String getLabelFor_XAPermType(int elementValue) {
931930
return null;
932931
}
933932

934-
static public String getLabelFor_ClassTypes(int elementValue) {
933+
public static String getLabelFor_ClassTypes(int elementValue) {
935934
if (elementValue == 1000) {
936935
return "Asset"; //CLASS_TYPE_XA_ASSET
937936
}
@@ -1068,7 +1067,7 @@ static public String getLabelFor_ClassTypes(int elementValue) {
10681067
return null;
10691068
}
10701069

1071-
static public int getEnumFor_AssetType(String label) {
1070+
public static int getEnumFor_AssetType(String label) {
10721071
if (label == null) {
10731072
return 0;
10741073
}
@@ -1093,15 +1092,15 @@ static public int getEnumFor_AssetType(String label) {
10931092
return 0;
10941093
}
10951094

1096-
static public int getEnumFor_BooleanValue(boolean label) {
1095+
public static int getEnumFor_BooleanValue(boolean label) {
10971096
if (label) {
10981097
return AppConstants.BOOL_TRUE;
10991098
} else {
11001099
return AppConstants.BOOL_FALSE;
11011100
}
11021101
}
11031102

1104-
static public boolean getBooleanFor_BooleanValue(int elementValue) {
1103+
public static boolean getBooleanFor_BooleanValue(int elementValue) {
11051104
if (elementValue == 1) {
11061105
return true;
11071106
}
@@ -1111,7 +1110,7 @@ static public boolean getBooleanFor_BooleanValue(int elementValue) {
11111110
return false;
11121111
}
11131112

1114-
static public int getEnumFor_ResourceType(String label) {
1113+
public static int getEnumFor_ResourceType(String label) {
11151114
if (label == null) {
11161115
return 0;
11171116
}
@@ -1151,7 +1150,7 @@ static public int getEnumFor_ResourceType(String label) {
11511150
return 0;
11521151
}
11531152

1154-
static public int getEnumFor_XAPermType(String label) {
1153+
public static int getEnumFor_XAPermType(String label) {
11551154
if (label == null) {
11561155
return 0;
11571156
}
@@ -1275,7 +1274,7 @@ static public int getEnumFor_XAPermType(String label) {
12751274
return 0;
12761275
}
12771276

1278-
static public int getEnumFor_PolicyType(String label) {
1277+
public static int getEnumFor_PolicyType(String label) {
12791278
if (label == null) {
12801279
return 0;
12811280
}
@@ -1288,7 +1287,7 @@ static public int getEnumFor_PolicyType(String label) {
12881287
return 0;
12891288
}
12901289

1291-
static public int getEnumFor_DatabaseFlavor(String label) {
1290+
public static int getEnumFor_DatabaseFlavor(String label) {
12921291
if (label == null) {
12931292
return DB_FLAVOR_UNKNOWN; // DB_FLAVOR_UNKNOWN
12941293
}
@@ -1310,7 +1309,7 @@ static public int getEnumFor_DatabaseFlavor(String label) {
13101309
return DB_FLAVOR_UNKNOWN;
13111310
}
13121311

1313-
static public String getLabelFor_DatabaseFlavor(int elementValue) {
1312+
public static String getLabelFor_DatabaseFlavor(int elementValue) {
13141313
if (elementValue == DB_FLAVOR_UNKNOWN) {
13151314
return "UNKNOWN"; // Unknown
13161315
}
@@ -1332,4 +1331,3 @@ static public String getLabelFor_DatabaseFlavor(int elementValue) {
13321331
return null;
13331332
}
13341333
}
1335-

security-admin/src/main/java/org/apache/ranger/common/ContextUtil.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.apache.ranger.security.context.RangerSecurityContext;
2525

2626
public class ContextUtil {
27-
2827
/**
2928
* Singleton class
3029
*/
@@ -33,61 +32,76 @@ public ContextUtil() {
3332

3433
public static Long getCurrentUserId() {
3534
RangerSecurityContext context = RangerContextHolder.getSecurityContext();
35+
3636
if (context != null) {
3737
UserSessionBase userSession = context.getUserSession();
38+
3839
if (userSession != null) {
3940
return userSession.getUserId();
4041
}
4142
}
43+
4244
return null;
4345
}
4446

4547
public static String getCurrentUserPublicName() {
4648
RangerSecurityContext context = RangerContextHolder.getSecurityContext();
49+
4750
if (context != null) {
4851
UserSessionBase userSession = context.getUserSession();
52+
4953
if (userSession != null) {
5054
return userSession.getXXPortalUser().getPublicScreenName();
5155
// return userSession.getGjUser().getPublicScreenName();
5256
}
5357
}
58+
5459
return null;
5560
}
5661

5762
public static UserSessionBase getCurrentUserSession() {
5863
UserSessionBase userSession = null;
5964
RangerSecurityContext context = RangerContextHolder.getSecurityContext();
65+
6066
if (context != null) {
6167
userSession = context.getUserSession();
6268
}
69+
6370
return userSession;
6471
}
6572

6673
public static RequestContext getCurrentRequestContext() {
6774
RangerSecurityContext context = RangerContextHolder.getSecurityContext();
75+
6876
if (context != null) {
6977
return context.getRequestContext();
7078
}
79+
7180
return null;
7281
}
7382

7483
public static String getCurrentUserLoginId() {
7584
RangerSecurityContext context = RangerContextHolder.getSecurityContext();
85+
7686
if (context != null) {
7787
UserSessionBase userSession = context.getUserSession();
88+
7889
if (userSession != null) {
7990
return userSession.getLoginId();
8091
}
8192
}
93+
8294
return null;
8395
}
8496

8597
public static boolean isBulkModeContext() {
8698
RangerAdminOpContext context = RangerContextHolder.getOpContext();
8799
boolean bulkMode = false;
100+
88101
if (context != null) {
89102
bulkMode = context.isBulkModeContext();
90103
}
104+
91105
return bulkMode;
92106
}
93107
}

security-admin/src/main/java/org/apache/ranger/common/DateUtil.java

+23-9
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333

3434
@Component
3535
public class DateUtil {
36-
3736
private static final TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT+0");
3837

3938
public static String dateToString(Date date, String dateFromat) {
4039
SimpleDateFormat formatter = new SimpleDateFormat(dateFromat);
40+
4141
return formatter.format(date);
4242
}
4343

@@ -46,8 +46,10 @@ public static Date getUTCDate() {
4646
Calendar local = Calendar.getInstance();
4747
int offset = local.getTimeZone().getOffset(local.getTimeInMillis());
4848
GregorianCalendar utc = new GregorianCalendar(gmtTimeZone);
49+
4950
utc.setTimeInMillis(local.getTimeInMillis());
5051
utc.add(Calendar.MILLISECOND, -offset);
52+
5153
return utc.getTime();
5254
} catch (Exception ex) {
5355
return null;
@@ -58,12 +60,15 @@ public static Date getUTCDate(long epoh) {
5860
if (epoh == 0) {
5961
return null;
6062
}
63+
6164
try {
6265
Calendar local = Calendar.getInstance();
6366
int offset = local.getTimeZone().getOffset(epoh);
6467
GregorianCalendar utc = new GregorianCalendar(gmtTimeZone);
68+
6569
utc.setTimeInMillis(epoh);
6670
utc.add(Calendar.MILLISECOND, -offset);
71+
6772
return utc.getTime();
6873
} catch (Exception ex) {
6974
return null;
@@ -74,22 +79,26 @@ public static Date getLocalDateForUTCDate(Date date) {
7479
Calendar local = Calendar.getInstance();
7580
int offset = local.getTimeZone().getOffset(local.getTimeInMillis());
7681
GregorianCalendar utc = new GregorianCalendar();
82+
7783
utc.setTimeInMillis(date.getTime());
7884
utc.add(Calendar.MILLISECOND, offset);
85+
7986
return utc.getTime();
8087
}
8188

8289
public static Date stringToDate(String dateString, String dateFromat) {
83-
SimpleDateFormat simpleDateFormat = null;
84-
Date date = null;
90+
Date date = null;
91+
8592
if (!StringUtils.isEmpty(dateString) && !StringUtils.isEmpty(dateFromat)) {
8693
try {
87-
simpleDateFormat = new SimpleDateFormat(dateFromat);
88-
date = simpleDateFormat.parse(dateString);
94+
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFromat);
95+
96+
date = simpleDateFormat.parse(dateString);
8997
} catch (Exception ex) {
9098
return null;
9199
}
92100
}
101+
93102
return date;
94103
}
95104

@@ -99,19 +108,23 @@ public Date getDateFromNow(int days) {
99108

100109
public Date getDateFromNow(int days, int hours, int minutes) {
101110
Calendar cal = Calendar.getInstance();
111+
102112
cal.add(Calendar.DATE, days);
103113
cal.add(Calendar.HOUR, hours);
104114
cal.add(Calendar.MINUTE, minutes);
115+
105116
return cal.getTime();
106117
}
107118

108119
public Date getDateFromGivenDate(Date date, int days, int hours, int minutes, int second) {
109120
Calendar cal = Calendar.getInstance();
121+
110122
cal.setTime(date);
111123
cal.add(Calendar.DATE, days);
112124
cal.add(Calendar.HOUR, hours);
113125
cal.add(Calendar.MINUTE, minutes);
114126
cal.add(Calendar.SECOND, second);
127+
115128
return cal.getTime();
116129
}
117130

@@ -124,10 +137,11 @@ public Date getDateFromGivenDate(Date date, int days, int hours, int minutes, in
124137
*/
125138
public Date addTimeOffset(Date date, int mins) {
126139
if (date == null) {
127-
return date;
140+
return null;
128141
}
129-
long t = date.getTime();
130-
Date newDate = new Date(t + (mins * 60000L));
131-
return newDate;
142+
143+
long t = date.getTime();
144+
145+
return new Date(t + (mins * 60000L));
132146
}
133147
}

0 commit comments

Comments
 (0)