Criar serviço Rest
bug#15900 dev:trevezani qua: git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@97980 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
32a96e81f8
commit
1bf6a50e3e
|
@ -0,0 +1,27 @@
|
||||||
|
package com.rjconsultores.ventaboletos.rest;
|
||||||
|
|
||||||
|
import javax.annotation.security.RolesAllowed;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.rest.bean.ParamsAlterarSenha;
|
||||||
|
import com.rjconsultores.ventaboletos.rest.service.AlterarSenhaService;
|
||||||
|
import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext;
|
||||||
|
|
||||||
|
@Path("/alterarSenha")
|
||||||
|
public class AlterarSenhaRS {
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
|
@RolesAllowed("EMBARCADA")
|
||||||
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
|
public Response alterarSenha(ParamsAlterarSenha params) {
|
||||||
|
AlterarSenhaService service = (AlterarSenhaService) AppContext.getApplicationContext().getBean("alterarSenhaService");
|
||||||
|
return Response.ok(service.alterarSenha(params), MediaType.APPLICATION_JSON).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.rjconsultores.ventaboletos.rest.bean;
|
||||||
|
|
||||||
|
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
|
||||||
|
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
public class ParamsAlterarSenha {
|
||||||
|
private Integer usuarioId;
|
||||||
|
private String senhaAtual;
|
||||||
|
private String novaSenha;
|
||||||
|
|
||||||
|
public ParamsAlterarSenha() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getUsuarioId() {
|
||||||
|
return usuarioId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsuarioId(Integer usuarioId) {
|
||||||
|
this.usuarioId = usuarioId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSenhaAtual() {
|
||||||
|
return senhaAtual;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSenhaAtual(String senhaAtual) {
|
||||||
|
this.senhaAtual = senhaAtual;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNovaSenha() {
|
||||||
|
return novaSenha;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNovaSenha(String novaSenha) {
|
||||||
|
this.novaSenha = novaSenha;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.rjconsultores.ventaboletos.rest.returns;
|
||||||
|
|
||||||
|
public class AlteracaoSenhaRetorno {
|
||||||
|
private String status;
|
||||||
|
private String mensagem;
|
||||||
|
|
||||||
|
public AlteracaoSenhaRetorno() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMensagem() {
|
||||||
|
return mensagem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMensagem(String mensagem) {
|
||||||
|
this.mensagem = mensagem;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.rjconsultores.ventaboletos.rest.service;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Usuario;
|
||||||
|
import com.rjconsultores.ventaboletos.exception.BusinessException;
|
||||||
|
import com.rjconsultores.ventaboletos.rest.bean.ParamsAlterarSenha;
|
||||||
|
import com.rjconsultores.ventaboletos.rest.returns.AlteracaoSenhaRetorno;
|
||||||
|
import com.rjconsultores.ventaboletos.service.UsuarioService;
|
||||||
|
import com.rjconsultores.ventaboletos.utilerias.seguridad.ContrasenaUtileria;
|
||||||
|
|
||||||
|
@Service("alterarSenhaService")
|
||||||
|
public class AlterarSenhaService {
|
||||||
|
@Autowired
|
||||||
|
private UsuarioService usuarioService;
|
||||||
|
|
||||||
|
public AlteracaoSenhaRetorno alterarSenha(ParamsAlterarSenha params) {
|
||||||
|
AlteracaoSenhaRetorno retorno = new AlteracaoSenhaRetorno();
|
||||||
|
retorno.setStatus("SUCCESS");
|
||||||
|
|
||||||
|
if (params.getUsuarioId() == null ||
|
||||||
|
params.getSenhaAtual() == null || params.getSenhaAtual().isEmpty() ||
|
||||||
|
params.getNovaSenha() == null || params.getNovaSenha().isEmpty()) {
|
||||||
|
retorno.setStatus("ERROR");
|
||||||
|
retorno.setMensagem("Chamada invalida");
|
||||||
|
|
||||||
|
return retorno;
|
||||||
|
}
|
||||||
|
|
||||||
|
Usuario usuario = usuarioService.obtenerID(params.getUsuarioId());
|
||||||
|
|
||||||
|
if (usuario == null) {
|
||||||
|
retorno.setStatus("ERROR");
|
||||||
|
retorno.setMensagem("Usuario nao encontrado");
|
||||||
|
} else if (!usuario.getSenha().equals(ContrasenaUtileria.encriptarContrasena(params.getSenhaAtual()))) {
|
||||||
|
retorno.setStatus("ERROR");
|
||||||
|
retorno.setMensagem("Senha atual invalida");
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
usuarioService.cambiarContrasena(usuario, params.getNovaSenha());
|
||||||
|
} catch (BusinessException e) {
|
||||||
|
retorno.setStatus("ERROR");
|
||||||
|
retorno.setMensagem(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return retorno;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue