| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.sip.RequestEvent; |
| | | import javax.sip.SipException; |
| | |
| | | AddressImpl address = (AddressImpl) fromHeader.getAddress(); |
| | | SipUri uri = (SipUri) address.getURI(); |
| | | String deviceId = uri.getUser(); |
| | | |
| | | Device device = deviceService.getDevice(deviceId); |
| | | String password = (device != null && !ObjectUtils.isEmpty(device.getPassword()))? device.getPassword() : sipConfig.getPassword(); |
| | | AuthorizationHeader authHead = (AuthorizationHeader) request.getHeader(AuthorizationHeader.NAME); |
| | | if (authHead == null && !ObjectUtils.isEmpty(sipConfig.getPassword())) { |
| | | if (authHead == null && !ObjectUtils.isEmpty(password)) { |
| | | logger.info("[注册请求] 未携带授权头 回复401: {}", requestAddress); |
| | | response = getMessageFactory().createResponse(Response.UNAUTHORIZED, request); |
| | | new DigestServerAuthenticationHelper().generateChallenge(getHeaderFactory(), response, sipConfig.getDomain()); |
| | |
| | | } |
| | | |
| | | // 校验密码是否正确 |
| | | passwordCorrect = ObjectUtils.isEmpty(sipConfig.getPassword()) || |
| | | new DigestServerAuthenticationHelper().doAuthenticatePlainTextPassword(request, sipConfig.getPassword()); |
| | | passwordCorrect = ObjectUtils.isEmpty(password) || |
| | | new DigestServerAuthenticationHelper().doAuthenticatePlainTextPassword(request, password); |
| | | |
| | | if (!passwordCorrect) { |
| | | // 注册失败 |
| | |
| | | sipSender.transmitRequest(response); |
| | | return; |
| | | } |
| | | |
| | | Device device = deviceService.queryDevice(deviceId); |
| | | |
| | | // 携带授权头并且密码正确 |
| | | response = getMessageFactory().createResponse(Response.OK, request); |