Skip to content

Commit dd352ac

Browse files
author
Anders Breid
authored
Update /auth endpoint to /authentication (#375)
- Update raml to have /authentication and not /auth - Update AthControllerImpl.java to AuthenticationControllerImpl.java - Update tests - Update documentation
1 parent c88c201 commit dd352ac

File tree

14 files changed

+115
-125
lines changed

14 files changed

+115
-125
lines changed

src/functionaltests/resources/features/authentication.feature

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,31 @@ Feature: Test Authentication
2323
@RESTWithSessionCookie
2424
Scenario: Call an REST API with session credentials
2525
Given LDAP is activated
26-
When a GET request is prepared for REST API "/auth/login"
26+
When a GET request is prepared for REST API "/authentication/login"
2727
And request is sent
2828
Then response code 401 is received
29-
When a GET request is prepared for REST API "/auth/login"
29+
When a GET request is prepared for REST API "/authentication/login"
3030
And username "gauss" and password "password" is used as credentials
3131
And request is sent
3232
Then response code 200 is received
33-
When a GET request is prepared for REST API "/auth/login"
33+
When a GET request is prepared for REST API "/authentication/login"
3434
And request is sent
3535
Then response code 200 is received
3636

3737
@RESTWithTokenId
3838
Scenario: Call an REST API with session credentials
3939
Given LDAP is activated
40-
When a GET request is prepared for REST API "/auth/logout"
40+
When a GET request is prepared for REST API "/authentication/logout"
4141
And request is sent
42-
When a GET request is prepared for REST API "/auth/login"
42+
When a GET request is prepared for REST API "/authentication/login"
4343
And request is sent
4444
Then response code 401 is received
45-
When a GET request is prepared for REST API "/auth/login"
45+
When a GET request is prepared for REST API "/authentication/login"
4646
And username "gauss" and password "password" is used as credentials
4747
And request is sent
4848
Then response code 200 is received
4949
And authentication token is saved
50-
When a GET request is prepared for REST API "/auth/login"
50+
When a GET request is prepared for REST API "/authentication/login"
5151
And client is replaced
5252
And authentication token is attached
5353
And request is sent

src/functionaltests/resources/features/authenticationMultiLDAP.feature

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@ Feature: Test Authentication with multiple LDAP servers
66
@RESTWithUniqueUsersInDifferentLDAPServers
77
Scenario: Login using unique users from two different LDAP servers
88
Given LDAP is activated
9-
When a GET request is prepared for REST API "/auth/login"
9+
When a GET request is prepared for REST API "/authentication/login"
1010
And username "gauss" and password "password" is used as credentials
1111
And request is sent
1212
Then response code 200 is received
13-
When a GET request is prepared for REST API "/auth/logout"
13+
When a GET request is prepared for REST API "/authentication/logout"
1414
And request is sent
15-
When a GET request is prepared for REST API "/auth/login"
15+
When a GET request is prepared for REST API "/authentication/login"
1616
And username "einstein" and password "e=mc2" is used as credentials
1717
And request is sent
1818
Then response code 200 is received
1919

2020
@RESTWithIdenticalUsernamesInDifferentLDAPServers
2121
Scenario: Login using identical usernames with different passwords from two different LDAP servers
2222
Given LDAP is activated
23-
When a GET request is prepared for REST API "/auth/login"
23+
When a GET request is prepared for REST API "/authentication/login"
2424
And username "newton" and password "password" is used as credentials
2525
And request is sent
2626
Then response code 200 is received
27-
When a GET request is prepared for REST API "/auth/logout"
27+
When a GET request is prepared for REST API "/authentication/logout"
2828
And request is sent
29-
When a GET request is prepared for REST API "/auth/login"
29+
When a GET request is prepared for REST API "/authentication/login"
3030
And username "newton" and password "password2" is used as credentials
3131
And request is sent
3232
Then response code 200 is received

src/functionaltests/resources/features/restEndpoints.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Feature: Test Rest Endpoints
1414
Examples:
1515
| responsecode | endpoint |
1616
| 200 | /information |
17-
| 200 | /auth |
18-
| 200 | /auth/login |
17+
| 200 | /authentication |
18+
| 200 | /authentication/login |
1919
| 200 | /status |
2020
| 200 | /templates |
2121
| 200 | /templates/events |

src/main/java/com/ericsson/ei/controller/AuthController.java renamed to src/main/java/com/ericsson/ei/controller/AuthenticationController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@
1616
*/
1717
@RestController
1818
@Validated
19-
@RequestMapping(value = "/auth", produces = "application/json")
20-
public interface AuthController {
19+
@RequestMapping(value = "/authentication", produces = "application/json")
20+
public interface AuthenticationController {
2121

2222

2323
/**
2424
* This method checks if security is enabled.
2525
*
2626
*/
2727
@RequestMapping(value = "", method = RequestMethod.GET)
28-
public ResponseEntity<?> getAuth(HttpServletRequest httpRequest);
28+
public ResponseEntity<?> getAuthentication(HttpServletRequest httpRequest);
2929

3030
/**
3131
* This method returns a logged in user.
3232
*
3333
*/
3434
@RequestMapping(value = "/login", method = RequestMethod.GET)
35-
public ResponseEntity<?> getAuthLogin(HttpServletRequest httpRequest);
35+
public ResponseEntity<?> getAuthenticationLogin(HttpServletRequest httpRequest);
3636

3737
}

src/main/java/com/ericsson/ei/controller/AuthControllerImpl.java renamed to src/main/java/com/ericsson/ei/controller/AuthenticationControllerImpl.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2018 Ericsson AB.
2+
authentication Copyright 2018 Ericsson AB.
33
For a full list of individual contributors, please see the commit history.
44
55
Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,23 +34,23 @@
3434
import io.swagger.annotations.ApiOperation;
3535

3636
/**
37-
* Endpoint /auth/login should be secured if LDAP is enabled.
38-
* Endpoint /auth should never be secured.
37+
* Endpoint /authentication/login should be secured if LDAP is enabled.
38+
* Endpoint /authentication should never be secured.
3939
*/
4040
@Component
4141
@CrossOrigin
4242
@Api(value = "Auth", tags = { "Authentication" })
43-
public class AuthControllerImpl implements AuthController {
43+
public class AuthenticationControllerImpl implements AuthenticationController {
4444

45-
private static final Logger LOGGER = LoggerFactory.getLogger(AuthControllerImpl.class);
45+
private static final Logger LOGGER = LoggerFactory.getLogger(AuthenticationControllerImpl.class);
4646

4747
@Value("${ldap.enabled:false}")
4848
private boolean ldapEnabled;
4949

5050
@Override
5151
@CrossOrigin
5252
@ApiOperation(value = "To check if security is enabled", response = String.class)
53-
public ResponseEntity<?> getAuth(final HttpServletRequest httpRequest) {
53+
public ResponseEntity<?> getAuthentication(final HttpServletRequest httpRequest) {
5454
try {
5555
return new ResponseEntity<>(new JSONObject().put("security", ldapEnabled).toString(),
5656
HttpStatus.OK);
@@ -65,7 +65,7 @@ public ResponseEntity<?> getAuth(final HttpServletRequest httpRequest) {
6565
@Override
6666
@CrossOrigin
6767
@ApiOperation(value = "To get login of current user", response = String.class)
68-
public ResponseEntity<?> getAuthLogin(final HttpServletRequest httpRequest) {
68+
public ResponseEntity<?> getAuthenticationLogin(final HttpServletRequest httpRequest) {
6969
try {
7070
String currentUser = SecurityContextHolder.getContext().getAuthentication().getName();
7171
return new ResponseEntity<>(new JSONObject().put("user", currentUser).toString(),

src/main/java/com/ericsson/ei/handlers/StatusHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
public class StatusHandler {
3636

3737
private static final String INITIAL_DELAY_OF_FIRST_STATUS_UPDATE = "1000";
38-
private static final String INTERVAL_TO_RUN_STATUS_UPDATES = "30000";
38+
private static final String INTERVAL_TO_RUN_STATUS_UPDATES = "5000";
3939

4040
private StatusData statusData = new StatusData();
4141
private ObjectMapper objectMapper = new ObjectMapper();

src/main/resources/public/raml/eiffel-intelligence.raml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ baseUri: /
4040
/templates: !include resourceTypes/templates.raml
4141
/failed-notifications: !include resourceTypes/failed-notifications.raml
4242
/rules: !include resourceTypes/rules.raml
43-
/auth: !include resourceTypes/auth.raml
43+
/authentication: !include resourceTypes/authentication.raml
4444
/status: !include resourceTypes/status.raml
4545
/information: !include resourceTypes/instance_info.raml
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.ericsson.ei.controller;
2+
3+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
4+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
5+
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
8+
import org.springframework.http.MediaType;
9+
import org.springframework.test.web.servlet.MockMvc;
10+
import org.springframework.test.web.servlet.MvcResult;
11+
import org.springframework.test.web.servlet.RequestBuilder;
12+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
13+
14+
@AutoConfigureMockMvc
15+
public class ControllerTestBaseClass {
16+
17+
@Autowired
18+
private MockMvc mockMvc;
19+
20+
protected void assertOkResponseStatus(String endpoint) throws Throwable {
21+
mockMvc.perform(MockMvcRequestBuilders.get(endpoint)
22+
.accept(MediaType.APPLICATION_JSON_VALUE))
23+
.andExpect(status().isOk())
24+
.andReturn();
25+
}
26+
27+
protected void assertExpectedResponse(String endpoint, String responseBody) throws Throwable {
28+
mockMvc.perform(MockMvcRequestBuilders.get(endpoint)
29+
.accept(MediaType.APPLICATION_JSON_VALUE))
30+
.andExpect(status().isOk())
31+
.andExpect(content().string(responseBody))
32+
.andReturn();
33+
}
34+
35+
protected MvcResult performMockMvcRequest(String endpoint, String body) throws Throwable {
36+
RequestBuilder requestBuilder = MockMvcRequestBuilders.post(endpoint)
37+
.accept(MediaType.ALL)
38+
.content(body)
39+
.contentType(
40+
MediaType.APPLICATION_JSON);
41+
42+
return mockMvc.perform(requestBuilder).andReturn();
43+
}
44+
45+
}

src/test/java/com/ericsson/ei/controller/TestAuthControllerImpl.java renamed to src/test/java/com/ericsson/ei/controller/TestAuthenticationControllerImpl.java

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,14 @@
1616
*/
1717
package com.ericsson.ei.controller;
1818

19-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
20-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
21-
2219
import org.json.JSONObject;
2320
import org.junit.Test;
2421
import org.junit.runner.RunWith;
25-
import org.springframework.beans.factory.annotation.Autowired;
26-
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
2722
import org.springframework.boot.test.context.SpringBootContextLoader;
2823
import org.springframework.boot.test.context.SpringBootTest;
29-
import org.springframework.http.MediaType;
3024
import org.springframework.test.context.ContextConfiguration;
3125
import org.springframework.test.context.TestPropertySource;
3226
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
33-
import org.springframework.test.web.servlet.MockMvc;
34-
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
3527

3628
import com.ericsson.ei.App;
3729
import com.ericsson.ei.utils.TestContextInitializer;
@@ -41,30 +33,21 @@
4133
"failed.notification.database-name: TestAuthControllerImpl-failedNotifications",
4234
"rabbitmq.exchange.name: TestAuthControllerImpl-exchange",
4335
"rabbitmq.consumerName: TestAuthControllerImpl" })
44-
@ContextConfiguration(
45-
classes = App.class,
46-
loader = SpringBootContextLoader.class,
47-
initializers = TestContextInitializer.class)
36+
@ContextConfiguration(classes = App.class, loader = SpringBootContextLoader.class, initializers = TestContextInitializer.class)
4837
@RunWith(SpringJUnit4ClassRunner.class)
4938
@SpringBootTest(classes = { App.class })
50-
@AutoConfigureMockMvc
51-
public class TestAuthControllerImpl {
52-
53-
@Autowired
54-
private MockMvc mockMvc;
39+
public class TestAuthenticationControllerImpl extends ControllerTestBaseClass {
5540

5641
@Test
57-
public void testGetAuth() throws Exception {
42+
public void testGetAuthentication() throws Throwable {
5843
String responseBody = new JSONObject().put("security", false).toString();
59-
mockMvc.perform(MockMvcRequestBuilders.get("/auth").accept(MediaType.APPLICATION_JSON_VALUE))
60-
.andExpect(status().isOk()).andExpect(content().string(responseBody)).andReturn();
44+
assertExpectedResponse("/authentication", responseBody);
6145
}
6246

6347
@Test
64-
public void testGetLogin() throws Exception {
48+
public void testGetLogin() throws Throwable {
6549
String responseBody = new JSONObject().put("user", "anonymousUser").toString();
66-
mockMvc.perform(MockMvcRequestBuilders.get("/auth/login").accept(MediaType.APPLICATION_JSON_VALUE))
67-
.andExpect(status().isOk()).andExpect(content().string(responseBody)).andReturn();
50+
assertExpectedResponse("/authentication/login", responseBody);
6851
}
6952

7053
}

0 commit comments

Comments
 (0)