【发布时间】:2019-04-01 22:04:40
【问题描述】:
我正在尝试将密码值传递给 spring-boot 控制器,但没有得到任何回应,有人可以就此提出建议吗?
我之前使用的是spring MVC控制器,第一次尝试spring-boot
<form method="POST" th:action="@{/esparkUserPage}">
<div class="control-group">
<input id="password" type="password" name="password" class="form-control input-sm" required="User Pwd is Required" placeholder="password" />
<label class="login-field-icon fui-lock" for="login-pass"></label>
</div>
<input class="btn btn-primary btn-large btn-block" type="submit" value="Submit" id="submit" name="submit" />
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form>
MVc配置:
@Configuration
public class WbMvcConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("esparkLoginPage");
registry.addViewController("/esparkHome").setViewName("esparkHome");
registry.addViewController("/esparkUserPage").setViewName("esparkUserPage");
registry.addViewController("/esparkLoginPage").setViewName("esparkLoginPage");
}
}
安全配置:
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.authorizeRequests()
//.antMatchers("/", "/esparkLoginPage","/passReset").permitAll()
.anyRequest()
.permitAll() //.authenticated()
.and()
.formLogin()
.loginPage("/esparkLoginPage")
.defaultSuccessUrl("/esparkUserPage")
.permitAll()
.and()
.csrf().disable()
.logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/esparkLoginPage")
.permitAll();
}
重置控制器
@Controller
public class ResetController {
@ResponseBody
@RequestMapping(value = "/esparkUserPage", method = RequestMethod.POST)
public String esparkUserPage(HttpServletRequest httpRequest,HttpServletResponse response ) {
String username = httpRequest.getParameter("username");
String password = httpRequest.getParameter("password");
System.out.println(username);
List<String> result = new ArrayList<String>();
/* try
{
JSch jsch = new JSch();
System.out.println("Inside shell");
Session session = jsch.getSession(USERNAME, host, port);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword(PASSWORD);
session.connect();
//create the excution channel over the session
ChannelExec channelExec = (ChannelExec)session.openChannel("exec");
System.out.println(channelExec.toString());
// Gets an InputStream for this channel. All data arriving in as messages from the remote side can be read from this stream.
InputStream in = channelExec.getInputStream();
String com="sh set_passwd"+" "+username+" "+"'"+password+"'" ;
channelExec.setCommand(com);
channelExec.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = reader.readLine()) != null)
{
result.add(line);
}
int exitStatus = channelExec.getExitStatus();
channelExec.disconnect();
session.disconnect();
if(exitStatus < 0){
}
else if(exitStatus > 0){
}
else{
}
}
catch(Exception e)
{
System.err.println("Error: " + e);
}*/
return "Password Reset Done!";
}
}
还请建议从 spring-boot 执行 shell 命令的最佳方法? 第一次使用 spring-boot 仅供参考。
【问题讨论】:
-
memorynotfound.com/… 按照本教程进行操作。
标签: java spring jsp spring-boot spring-security