Set password for sip endpoint using API
This commit is contained in:
parent
4e6a39bf4a
commit
ab41e16bb2
@ -13,7 +13,7 @@
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"id\": \"1004\",\n \"transport\": \"transport-udp\",\n \"aors\": \"1004\",\n \"auth\": \"1004\",\n \"context\": \"default\",\n \"disallow\": \"all\",\n \"allow\": \"ulaw,alaw\",\n \"directMedia\": \"no\",\n \"connectedLineMethod\": \"invite\",\n \"callerid\": \"User <1004>\",\n \"dtmfMode\": \"rfc4733\",\n \"mohsuggest\": \"default\",\n \"mailboxes\": \"1004@default\"\n}\n\n// {\n// \"id\": \"1004\",\n// \"transport\": \"transport-udp\",\n// \"aors\": \"1004\",\n// \"auth\": \"1004\",\n// \"context\": \"default\",\n// \"disallow\": \"all\",\n// \"allow\": \"ulaw,alaw\",\n// \"directMedia\": \"no\",\n// \"connectedLineMethod\": null,\n// \"callerid\": \"User <1004>\",\n// \"dtmfMode\": null,\n// \"mohsuggest\": \"default\",\n// \"mailboxes\": \"1004@default\"\n// }",
|
||||
"raw": "{\n \"id\": \"1005\",\n \"transport\": \"transport-udp\",\n \"aors\": \"1005\",\n \"auth\": \"1005\",\n \"context\": \"default\",\n \"disallow\": \"all\",\n \"allow\": \"ulaw,alaw\",\n \"directMedia\": \"no\",\n \"connectedLineMethod\": \"invite\",\n \"callerid\": \"User <1005>\",\n \"dtmfMode\": \"rfc4733\",\n \"mohsuggest\": \"default\",\n \"mailboxes\": \"1005@default\"\n}\n\n// {\n// \"id\": \"1004\",\n// \"transport\": \"transport-udp\",\n// \"aors\": \"1004\",\n// \"auth\": \"1004\",\n// \"context\": \"default\",\n// \"disallow\": \"all\",\n// \"allow\": \"ulaw,alaw\",\n// \"directMedia\": \"no\",\n// \"connectedLineMethod\": null,\n// \"callerid\": \"User <1004>\",\n// \"dtmfMode\": null,\n// \"mohsuggest\": \"default\",\n// \"mailboxes\": \"1004@default\"\n// }",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
@ -36,13 +36,13 @@
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "New Request",
|
||||
"name": "create a new extension",
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"context\": \"default\",\n \"extension\": \"1004\",\n \"priority\": 2,\n \"app\": \"Dial\",\n \"appdata\": \"PJSIP/1004,20,m(default)\"\n}\n",
|
||||
"raw": "{\n \"context\": \"default\",\n \"extension\": \"1005\",\n \"priority\": 2,\n \"app\": \"Dial\",\n \"appdata\": \"PJSIP/1005,20,m(default)\"\n}\n",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
@ -63,6 +63,35 @@
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "set_password",
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"id\": \"1005\",\n \"authType\": \"userpass\",\n \"userName\": \"1005\",\n \"password\": \"12345\",\n \"md5Cred\": null,\n \"realm\": null\n}\n",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "http://localhost:8081/cezen/set_password",
|
||||
"protocol": "http",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "8081",
|
||||
"path": [
|
||||
"cezen",
|
||||
"set_password"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
}
|
||||
]
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,6 +2,8 @@
|
||||
13,2
|
||||
13,1
|
||||
13,0
|
||||
11,5
|
||||
11,4
|
||||
11,3
|
||||
11,2
|
||||
11,1
|
||||
@ -111,13 +113,18 @@
|
||||
2,18
|
||||
1,18
|
||||
3,17
|
||||
2,48
|
||||
2,17
|
||||
1,17
|
||||
3,16
|
||||
2,16
|
||||
1,49
|
||||
1,16
|
||||
3,45
|
||||
3,15
|
||||
2,47
|
||||
2,15
|
||||
1,48
|
||||
1,15
|
||||
3,14
|
||||
2,14
|
||||
@ -126,10 +133,13 @@
|
||||
2,13
|
||||
1,13
|
||||
3,12
|
||||
2,46
|
||||
2,12
|
||||
1,12
|
||||
3,11
|
||||
2,45
|
||||
2,11
|
||||
1,47
|
||||
1,11
|
||||
3,10
|
||||
2,10
|
||||
@ -139,6 +149,7 @@
|
||||
1,9
|
||||
3,8
|
||||
2,8
|
||||
1,46
|
||||
1,8
|
||||
3,7
|
||||
2,7
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,6 +2,7 @@ package com.example.cezenPBX.DAO;
|
||||
|
||||
import com.example.cezenPBX.DTO.ReturnStatus;
|
||||
import com.example.cezenPBX.entity.ExtensionsTable;
|
||||
import com.example.cezenPBX.entity.PsAuths;
|
||||
import com.example.cezenPBX.entity.PsEndPoints;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.transaction.Transactional;
|
||||
@ -40,18 +41,33 @@ public class BasicAsteriskOpsDAO implements CezenPbxOpsDAO {
|
||||
@Override
|
||||
@Transactional
|
||||
public ReturnStatus saveAnExtension(ExtensionsTable extensionsTable) {
|
||||
|
||||
// check if endpoint exists
|
||||
try{
|
||||
System.out.println("End point ID is " + findEndPontById(extensionsTable.getExtension()).getId());
|
||||
}catch (Exception e){
|
||||
return new ReturnStatus(false, "Create Endpoint First for " + extensionsTable.getExtension(),e.toString());
|
||||
return new ReturnStatus(false, "Create Endpoint for " + extensionsTable.getExtension(),e.toString() + " First");
|
||||
}
|
||||
|
||||
System.out.println("Context in DAO is " + extensionsTable.getContext());
|
||||
|
||||
this.entityManager.persist(extensionsTable);
|
||||
return new ReturnStatus(true, extensionsTable.getExtension() + " Persisted ", "");
|
||||
|
||||
}
|
||||
|
||||
// the method persists
|
||||
@Override
|
||||
@Transactional
|
||||
public ReturnStatus setThePasswordForSipEndpoint(PsAuths psAuths) {
|
||||
|
||||
//check if endpoint exists
|
||||
try{
|
||||
System.out.println("End point ID is " + findEndPontById(psAuths.getId()));
|
||||
}catch (Exception e){
|
||||
return new ReturnStatus(false, "Create Endpoint for " + findEndPontById(psAuths.getId()),e.toString() + " First");
|
||||
}
|
||||
|
||||
this.entityManager.persist(psAuths);
|
||||
return new ReturnStatus(true, psAuths.getId() + " Persisted ", "");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.example.cezenPBX.DAO;
|
||||
|
||||
import com.example.cezenPBX.DTO.ReturnStatus;
|
||||
import com.example.cezenPBX.entity.ExtensionsTable;
|
||||
import com.example.cezenPBX.entity.PsAuths;
|
||||
import com.example.cezenPBX.entity.PsEndPoints;
|
||||
|
||||
public interface CezenPbxOpsDAO {
|
||||
@ -11,4 +12,6 @@ public interface CezenPbxOpsDAO {
|
||||
boolean addNewEndPoint(PsEndPoints psEndPoints);
|
||||
|
||||
ReturnStatus saveAnExtension(ExtensionsTable extensionsTable);
|
||||
|
||||
ReturnStatus setThePasswordForSipEndpoint(PsAuths psAuths);
|
||||
}
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
package com.example.cezenPBX.DTO;
|
||||
|
||||
public record SipPasswordDTO(String id, String authType, String userName, String password, String md5Cred, String realm) {
|
||||
}
|
||||
@ -1,8 +1,8 @@
|
||||
package com.example.cezenPBX.controller;
|
||||
|
||||
import com.example.cezenPBX.DTO.ExtensionsDTO;
|
||||
import com.example.cezenPBX.DTO.PsEndPointsDTO;
|
||||
import com.example.cezenPBX.DTO.ReturnStatus;
|
||||
import com.example.cezenPBX.DTO.SipPasswordDTO;
|
||||
import com.example.cezenPBX.service.BasicPbxServiceInterface;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@ -54,4 +54,18 @@ public class CezenPbxController {
|
||||
extensionsDTO.app(),
|
||||
extensionsDTO.appdata());
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/set_password")
|
||||
public ReturnStatus setPasswordForSipEndpoint(@RequestBody SipPasswordDTO sipPasswordDTO){
|
||||
|
||||
return this.basicPbxServiceInterface.addAPasswordForEndpoint(
|
||||
sipPasswordDTO.id(),
|
||||
sipPasswordDTO.authType(),
|
||||
sipPasswordDTO.userName(),
|
||||
sipPasswordDTO.password(),
|
||||
sipPasswordDTO.md5Cred(),
|
||||
sipPasswordDTO.realm()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,22 +10,22 @@ public class ExtensionsTable {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
int id;
|
||||
private int id;
|
||||
|
||||
@Column(name = "context")
|
||||
String context;
|
||||
private String context;
|
||||
|
||||
@Column(name = "exten")
|
||||
String extension;
|
||||
private String extension;
|
||||
|
||||
@Column(name = "priority")
|
||||
int priority;
|
||||
private int priority;
|
||||
|
||||
@Column(name = "app")
|
||||
String app;
|
||||
private String app;
|
||||
|
||||
@Column(name = "appdata")
|
||||
String appdata;
|
||||
private String appdata;
|
||||
|
||||
public ExtensionsTable(){}
|
||||
|
||||
|
||||
@ -0,0 +1,88 @@
|
||||
package com.example.cezenPBX.entity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@Table(name = "ps_auths")
|
||||
@Entity
|
||||
public class PsAuths {
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
private String id;
|
||||
|
||||
@Column(name = "auth_type")
|
||||
private String authType;
|
||||
|
||||
@Column(name = "username")
|
||||
private String userName;
|
||||
|
||||
@Column(name = "password")
|
||||
private String password;
|
||||
|
||||
@Column(name = "md5_cred")
|
||||
private String md5Cred;
|
||||
|
||||
@Column(name = "realm")
|
||||
private String realm;
|
||||
|
||||
|
||||
public PsAuths(String id, String authType, String userName, String password, String md5Cred, String realm) {
|
||||
this.id = id;
|
||||
this.authType = authType;
|
||||
this.userName = userName;
|
||||
this.password = password;
|
||||
this.md5Cred = md5Cred;
|
||||
this.realm = realm;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getAuthType() {
|
||||
return authType;
|
||||
}
|
||||
|
||||
public void setAuthType(String authType) {
|
||||
this.authType = authType;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getMd5Cred() {
|
||||
return md5Cred;
|
||||
}
|
||||
|
||||
public void setMd5Cred(String md5Cred) {
|
||||
this.md5Cred = md5Cred;
|
||||
}
|
||||
|
||||
public String getRealm() {
|
||||
return realm;
|
||||
}
|
||||
|
||||
public void setRealm(String realm) {
|
||||
this.realm = realm;
|
||||
}
|
||||
}
|
||||
@ -11,43 +11,43 @@ public class PsEndPoints {
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
String id;
|
||||
private String id;
|
||||
|
||||
@Column(name = "transport")
|
||||
String transport;
|
||||
private String transport;
|
||||
|
||||
@Column(name = "aors")
|
||||
String aors;
|
||||
private String aors;
|
||||
|
||||
@Column(name = "auth")
|
||||
String auth;
|
||||
private String auth;
|
||||
|
||||
@Column(name = "context")
|
||||
String context;
|
||||
private String context;
|
||||
|
||||
@Column(name = "disallow")
|
||||
String disallow;
|
||||
private String disallow;
|
||||
|
||||
@Column(name = "allow")
|
||||
String allow;
|
||||
private String allow;
|
||||
|
||||
@Column(name = "direct_media")
|
||||
String directMedia;
|
||||
private String directMedia;
|
||||
|
||||
@Column(name = "connected_line_method")
|
||||
String connectedLineMethod;
|
||||
private String connectedLineMethod;
|
||||
|
||||
@Column(name = "callerid")
|
||||
String callerid;
|
||||
private String callerid;
|
||||
|
||||
@Column(name = "dtmf_mode")
|
||||
String dtmfMode;
|
||||
private String dtmfMode;
|
||||
|
||||
@Column(name = "mohsuggest")
|
||||
String mohsuggest;
|
||||
private String mohsuggest;
|
||||
|
||||
@Column(name = "mailboxes")
|
||||
String mailboxes;
|
||||
private String mailboxes;
|
||||
|
||||
public PsEndPoints(String id, String transport, String aors, String auth, String context,
|
||||
String disallow, String allow, String directMedia, String connectedLineMethod,
|
||||
|
||||
@ -3,6 +3,7 @@ package com.example.cezenPBX.service;
|
||||
import com.example.cezenPBX.DAO.CezenPbxOpsDAO;
|
||||
import com.example.cezenPBX.DTO.ReturnStatus;
|
||||
import com.example.cezenPBX.entity.ExtensionsTable;
|
||||
import com.example.cezenPBX.entity.PsAuths;
|
||||
import com.example.cezenPBX.entity.PsEndPoints;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -53,17 +54,31 @@ public class BasicPbxService implements BasicPbxServiceInterface {
|
||||
|
||||
try{
|
||||
// create a new entity of extension
|
||||
this.cezenPbxOpsDAO.saveAnExtension(new ExtensionsTable(
|
||||
return this.cezenPbxOpsDAO.saveAnExtension(new ExtensionsTable(
|
||||
context,
|
||||
extension,
|
||||
priority,
|
||||
app,
|
||||
appdata
|
||||
));
|
||||
return new ReturnStatus(true, extension + " Persisted ", "");
|
||||
}catch ( Exception e){
|
||||
// the persisting data already exists or it's a db issue
|
||||
return new ReturnStatus(false, "Data likely already exists or DB issue",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnStatus addAPasswordForEndpoint(String id, String authType, String userName, String password, String md5Cred, String realm) {
|
||||
|
||||
// create the new endpoint password instance
|
||||
PsAuths psAuths = new PsAuths(id, authType, userName, password, md5Cred, realm);
|
||||
|
||||
// send it to the DAO
|
||||
try{
|
||||
return this.cezenPbxOpsDAO.setThePasswordForSipEndpoint(psAuths);
|
||||
|
||||
}catch(Exception e){
|
||||
return new ReturnStatus(false, "Endpoint and password already set ",e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,4 +12,6 @@ public interface BasicPbxServiceInterface {
|
||||
|
||||
// provided the user exists returns message of error or status
|
||||
public ReturnStatus addExtensionForUser(String context, String extension, int priority, String app, String appdata);
|
||||
|
||||
public ReturnStatus addAPasswordForEndpoint(String id, String authType, String userName, String password, String md5Cred, String realm);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user