Commit 8f9d0607ca81de5d81ef7a60e4751797d46e3164
1 parent
91416358
Exists in
master
redmine #4583 validacao usuario ldap ao assinar
Showing
1 changed file
with
25 additions
and
35 deletions
Show diff stats
cit-ecm-api/src/main/java/br/com/centralit/api/service/impl/AssinaturaServiceImpl.java
| @@ -35,10 +35,13 @@ import br.com.centralit.framework.service.arquitetura.GenericServiceImpl; | @@ -35,10 +35,13 @@ import br.com.centralit.framework.service.arquitetura.GenericServiceImpl; | ||
| 35 | import br.com.centralit.framework.util.UtilObjeto; | 35 | import br.com.centralit.framework.util.UtilObjeto; |
| 36 | import br.com.centralit.framework.util.UtilString; | 36 | import br.com.centralit.framework.util.UtilString; |
| 37 | 37 | ||
| 38 | - | ||
| 39 | /** | 38 | /** |
| 40 | - * <p><b>Title: </b></p> | ||
| 41 | - * <p><b>Description: </b></p> | 39 | + * <p> |
| 40 | + * <b>Title: </b> | ||
| 41 | + * </p> | ||
| 42 | + * <p> | ||
| 43 | + * <b>Description: </b> | ||
| 44 | + * </p> | ||
| 42 | * <p> | 45 | * <p> |
| 43 | * <b>Title: </b> | 46 | * <b>Title: </b> |
| 44 | * </p> | 47 | * </p> |
| @@ -56,39 +59,30 @@ public class AssinaturaServiceImpl extends GenericServiceImpl<Assinatura, Long> | @@ -56,39 +59,30 @@ public class AssinaturaServiceImpl extends GenericServiceImpl<Assinatura, Long> | ||
| 56 | 59 | ||
| 57 | @Autowired | 60 | @Autowired |
| 58 | private AssinaturaDao assinaturaDao; | 61 | private AssinaturaDao assinaturaDao; |
| 59 | - | ||
| 60 | 62 | ||
| 61 | @Autowired | 63 | @Autowired |
| 62 | private DocumentoGedService documentoGedService; | 64 | private DocumentoGedService documentoGedService; |
| 63 | - | ||
| 64 | 65 | ||
| 65 | @Autowired | 66 | @Autowired |
| 66 | private UsuarioService usuarioService; | 67 | private UsuarioService usuarioService; |
| 67 | - | ||
| 68 | 68 | ||
| 69 | @Autowired | 69 | @Autowired |
| 70 | private DominioService dominioService; | 70 | private DominioService dominioService; |
| 71 | - | ||
| 72 | 71 | ||
| 73 | @Autowired | 72 | @Autowired |
| 74 | private FuncaoService funcaoService; | 73 | private FuncaoService funcaoService; |
| 75 | - | ||
| 76 | 74 | ||
| 77 | @Autowired | 75 | @Autowired |
| 78 | private PessoaService pessoaService; | 76 | private PessoaService pessoaService; |
| 79 | - | ||
| 80 | 77 | ||
| 81 | @Autowired | 78 | @Autowired |
| 82 | private HistoricoAlteracaoProcessoService historicoAlteracaoProcessoService; | 79 | private HistoricoAlteracaoProcessoService historicoAlteracaoProcessoService; |
| 83 | - | ||
| 84 | 80 | ||
| 85 | @Autowired | 81 | @Autowired |
| 86 | private TarjaAssinaturaService tarjaAssinaturaService; | 82 | private TarjaAssinaturaService tarjaAssinaturaService; |
| 87 | - | ||
| 88 | 83 | ||
| 89 | @Value("${metodo.autenticacao.ldap}") | 84 | @Value("${metodo.autenticacao.ldap}") |
| 90 | private String ldap; | 85 | private String ldap; |
| 91 | - | ||
| 92 | 86 | ||
| 93 | @Value("${ldap.host.name}") | 87 | @Value("${ldap.host.name}") |
| 94 | public String ldapHostName; | 88 | public String ldapHostName; |
| @@ -103,12 +97,10 @@ public class AssinaturaServiceImpl extends GenericServiceImpl<Assinatura, Long> | @@ -103,12 +97,10 @@ public class AssinaturaServiceImpl extends GenericServiceImpl<Assinatura, Long> | ||
| 103 | public String ldapSearchDC; | 97 | public String ldapSearchDC; |
| 104 | 98 | ||
| 105 | @Autowired | 99 | @Autowired |
| 106 | - public AssinaturaServiceImpl( AssinaturaDao assinaturaDao) { | ||
| 107 | public AssinaturaServiceImpl( AssinaturaDao assinaturaDao ) { | 100 | public AssinaturaServiceImpl( AssinaturaDao assinaturaDao ) { |
| 108 | 101 | ||
| 109 | this.dao = assinaturaDao; | 102 | this.dao = assinaturaDao; |
| 110 | } | 103 | } |
| 111 | - | ||
| 112 | 104 | ||
| 113 | /** | 105 | /** |
| 114 | * Salva assinatura do documento e gera histórico | 106 | * Salva assinatura do documento e gera histórico |
| @@ -120,7 +112,7 @@ public class AssinaturaServiceImpl extends GenericServiceImpl<Assinatura, Long> | @@ -120,7 +112,7 @@ public class AssinaturaServiceImpl extends GenericServiceImpl<Assinatura, Long> | ||
| 120 | validarSenha(assinatura.getPassword(), usuario); | 112 | validarSenha(assinatura.getPassword(), usuario); |
| 121 | montarTransients(assinatura, usuario); | 113 | montarTransients(assinatura, usuario); |
| 122 | historicoAlteracaoProcessoService.gerarHistoricoAssinatura(assinatura); | 114 | historicoAlteracaoProcessoService.gerarHistoricoAssinatura(assinatura); |
| 123 | - tarjaAssinaturaService.gerarAssinaturaInternaUsuario(assinatura,assinatura.getDocumentoGed().getFormaCriacao().getCodigo()); | 115 | + tarjaAssinaturaService.gerarAssinaturaInternaUsuario(assinatura, assinatura.getDocumentoGed().getFormaCriacao().getCodigo()); |
| 124 | tarjaAssinaturaService.gerarAssinaturaInternaUsuario(assinatura, assinatura.getDocumentoGed().getFormaCriacao().getCodigo()); | 116 | tarjaAssinaturaService.gerarAssinaturaInternaUsuario(assinatura, assinatura.getDocumentoGed().getFormaCriacao().getCodigo()); |
| 125 | alterarEstadoDocumento(assinatura.getDocumentoGed()); | 117 | alterarEstadoDocumento(assinatura.getDocumentoGed()); |
| 126 | return super.save(assinatura); | 118 | return super.save(assinatura); |
| @@ -133,10 +125,11 @@ public class AssinaturaServiceImpl extends GenericServiceImpl<Assinatura, Long> | @@ -133,10 +125,11 @@ public class AssinaturaServiceImpl extends GenericServiceImpl<Assinatura, Long> | ||
| 133 | * @param documentoGed | 125 | * @param documentoGed |
| 134 | */ | 126 | */ |
| 135 | private void alterarEstadoDocumento(DocumentoGed documentoGed) { | 127 | private void alterarEstadoDocumento(DocumentoGed documentoGed) { |
| 136 | - if(documentoGed.getFormaCriacao().getCodigo().equals(1L) && !documentoGed.getEstado().getCodigo().equals(2L)) | ||
| 137 | 128 | ||
| 138 | if (documentoGed.getFormaCriacao().getCodigo().equals(1L) && !documentoGed.getEstado().getCodigo().equals(2L)) | 129 | if (documentoGed.getFormaCriacao().getCodigo().equals(1L) && !documentoGed.getEstado().getCodigo().equals(2L)) |
| 139 | - documentoGed.setEstado(dominioService.findByChaveAndCodigo("estadoDocumentoGed", 2L)); | 130 | + |
| 131 | + if (documentoGed.getFormaCriacao().getCodigo().equals(1L) && !documentoGed.getEstado().getCodigo().equals(2L)) | ||
| 132 | + documentoGed.setEstado(dominioService.findByChaveAndCodigo("estadoDocumentoGed", 2L)); | ||
| 140 | } | 133 | } |
| 141 | 134 | ||
| 142 | /** | 135 | /** |
| @@ -154,7 +147,6 @@ public class AssinaturaServiceImpl extends GenericServiceImpl<Assinatura, Long> | @@ -154,7 +147,6 @@ public class AssinaturaServiceImpl extends GenericServiceImpl<Assinatura, Long> | ||
| 154 | assinatura.setTipoAssinatura(dominioService.findByChaveAndCodigo(Dominio.TIPO_ASSINATURA, Dominio.TIPO_ASSINATURA_INTERNA)); | 147 | assinatura.setTipoAssinatura(dominioService.findByChaveAndCodigo(Dominio.TIPO_ASSINATURA, Dominio.TIPO_ASSINATURA_INTERNA)); |
| 155 | assinatura.setFuncao(funcaoService.getReference(assinatura.getFuncao().getId())); | 148 | assinatura.setFuncao(funcaoService.getReference(assinatura.getFuncao().getId())); |
| 156 | } | 149 | } |
| 157 | - | ||
| 158 | 150 | ||
| 159 | /** | 151 | /** |
| 160 | * Método responsável por validar senha para assinar o documento | 152 | * Método responsável por validar senha para assinar o documento |
| @@ -164,24 +156,25 @@ public class AssinaturaServiceImpl extends GenericServiceImpl<Assinatura, Long> | @@ -164,24 +156,25 @@ public class AssinaturaServiceImpl extends GenericServiceImpl<Assinatura, Long> | ||
| 164 | * @param usuario | 156 | * @param usuario |
| 165 | */ | 157 | */ |
| 166 | private void validarSenha(String password, Usuario usuario) { | 158 | private void validarSenha(String password, Usuario usuario) { |
| 167 | - | ||
| 168 | - if(!UtilString.isNullOrEmpty(ldap) && ldap.equals("false")) { | ||
| 169 | 159 | ||
| 170 | - if(UtilString.isNullOrEmpty(password)) | ||
| 171 | - if (!UtilString.isNullOrEmpty(ldap) && !Boolean.parseBoolean(ldap)) { | 160 | + if (!UtilString.isNullOrEmpty(ldap) && ldap.equals("false")) { |
| 172 | 161 | ||
| 173 | if (UtilString.isNullOrEmpty(password)) | 162 | if (UtilString.isNullOrEmpty(password)) |
| 174 | - throw new BusinessException("ECM.VALIDACAO.SENHA_ASSINATURA", CodigoErro.REGRA_NEGOCIO.getValue(), ""); | ||
| 175 | - | ||
| 176 | - if(!UtilObjeto.isReferencia(this.usuarioService.loadUserByUsernamePasswordMobile(usuario.getUsername(), password))) | 163 | + if (!UtilString.isNullOrEmpty(ldap) && !Boolean.parseBoolean(ldap)) { |
| 164 | + | ||
| 165 | + if (UtilString.isNullOrEmpty(password)) | ||
| 166 | + throw new BusinessException("ECM.VALIDACAO.SENHA_ASSINATURA", CodigoErro.REGRA_NEGOCIO.getValue(), ""); | ||
| 167 | + | ||
| 168 | + if (!UtilObjeto.isReferencia(this.usuarioService.loadUserByUsernamePasswordMobile(usuario.getUsername(), password))) | ||
| 177 | 169 | ||
| 178 | - if (!UtilObjeto.isReferencia(this.usuarioService.loadUserByUsernamePasswordMobile(usuario.getUsername(), password))) | ||
| 179 | - throw new BusinessException("ECM.VALIDACAO.SENHA_ASSINATURA_INVALIDA", CodigoErro.REGRA_NEGOCIO.getValue(), ""); | ||
| 180 | - | 170 | + if (!UtilObjeto.isReferencia(this.usuarioService.loadUserByUsernamePasswordMobile(usuario.getUsername(), password))) |
| 171 | + throw new BusinessException("ECM.VALIDACAO.SENHA_ASSINATURA_INVALIDA", CodigoErro.REGRA_NEGOCIO.getValue(), ""); | ||
| 181 | 172 | ||
| 182 | - } else if (!UtilString.isNullOrEmpty(ldap) && Boolean.parseBoolean(ldap)) { | 173 | + } else if (!UtilString.isNullOrEmpty(ldap) && Boolean.parseBoolean(ldap)) { |
| 174 | + | ||
| 175 | + autenticarMaster(password, usuario.getUsername()); | ||
| 176 | + } | ||
| 183 | 177 | ||
| 184 | - autenticarMaster(password, usuario.getUsername()); | ||
| 185 | } | 178 | } |
| 186 | } | 179 | } |
| 187 | 180 | ||
| @@ -211,11 +204,10 @@ public class AssinaturaServiceImpl extends GenericServiceImpl<Assinatura, Long> | @@ -211,11 +204,10 @@ public class AssinaturaServiceImpl extends GenericServiceImpl<Assinatura, Long> | ||
| 211 | if (autenticarUser(result.getName() + "," + ldapSearchDC, password)) { | 204 | if (autenticarUser(result.getName() + "," + ldapSearchDC, password)) { |
| 212 | return Boolean.TRUE; | 205 | return Boolean.TRUE; |
| 213 | } else { | 206 | } else { |
| 214 | - //TODO LDAP validação | ||
| 215 | throw new BusinessException("ECM.VALIDACAO.SENHA_ASSINATURA_INVALIDA", CodigoErro.REGRA_NEGOCIO.getValue(), ""); | 207 | throw new BusinessException("ECM.VALIDACAO.SENHA_ASSINATURA_INVALIDA", CodigoErro.REGRA_NEGOCIO.getValue(), ""); |
| 216 | } | 208 | } |
| 217 | } | 209 | } |
| 218 | - | 210 | + |
| 219 | } catch (AuthenticationException authEx) { | 211 | } catch (AuthenticationException authEx) { |
| 220 | throw new BusinessException("ECM.VALIDACAO.SENHA_ASSINATURA_INVALIDA", CodigoErro.REGRA_NEGOCIO.getValue(), ""); | 212 | throw new BusinessException("ECM.VALIDACAO.SENHA_ASSINATURA_INVALIDA", CodigoErro.REGRA_NEGOCIO.getValue(), ""); |
| 221 | } catch (NamingException namEx) { | 213 | } catch (NamingException namEx) { |
| @@ -250,7 +242,6 @@ public class AssinaturaServiceImpl extends GenericServiceImpl<Assinatura, Long> | @@ -250,7 +242,6 @@ public class AssinaturaServiceImpl extends GenericServiceImpl<Assinatura, Long> | ||
| 250 | */ | 242 | */ |
| 251 | @Override | 243 | @Override |
| 252 | public Boolean validarAssinaturaPorUsuario(Long idDocumento) { | 244 | public Boolean validarAssinaturaPorUsuario(Long idDocumento) { |
| 253 | - return this.assinaturaDao.validarAssinaturaPorUsuario(idDocumento, ((Usuario) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getId()); | ||
| 254 | 245 | ||
| 255 | return this.assinaturaDao.validarAssinaturaPorUsuario(idDocumento, ( (Usuario) SecurityContextHolder.getContext().getAuthentication().getPrincipal() ).getId()); | 246 | return this.assinaturaDao.validarAssinaturaPorUsuario(idDocumento, ( (Usuario) SecurityContextHolder.getContext().getAuthentication().getPrincipal() ).getId()); |
| 256 | } | 247 | } |
| @@ -260,10 +251,9 @@ public class AssinaturaServiceImpl extends GenericServiceImpl<Assinatura, Long> | @@ -260,10 +251,9 @@ public class AssinaturaServiceImpl extends GenericServiceImpl<Assinatura, Long> | ||
| 260 | 251 | ||
| 261 | Assinatura assinatura = (Assinatura) this.assinaturaDao.getReference(id); | 252 | Assinatura assinatura = (Assinatura) this.assinaturaDao.getReference(id); |
| 262 | assinatura.getConteudoTarja().setConteudo(tarjaAssinaturaService.decrypted(assinatura.getConteudoTarja().getConteudoCriptografado())); | 253 | assinatura.getConteudoTarja().setConteudo(tarjaAssinaturaService.decrypted(assinatura.getConteudoTarja().getConteudoCriptografado())); |
| 263 | - if(UtilObjeto.isReferencia(assinatura.getDocumentoGed().getConteudoTarja())){ | ||
| 264 | if (UtilObjeto.isReferencia(assinatura.getDocumentoGed().getConteudoTarja())) { | 254 | if (UtilObjeto.isReferencia(assinatura.getDocumentoGed().getConteudoTarja())) { |
| 265 | assinatura.getDocumentoGed().getConteudoTarja().setConteudo(tarjaAssinaturaService.decrypted(assinatura.getDocumentoGed().getConteudoTarja().getConteudoCriptografado())); | 255 | assinatura.getDocumentoGed().getConteudoTarja().setConteudo(tarjaAssinaturaService.decrypted(assinatura.getDocumentoGed().getConteudoTarja().getConteudoCriptografado())); |
| 266 | } | 256 | } |
| 267 | return assinatura; | 257 | return assinatura; |
| 268 | } | 258 | } |
| 269 | -} | ||
| 270 | \ No newline at end of file | 259 | \ No newline at end of file |
| 260 | +} |