diff --git a/services/save-and-restore/doc/index.rst b/services/save-and-restore/doc/index.rst index cb8f2b0578..1685b031f3 100644 --- a/services/save-and-restore/doc/index.rst +++ b/services/save-and-restore/doc/index.rst @@ -839,6 +839,8 @@ The response is a snapshot object representing the persisted data, see :ref:`Get Server Restore Endpoints ------------------------ +**NOTE:** the restore endpoints require an authenticated user to have role ``sar-server-restore``. + Restore from snapshot items """"""""""""""""""""""""""" @@ -1042,10 +1044,10 @@ service can be configured to delegate authentication to Active Directory or remo purposes hard coded credentials are found in the ``WebSecurityConfig`` class. See the file ``application.properties`` for information on how to select authentication method. -Two roles are defined, "sar-user" and "sar-admin". The actual name of these roles can be customizable in ``application.properties``, +Three roles are defined, "sar-user", "sar-admin" and "sar-server-restore". The actual name of these roles can be customizable in ``application.properties``, and must match role/group names in LDAP or Active Directory. -Authorization uses a role-based approach like so: +The role-based authorization works like so: * Unauthenticated users may read data, i.e. access GET endpoints. * Save-and-restore role "sar-user": @@ -1060,7 +1062,8 @@ Authorization uses a role-based approach like so: * Object is configuration or folder node with no child nodes * Object is a filter * Object is a tag -* Save-and-restore role "sar-admin": no restrictions +* Save-and-restore role "sar-admin": no restrictions, except for server-side restore +* Role "sar-server-restore" is used only to control access to endpoints related to restore operations. Authentication endpoint ----------------------- @@ -1077,11 +1080,30 @@ Body: {"username":"johndoe", "password":"undisclosed"} +Handles client authentication. Upon successful authentication it returns an object like so: + +.. code-block:: JSON + + { + "userName": "johndoe", + "roles" : ["role1", "role2"] + } + + +**.../server-restore-authorized** + + Method: POST + +Returns ``true`` if an authenticated client may request the service to perform a restore operation, otherwise +``false``. Note though that calling this endpoint from an unauthenticated client will return a HTTP 401 response. + + Enabled authentication, disabled authorization ---------------------------------------------- -The application property ``authorization.permitall`` (default ``true``) can be used to bypass all authorization. In +The application property ``authorization.permitall`` (default ``true``) can be used to bypass all authorization, except +for endpoints related to snapshot restore on the service. In this case authentication is still required for protected endpoints, but user need not be associated with a save-and-restore role/group. diff --git a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/persistence/config/IndexConfig.java b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/persistence/config/IndexConfig.java new file mode 100644 index 0000000000..341d04cb4b --- /dev/null +++ b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/persistence/config/IndexConfig.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2026 European Spallation Source ERIC. + */ + +package org.phoebus.service.saveandrestore.persistence.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +/** + * Component to centralize values related to Elasticsearch index names. + */ +@Component +public class IndexConfig { + + @SuppressWarnings("unused") + @Value("${elasticsearch.tree_node.index:saveandrestore_tree}") + public String ES_TREE_INDEX; + + @SuppressWarnings("unused") + @Value("${elasticsearch.configuration_node.index:saveandrestore_configuration}") + public String ES_CONFIGURATION_INDEX; + + @SuppressWarnings("unused") + @Value("${elasticsearch.snapshot_node.index:saveandrestore_snapshot}") + public String ES_SNAPSHOT_INDEX; + + @SuppressWarnings("unused") + @Value("${elasticsearch.composite_snapshot_node.index:saveandrestore_composite_snapshot}") + public String ES_COMPOSITE_SNAPSHOT_INDEX; + + @SuppressWarnings("unused") + @Value("${elasticsearch.filter.index:saveandrestore_filter}") + public String ES_FILTER_INDEX; +} diff --git a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/config/InMemorySecurityConfig.java b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/config/InMemorySecurityConfig.java index c85b378bfd..40d582df35 100644 --- a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/config/InMemorySecurityConfig.java +++ b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/config/InMemorySecurityConfig.java @@ -48,12 +48,21 @@ public class InMemorySecurityConfig { @Value("${demo.readOnly.password:1234}") private String demoReadOnlyPassword; + @Value("${demo.server.restore.user:serverRestoreUser}") + private String demoServerRestoreUser; + + @Value("${demo.server.restore.password:serverRestoreUserPass}") + private String demoServerRestoreUserPass; + @Autowired private String roleUser; @Autowired private String roleAdmin; + @Autowired + private String roleServerRestore; + @Bean(WebSecurityConfig.IN_MEMORY) public AuthenticationProvider authenticationProvider() { DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider(userDetailsService()); @@ -78,7 +87,12 @@ public InMemoryUserDetailsManager userDetailsService() { .username(demoReadOnly) .password(passwordEncoder.encode(demoReadOnlyPassword)) .build(); - return new InMemoryUserDetailsManager(user, adminUser, readOnlyUser); + UserDetails serverRestoreUser = User.builder() + .username(demoServerRestoreUser) + .password(passwordEncoder.encode(demoServerRestoreUserPass)) + .roles(roleServerRestore.toUpperCase()) + .build(); + return new InMemoryUserDetailsManager(user, adminUser, readOnlyUser, serverRestoreUser); } public static class InMemoryCondition implements Condition { diff --git a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/config/WebSecurityConfig.java b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/config/WebSecurityConfig.java index 2b465b2c1f..aace18d561 100644 --- a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/config/WebSecurityConfig.java +++ b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/config/WebSecurityConfig.java @@ -1,7 +1,9 @@ /* * Copyright (C) 2026 European Spallation Source ERIC. * - */package org.phoebus.service.saveandrestore.web.config; + */ + +package org.phoebus.service.saveandrestore.web.config; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -57,6 +59,9 @@ public class WebSecurityConfig { @Value("${role.admin:sar-admin}") private String roleAdmin; + @Value("${role.server.restore:sar-server-restore}") + private String roleServerRestore; + /** * * @return name of regular user role @@ -75,6 +80,14 @@ public String roleAdmin() { return roleAdmin.toUpperCase(); } + /** + * + * @return name of role authorizing server side restore + */ + @Bean + public String roleServerRestore(){ + return roleServerRestore; + } /** * @@ -114,7 +127,7 @@ public WebSecurityCustomizer ignoringCustomizer() { return web -> { // The below lists exceptions for authentication. web.ignoring().requestMatchers(HttpMethod.GET, "/**"); - web.ignoring().requestMatchers(HttpMethod.POST, "/**/login*"); + web.ignoring().requestMatchers(HttpMethod.POST, "/**/login"); }; } diff --git a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/AuthenticationController.java b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/AuthenticationController.java index 917162bfbf..59cfab84ed 100644 --- a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/AuthenticationController.java +++ b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/AuthenticationController.java @@ -1,24 +1,11 @@ /* - * Copyright (C) 2024 European Spallation Source ERIC. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Copyright (C) 2026 European Spallation Source ERIC. * */ package org.phoebus.service.saveandrestore.web.controllers; +import jakarta.servlet.http.HttpServletRequest; import org.phoebus.applications.saveandrestore.model.LoginCredentials; import org.phoebus.applications.saveandrestore.model.UserData; import org.springframework.beans.factory.annotation.Autowired; @@ -48,6 +35,9 @@ public class AuthenticationController extends BaseController { @Autowired private AuthenticationManager authenticationManager; + @Autowired + private String roleServerRestore; + /** * Authenticates user. * @@ -62,7 +52,7 @@ public ResponseEntity login(@RequestBody LoginCredentials loginCredent authentication = authenticationManager.authenticate(authentication); } catch (AuthenticationException e) { Logger.getLogger(AuthenticationController.class.getName()).log(Level.WARNING, "Unable to authenticate user " + loginCredentials.username(), e); - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); } List roles = authentication.getAuthorities().stream() .map(GrantedAuthority::getAuthority).collect(Collectors.toList()); @@ -70,4 +60,16 @@ public ResponseEntity login(@RequestBody LoginCredentials loginCredent new UserData(loginCredentials.username(), roles), HttpStatus.OK); } + + + /** + * Checks if a user is authorized to do server side restore. Note that this must be a POST endpoint + * as GET endpoints do not provide information on user authorization. + * @param request A {@link HttpServletRequest} object + * @return true if authorized, i.e. has the associated role. + */ + @PostMapping(value = "server-restore-authorized") + public boolean authorizedForServerRestore(HttpServletRequest request) { + return request.isUserInRole("ROLE_" + roleServerRestore.toUpperCase()); + } } diff --git a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/AuthorizationHelper.java b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/AuthorizationHelper.java index 3b4b41e0ee..574c3fdc82 100644 --- a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/AuthorizationHelper.java +++ b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/AuthorizationHelper.java @@ -1,19 +1,5 @@ /* - * Copyright (C) 2024 European Spallation Source ERIC. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Copyright (C) 2026 European Spallation Source ERIC. * */ @@ -52,6 +38,9 @@ public class AuthorizationHelper { @Autowired private String roleUser; + @Autowired + private String roleServerRestore; + @Value("${authorization.permitall:true}") private boolean permitAll; @@ -288,4 +277,14 @@ public boolean mayCreate(MethodSecurityExpressionOperations methodSecurityExpres public boolean mayMoveOrCopy(MethodSecurityExpressionOperations methodSecurityExpressionOperations) { return permitAll || methodSecurityExpressionOperations.hasAuthority(ROLE_PREFIX + roleAdmin); } + + /** + * Checks if user is authorized to perform server side restore. + * @param methodSecurityExpressionOperations {@link MethodSecurityExpressionOperations} Spring managed object + * queried for authorization. + * @return false if user is not authorized to request server side restore, otherwise true. + */ + public boolean hasServerRestoreAuthorization(MethodSecurityExpressionOperations methodSecurityExpressionOperations){ + return methodSecurityExpressionOperations.hasAuthority(ROLE_PREFIX + roleServerRestore); + } } diff --git a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/BaseController.java b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/BaseController.java index b732ed5c6c..0fa80174b1 100644 --- a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/BaseController.java +++ b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/BaseController.java @@ -1,24 +1,11 @@ /** - * Copyright (C) 2018 European Spallation Source ERIC. - *

- * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - *

- * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - *

- * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Copyright (C) 2026 European Spallation Source ERIC. */ package org.phoebus.service.saveandrestore.web.controllers; import org.phoebus.service.saveandrestore.NodeNotFoundException; import org.phoebus.service.saveandrestore.SnapshotNotFoundException; +import org.phoebus.service.saveandrestore.persistence.config.IndexConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -39,7 +26,7 @@ */ @RestController @SuppressWarnings("unused") -public abstract class BaseController { +public abstract class BaseController extends IndexConfig { protected static final String JSON = "application/json"; diff --git a/services/save-and-restore/src/main/resources/sar.ldif b/services/save-and-restore/src/main/resources/sar.ldif index 93b329e319..7f853992cd 100644 --- a/services/save-and-restore/src/main/resources/sar.ldif +++ b/services/save-and-restore/src/main/resources/sar.ldif @@ -32,7 +32,7 @@ uidNumber: 23006 gidNumber: 23006 homeDirectory: /dev/null -dn: uid=johndoe,ou=Group,dc=sar,dc=local +dn: uid=johndoe,ou=People,dc=sar,dc=local uid: johndoe objectClass: account objectClass: posixAccount @@ -44,6 +44,18 @@ uidNumber: 23007 gidNumber: 23007 homeDirectory: /dev/null +dn: uid=serverRestoreUser,ou=People,dc=sar,dc=local +uid: serverRestoreUser +objectClass: account +objectClass: posixAccount +description: User with server restore authorization +cn: serverRestoreUser +# bcrypt encoded string "1234" +userPassword: $2a$12$.gd4p4gwfNd3S0I1giLWfuEdtBvHCg/B9gi7OmAsyNAF62eWg4xDS +uidNumber: 23008 +gidNumber: 23008 +homeDirectory: /dev/null + dn: cn=sar-user,ou=Group,dc=sar,dc=local cn: sar-user objectClass: posixGroup @@ -59,3 +71,11 @@ description: save-n-restore admin gidNumber: 27003 uidNumber: 27003 memberUid: admin + +dn: cn=sar-server-restore,ou=Group,dc=sar,dc=local +cn: sar-server-restore +objectClass: posixGroup +description: restore role +gidNumber: 27004 +uidNumber: 27004 +memberUid: serverRestoreUser diff --git a/services/save-and-restore/src/main/resources/security/in_memory.properties b/services/save-and-restore/src/main/resources/security/in_memory.properties index 586fe366de..c9c30adaba 100644 --- a/services/save-and-restore/src/main/resources/security/in_memory.properties +++ b/services/save-and-restore/src/main/resources/security/in_memory.properties @@ -6,3 +6,5 @@ demo.admin=admin demo.admin.password=adminPass demo.readOnly=johndoe demo.readOnlyPassword=1234 +demo.server.restore.user=serverRestoreUser +demo.server.restore.password=serverRestoreUserPass diff --git a/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/config/ControllersTestConfig.java b/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/config/ControllersTestConfig.java index 8e4e665193..b27b624ceb 100644 --- a/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/config/ControllersTestConfig.java +++ b/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/config/ControllersTestConfig.java @@ -48,6 +48,9 @@ public class ControllersTestConfig { @Value("${role.admin:sar-admin}") private String roleAdmin; + @Value("${role.server.restore:sar-server-restore}") + private String roleServerRestore; + @Value("${demo.user:user}") private String demoUser; @@ -66,6 +69,12 @@ public class ControllersTestConfig { @Value("${demo.readOnly.password:1234}") private String demoReadOnlyPassword; + @Value("${demo.server.restore.user:serverRestoreUser}") + private String demoServerRestoreUser; + + @Value("${demo.server.restore.password:serverRestoreUserPass}") + private String demoServerRestoreUserPass; + @Bean public String demoUser() { return demoUser; @@ -76,6 +85,11 @@ public String demoAdmin() { return demoAdmin; } + @Bean + public String demoServerRestoreUser() { + return demoServerRestoreUser; + } + @Bean() public String roleAdmin(){ return roleAdmin.toUpperCase(); @@ -86,6 +100,11 @@ public String roleUser(){ return roleUser.toUpperCase(); } + @Bean + public String roleServerRestore(){ + return roleServerRestore.toUpperCase(); + } + @Bean public NodeDAO nodeDAO() { return Mockito.mock(NodeDAO.class); @@ -93,7 +112,7 @@ public NodeDAO nodeDAO() { @Bean public ElasticsearchTreeRepository elasticsearchTreeRepository() { - return Mockito.mock(ElasticsearchTreeRepository.class); + return Mockito.mock(ElasticsearchTreeRepository.class); } @Bean @@ -153,6 +172,11 @@ public String readOnlyAuthorization() { return "Basic " + Base64.getEncoder().encodeToString((demoReadOnly + ":" + demoReadOnlyPassword).getBytes()); } + @Bean("serverRestoreAuthorization") + public String serverRestoreAuthorization() { + return "Basic " + Base64.getEncoder().encodeToString((demoServerRestoreUser + ":" + demoServerRestoreUserPass).getBytes()); + } + @Bean public ExecutorService executorService() { return Executors.newCachedThreadPool(); @@ -160,7 +184,7 @@ public ExecutorService executorService() { @Bean public SnapshotUtil snapshotUtil() { - return new SnapshotUtil(); + return new SnapshotUtil(); } @Bean diff --git a/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/AuthenticationControllerTest.java b/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/AuthenticationControllerTest.java new file mode 100644 index 0000000000..55c6f013ed --- /dev/null +++ b/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/AuthenticationControllerTest.java @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2026 European Spallation Source ERIC. + * + */ + +package org.phoebus.service.saveandrestore.web.controllers; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.phoebus.applications.saveandrestore.model.LoginCredentials; +import org.phoebus.applications.saveandrestore.model.UserData; +import org.phoebus.service.saveandrestore.web.config.ControllersTestConfig; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpHeaders; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; +import tools.jackson.databind.ObjectMapper; + +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest(classes = {ControllersTestConfig.class}, + webEnvironment = SpringBootTest.WebEnvironment.MOCK, + properties = "spring.main.allow-bean-definition-overriding=true") +@TestPropertySource(locations = "classpath:test_application.properties") +public class AuthenticationControllerTest extends BaseController{ + + private MockMvc mockMvc; + + @Autowired + private WebApplicationContext webApplicationContext; + + @Autowired + private String userAuthorization; + + @Autowired + private String serverRestoreAuthorization; + + @Autowired + public String roleUser; + + @Value("${demo.user:user}") + private String demoUser; + + @Value("${demo.user.password:userPass}") + private String demoUserPassword; + + private ObjectMapper objectMapper = new ObjectMapper(); + + @BeforeEach + void setUp() { + mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + } + + @Test + public void testCheckServerRestoreAuthorizationRegularUser() throws Exception{ + MockHttpServletRequestBuilder request = post("/server-restore-authorized") + .header(HttpHeaders.AUTHORIZATION, userAuthorization); + + MvcResult result = mockMvc.perform(request).andExpect(status().isOk()) + .andReturn(); + + assertEquals("false", result.getResponse().getContentAsString()); + } + + @Test + public void testCheckServerRestoreAuthorizationServerRestoreUser() throws Exception{ + MockHttpServletRequestBuilder request = post("/server-restore-authorized") + .header(HttpHeaders.AUTHORIZATION, serverRestoreAuthorization); + + MvcResult result = mockMvc.perform(request).andExpect(status().isOk()) + .andReturn(); + + assertEquals("true", result.getResponse().getContentAsString()); + } + + @Test + public void testCheckServerRestoreUnauthenticated() throws Exception{ + MockHttpServletRequestBuilder request = post("/server-restore-authorized"); + + mockMvc.perform(request).andExpect(status().isUnauthorized()); + + } + + @Test + public void testSuccessfulLogin() throws Exception{ + + LoginCredentials loginCredentials = new LoginCredentials(demoUser, demoUserPassword); + MockHttpServletRequestBuilder request = post("/login") + .contentType(JSON).content(objectMapper.writeValueAsString(loginCredentials)); + + MvcResult result = mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentType(JSON)) + .andReturn(); + + // Make sure response contains expected data + UserData userData = objectMapper.readValue(result.getResponse().getContentAsString(), UserData.class); + + assertEquals(demoUser, userData.getUserName()); + assertTrue(userData.getRoles().size() > 1); // Spring Security adds role related to authentication procedure + assertTrue(userData.getRoles().contains("ROLE_" + roleUser)); + } + + @Test + public void testLoginBadCredentials() throws Exception{ + + LoginCredentials loginCredentials = new LoginCredentials("foo", "bar"); + MockHttpServletRequestBuilder request = post("/login") + .contentType(JSON).content(objectMapper.writeValueAsString(loginCredentials)); + + mockMvc.perform(request).andExpect(status().isUnauthorized()); + } + + @Test + public void testLoginMissingCredentials() throws Exception{ + + MockHttpServletRequestBuilder request = post("/login") + .contentType(JSON); + + mockMvc.perform(request).andExpect(status().isBadRequest()); + } +}