@Before public void setup() { logger.info("setup"); this.mockMvc = MockMvcBuilders.webAppContextSetup(context).addFilters(springSecurityFilterChain).build(); User user = null; try { user = userService.findByLogin("johndoe"); } catch (ServiceException e) { logger.error(e.getLocalizedMessage()); } Authentication authentication = null; if (user != null) { authentication = new UsernamePasswordAuthenticationToken(user.getLogin(), user.getPassword()); } Authentication result = authenticationManager.authenticate(authentication); SecurityContext securityContext = SecurityContextHolder.getContext(); securityContext.setAuthentication(result); session = new MockHttpSession(); session.setAttribute( HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, securityContext); }
@Before public void setup() { logger.info("setup"); this.mockMvc = MockMvcBuilders.webAppContextSetup(context).addFilters(springSecurityFilterChain).build(); User user = null; try { user = userService.findByLogin("johndoe"); } catch (ServiceException e) { logger.error(e.getLocalizedMessage()); } Authentication authentication = new UsernamePasswordAuthenticationToken(user.getLogin(), user.getPassword()); Authentication result = authenticationManager.authenticate(authentication); SecurityContext securityContext = SecurityContextHolder.getContext(); securityContext.setAuthentication(result); session = new MockHttpSession(); session.setAttribute( HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, securityContext); try { logger.info("Create Tomcat server"); String jsonString = "{\"applicationName\":\"" + applicationName + "\", \"serverName\":\"" + release + "\"}"; ResultActions resultats = mockMvc.perform( post("/application") .session(session) .contentType(MediaType.APPLICATION_JSON) .content(jsonString)); resultats.andExpect(status().isOk()); } catch (Exception e) { logger.error(e.getMessage()); } }
/** * Lancer par signal de NoPublicController quand le processus sshd est (re)démarré dans container * serveur et git, pour mettre à jour la nouvelle IP du serveur */ @Override public Application sshCopyIDToServer(Application application, User user) throws ServiceException { String command = null; Map<String, String> configShell = new HashMap<>(); Module moduleGit = moduleService.findGitModule(user.getLogin(), application); if (logger.isDebugEnabled()) { logger.debug("--ssh Copy ID To Server--"); logger.debug("ssh port : " + moduleGit.getSshPort()); logger.debug("manager ip : " + application.getManagerIp()); } for (Server server : application.getServers()) { configShell.put("password", server.getApplication().getUser().getPassword()); configShell.put("port", moduleGit.getSshPort()); configShell.put("dockerManagerAddress", application.getManagerIp()); configShell.put("userLogin", server.getApplication().getUser().getLogin()); try { int counter = 0; while (!server.getStatus().equals(Status.START) || !moduleGit.getStatus().equals(Status.START)) { if (counter == 100) { break; } Thread.sleep(1000); logger.info(" wait git and server ssh processus start"); logger.info( "STATUS = server : " + server.getStatus() + " - module : " + moduleGit.getStatus()); moduleGit = moduleService.findById(moduleGit.getId()); server = serverService.findById(server.getId()); counter++; } // To permit ssh access on server from git container command = "expect /cloudunit/scripts/ssh-copy-id-expect.sh " + moduleGit.getApplication().getUser().getPassword(); logger.info("command shell to execute [" + command + "]"); shellUtils.executeShell(command, configShell); } catch (Exception e) { moduleGit.setStatus(Status.FAIL); moduleGit = moduleService.saveInDB(moduleGit); server.setStatus(Status.FAIL); server = serverService.saveInDB(server); logger.error("Error : Error during permit git to access to server " + e); throw new ServiceException(e.getLocalizedMessage(), e); } } try { moduleGit = moduleService.update(moduleGit); application.getModules().add(moduleGit); application.setGitContainerIP(moduleGit.getContainerIP()); } catch (ServiceException e) { moduleGit.setStatus(Status.FAIL); moduleService.saveInDB(moduleGit); logger.error("Error : Error during persist git module " + e); throw new ServiceException(e.getLocalizedMessage(), e); } logger.info( "ApplicationService : Application " + application.getName() + " successfully created."); return application; }