1111import org .apache .logging .log4j .Logger ;
1212import org .elasticsearch .common .logging .Loggers ;
1313import org .elasticsearch .license .License ;
14- import org .elasticsearch .license .XPackLicenseState ;
15- import org .elasticsearch .license .XPackLicenseState .Feature ;
14+ import org .elasticsearch .license .MockLicenseState ;
1615import org .elasticsearch .rest .RestRequest ;
1716import org .elasticsearch .test .ESTestCase ;
1817import org .elasticsearch .test .MockLogAppender ;
2221import org .elasticsearch .xpack .core .security .authc .AuthenticationToken ;
2322import org .elasticsearch .xpack .core .security .authz .AuthorizationEngine .AuthorizationInfo ;
2423import org .elasticsearch .xpack .core .security .user .User ;
24+ import org .elasticsearch .xpack .security .Security ;
2525import org .elasticsearch .xpack .security .transport .filter .IPFilter ;
2626import org .elasticsearch .xpack .security .transport .filter .SecurityIpFilterRule ;
2727import org .junit .Before ;
@@ -47,7 +47,7 @@ public class AuditTrailServiceTests extends ESTestCase {
4747 private AuthenticationToken token ;
4848 private TransportRequest request ;
4949 private RestRequest restRequest ;
50- private XPackLicenseState licenseState ;
50+ private MockLicenseState licenseState ;
5151 private boolean isAuditingAllowed ;
5252
5353 @ Before
@@ -57,10 +57,10 @@ public void init() throws Exception {
5757 auditTrailsBuilder .add (mock (AuditTrail .class ));
5858 }
5959 auditTrails = unmodifiableList (auditTrailsBuilder );
60- licenseState = mock (XPackLicenseState .class );
60+ licenseState = mock (MockLicenseState .class );
6161 service = new AuditTrailService (auditTrails , licenseState );
6262 isAuditingAllowed = randomBoolean ();
63- when (licenseState .checkFeature ( Feature . SECURITY_AUDITING )).thenReturn (isAuditingAllowed );
63+ when (licenseState .isAllowed ( Security . AUDITING_FEATURE )).thenReturn (isAuditingAllowed );
6464 token = mock (AuthenticationToken .class );
6565 request = mock (TransportRequest .class );
6666 restRequest = mock (RestRequest .class );
@@ -118,7 +118,7 @@ public void testNoLogRecentlyWhenLicenseProhibitsAuditing() throws Exception {
118118 public void testAuthenticationFailed () throws Exception {
119119 final String requestId = randomAlphaOfLengthBetween (6 , 12 );
120120 service .get ().authenticationFailed (requestId , token , "_action" , request );
121- verify (licenseState ).checkFeature ( Feature . SECURITY_AUDITING );
121+ verify (licenseState ).isAllowed ( Security . AUDITING_FEATURE );
122122 if (isAuditingAllowed ) {
123123 for (AuditTrail auditTrail : auditTrails ) {
124124 verify (auditTrail ).authenticationFailed (requestId , token , "_action" , request );
@@ -131,7 +131,7 @@ public void testAuthenticationFailed() throws Exception {
131131 public void testAuthenticationFailedNoToken () throws Exception {
132132 final String requestId = randomAlphaOfLengthBetween (6 , 12 );
133133 service .get ().authenticationFailed (requestId , "_action" , request );
134- verify (licenseState ).checkFeature ( Feature . SECURITY_AUDITING );
134+ verify (licenseState ).isAllowed ( Security . AUDITING_FEATURE );
135135 if (isAuditingAllowed ) {
136136 for (AuditTrail auditTrail : auditTrails ) {
137137 verify (auditTrail ).authenticationFailed (requestId , "_action" , request );
@@ -144,7 +144,7 @@ public void testAuthenticationFailedNoToken() throws Exception {
144144 public void testAuthenticationFailedRestNoToken () throws Exception {
145145 final String requestId = randomAlphaOfLengthBetween (6 , 12 );
146146 service .get ().authenticationFailed (requestId , restRequest );
147- verify (licenseState ).checkFeature ( Feature . SECURITY_AUDITING );
147+ verify (licenseState ).isAllowed ( Security . AUDITING_FEATURE );
148148 if (isAuditingAllowed ) {
149149 for (AuditTrail auditTrail : auditTrails ) {
150150 verify (auditTrail ).authenticationFailed (requestId , restRequest );
@@ -157,7 +157,7 @@ public void testAuthenticationFailedRestNoToken() throws Exception {
157157 public void testAuthenticationFailedRest () throws Exception {
158158 final String requestId = randomAlphaOfLengthBetween (6 , 12 );
159159 service .get ().authenticationFailed (requestId , token , restRequest );
160- verify (licenseState ).checkFeature ( Feature . SECURITY_AUDITING );
160+ verify (licenseState ).isAllowed ( Security . AUDITING_FEATURE );
161161 if (isAuditingAllowed ) {
162162 for (AuditTrail auditTrail : auditTrails ) {
163163 verify (auditTrail ).authenticationFailed (requestId , token , restRequest );
@@ -170,7 +170,7 @@ public void testAuthenticationFailedRest() throws Exception {
170170 public void testAuthenticationFailedRealm () throws Exception {
171171 final String requestId = randomAlphaOfLengthBetween (6 , 12 );
172172 service .get ().authenticationFailed (requestId , "_realm" , token , "_action" , request );
173- verify (licenseState ).checkFeature ( Feature . SECURITY_AUDITING );
173+ verify (licenseState ).isAllowed ( Security . AUDITING_FEATURE );
174174 if (isAuditingAllowed ) {
175175 for (AuditTrail auditTrail : auditTrails ) {
176176 verify (auditTrail ).authenticationFailed (requestId , "_realm" , token , "_action" , request );
@@ -183,7 +183,7 @@ public void testAuthenticationFailedRealm() throws Exception {
183183 public void testAuthenticationFailedRestRealm () throws Exception {
184184 final String requestId = randomAlphaOfLengthBetween (6 , 12 );
185185 service .get ().authenticationFailed (requestId , "_realm" , token , restRequest );
186- verify (licenseState ).checkFeature ( Feature . SECURITY_AUDITING );
186+ verify (licenseState ).isAllowed ( Security . AUDITING_FEATURE );
187187 if (isAuditingAllowed ) {
188188 for (AuditTrail auditTrail : auditTrails ) {
189189 verify (auditTrail ).authenticationFailed (requestId , "_realm" , token , restRequest );
@@ -196,7 +196,7 @@ public void testAuthenticationFailedRestRealm() throws Exception {
196196 public void testAnonymousAccess () throws Exception {
197197 final String requestId = randomAlphaOfLengthBetween (6 , 12 );
198198 service .get ().anonymousAccessDenied (requestId , "_action" , request );
199- verify (licenseState ).checkFeature ( Feature . SECURITY_AUDITING );
199+ verify (licenseState ).isAllowed ( Security . AUDITING_FEATURE );
200200 if (isAuditingAllowed ) {
201201 for (AuditTrail auditTrail : auditTrails ) {
202202 verify (auditTrail ).anonymousAccessDenied (requestId , "_action" , request );
@@ -213,7 +213,7 @@ public void testAccessGranted() throws Exception {
213213 () -> Collections .singletonMap (PRINCIPAL_ROLES_FIELD_NAME , new String [] { randomAlphaOfLengthBetween (1 , 6 ) });
214214 final String requestId = randomAlphaOfLengthBetween (6 , 12 );
215215 service .get ().accessGranted (requestId , authentication , "_action" , request , authzInfo );
216- verify (licenseState ).checkFeature ( Feature . SECURITY_AUDITING );
216+ verify (licenseState ).isAllowed ( Security . AUDITING_FEATURE );
217217 if (isAuditingAllowed ) {
218218 for (AuditTrail auditTrail : auditTrails ) {
219219 verify (auditTrail ).accessGranted (requestId , authentication , "_action" , request , authzInfo );
@@ -230,7 +230,7 @@ public void testAccessDenied() throws Exception {
230230 () -> Collections .singletonMap (PRINCIPAL_ROLES_FIELD_NAME , new String [] { randomAlphaOfLengthBetween (1 , 6 ) });
231231 final String requestId = randomAlphaOfLengthBetween (6 , 12 );
232232 service .get ().accessDenied (requestId , authentication , "_action" , request , authzInfo );
233- verify (licenseState ).checkFeature ( Feature . SECURITY_AUDITING );
233+ verify (licenseState ).isAllowed ( Security . AUDITING_FEATURE );
234234 if (isAuditingAllowed ) {
235235 for (AuditTrail auditTrail : auditTrails ) {
236236 verify (auditTrail ).accessDenied (requestId , authentication , "_action" , request , authzInfo );
@@ -244,7 +244,7 @@ public void testConnectionGranted() throws Exception {
244244 InetAddress inetAddress = InetAddress .getLoopbackAddress ();
245245 SecurityIpFilterRule rule = randomBoolean () ? SecurityIpFilterRule .ACCEPT_ALL : IPFilter .DEFAULT_PROFILE_ACCEPT_ALL ;
246246 service .get ().connectionGranted (inetAddress , "client" , rule );
247- verify (licenseState ).checkFeature ( Feature . SECURITY_AUDITING );
247+ verify (licenseState ).isAllowed ( Security . AUDITING_FEATURE );
248248 if (isAuditingAllowed ) {
249249 for (AuditTrail auditTrail : auditTrails ) {
250250 verify (auditTrail ).connectionGranted (inetAddress , "client" , rule );
@@ -258,7 +258,7 @@ public void testConnectionDenied() throws Exception {
258258 InetAddress inetAddress = InetAddress .getLoopbackAddress ();
259259 SecurityIpFilterRule rule = new SecurityIpFilterRule (false , "_all" );
260260 service .get ().connectionDenied (inetAddress , "client" , rule );
261- verify (licenseState ).checkFeature ( Feature . SECURITY_AUDITING );
261+ verify (licenseState ).isAllowed ( Security . AUDITING_FEATURE );
262262 if (isAuditingAllowed ) {
263263 for (AuditTrail auditTrail : auditTrails ) {
264264 verify (auditTrail ).connectionDenied (inetAddress , "client" , rule );
@@ -273,7 +273,7 @@ public void testAuthenticationSuccessRest() throws Exception {
273273 new RealmRef (null , null , null ));
274274 final String requestId = randomAlphaOfLengthBetween (6 , 12 );
275275 service .get ().authenticationSuccess (requestId , authentication , restRequest );
276- verify (licenseState ).checkFeature ( Feature . SECURITY_AUDITING );
276+ verify (licenseState ).isAllowed ( Security . AUDITING_FEATURE );
277277 if (isAuditingAllowed ) {
278278 for (AuditTrail auditTrail : auditTrails ) {
279279 verify (auditTrail ).authenticationSuccess (requestId , authentication , restRequest );
@@ -288,7 +288,7 @@ public void testAuthenticationSuccessTransport() throws Exception {
288288 new RealmRef (null , null , null ));
289289 final String requestId = randomAlphaOfLengthBetween (6 , 12 );
290290 service .get ().authenticationSuccess (requestId , authentication , "_action" , request );
291- verify (licenseState ).checkFeature ( Feature . SECURITY_AUDITING );
291+ verify (licenseState ).isAllowed ( Security . AUDITING_FEATURE );
292292 if (isAuditingAllowed ) {
293293 for (AuditTrail auditTrail : auditTrails ) {
294294 verify (auditTrail ).authenticationSuccess (requestId , authentication , "_action" , request );
0 commit comments