]> git.argeo.org Git - lgpl/argeo-commons.git/blob - ria/SecurityAPI.js
Prepare next development cycle
[lgpl/argeo-commons.git] / ria / SecurityAPI.js
1 qx.Class.define("org.argeo.security.ria.SecurityAPI", {
2 extend : qx.core.Object,
3 statics : {
4
5 DEFAULT_CONTEXT : "/org.argeo.security.webapp",
6
7 CREDENTIALS_SERVICE : "getCredentials.security",
8
9 USERS_LIST_SERVICE : "getUsersList.security",
10 USER_EXISTS_SERVICE : "userExists.security",
11 DELETE_USER_SERVICE : "deleteUser.security",
12 UPDATE_USER_SERVICE : "updateUser.security",
13 GET_USER_DETAILS_SERVICE : "getUserDetails.security",
14 CREATE_USER_SERVICE : "createUser.security",
15 UPDATE_USER_PASS_SERVICE : "updateUserPassword.security",
16 UPDATE_PASS_SERVICE : "updatePassword.security",
17
18 ROLES_LIST_SERVICE : "getRolesList.security",
19 CREATE_ROLE_SERVICE : "createRole.security",
20 DELETE_ROLE_SERVICE : "deleteRole.security",
21
22 /**
23 * Standard Request getter
24 * @param serviceName {String} The name of the service to call (without base context)
25 * @param fireReloadEventType {String} Whether query should trigger a ReloadEvent
26 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
27 * @return {qx.io.remote.Request}
28 */
29 getServiceRequest : function(serviceName) {
30 var serviceManager = org.argeo.ria.remote.RequestManager.getInstance();
31 return serviceManager.getRequest(
32 org.argeo.security.ria.SecurityAPI.DEFAULT_CONTEXT + "/" + serviceName,
33 "GET",
34 "application/json");
35 },
36
37 /**
38 *
39 * @param {qx.io.remote.Request} request
40 * @param {Array} argumentsArray
41 * @param {Integer} startIndex
42 */
43 parseOptionalArguments : function(request, argumentsArray, startIndex){
44 // Attach Error listener
45 request.addListener("completed", function(response){
46 var jSonContent = response.getContent();
47 if(typeof jSonContent == "object" && jSonContent.status && jSonContent.status == "ERROR"){
48 org.argeo.ria.components.Logger.getInstance().error(jSonContent.message);
49 response.getTarget().abort();
50 }
51 });
52
53 // Attach ILoadStatusables & reloadEvents
54 if(argumentsArray.length <= startIndex) return;
55 var serviceManager = org.argeo.ria.remote.RequestManager.getInstance();
56 for(var i=startIndex;i<argumentsArray.length;i++){
57 var argument = argumentsArray[i];
58 if(qx.lang.Array.isArray(argument)){
59 serviceManager.attachILoadStatusables(request, argument);
60 }else if(typeof argument == "string"){
61 serviceManager.attachReloadEventType(request, argument);
62 }
63 }
64 },
65
66 getCredentialsService : function(){
67 var req = org.argeo.security.ria.SecurityAPI.getServiceRequest(org.argeo.security.ria.SecurityAPI.CREDENTIALS_SERVICE);
68 org.argeo.security.ria.SecurityAPI.parseOptionalArguments(req, arguments, 0);
69 return req;
70 },
71
72 /**
73 * @return {qx.io.remote.Request}
74 */
75 getListUsersService : function(getNatures){
76 var req = org.argeo.security.ria.SecurityAPI.getServiceRequest(org.argeo.security.ria.SecurityAPI.USERS_LIST_SERVICE);
77 org.argeo.security.ria.SecurityAPI.parseOptionalArguments(req, arguments, 1);
78 req.setParameter("getNatures", (getNatures || false));
79 return req;
80 },
81
82 /**
83 * @return {qx.io.remote.Request}
84 */
85 getUserExistsService : function(userName){
86 var req = org.argeo.security.ria.SecurityAPI.getServiceRequest(org.argeo.security.ria.SecurityAPI.USER_EXISTS_SERVICE);
87 org.argeo.security.ria.SecurityAPI.parseOptionalArguments(req, arguments, 1);
88 req.setParameter("username", userName);
89 return req;
90 },
91
92 /**
93 * @return {qx.io.remote.Request}
94 */
95 getDeleteUserService : function(userName){
96 var req = org.argeo.security.ria.SecurityAPI.getServiceRequest(org.argeo.security.ria.SecurityAPI.DELETE_USER_SERVICE);
97 org.argeo.security.ria.SecurityAPI.parseOptionalArguments(req, arguments, 1);
98 req.setParameter("username", userName);
99 return req;
100 },
101
102 /**
103 * @return {qx.io.remote.Request}
104 */
105 getUpdateUserService : function(userObject){
106 var req = org.argeo.security.ria.SecurityAPI.getServiceRequest(org.argeo.security.ria.SecurityAPI.UPDATE_USER_SERVICE);
107 req.setMethod("POST");
108 org.argeo.security.ria.SecurityAPI.parseOptionalArguments(req, arguments, 1);
109 var jsonString = qx.util.Json.stringify(userObject);
110 req.setData(jsonString);
111 return req;
112 },
113
114 /**
115 * @return {qx.io.remote.Request}
116 */
117 getUserDetailsService : function(userName){
118 var req = org.argeo.security.ria.SecurityAPI.getServiceRequest(org.argeo.security.ria.SecurityAPI.GET_USER_DETAILS_SERVICE);
119 org.argeo.security.ria.SecurityAPI.parseOptionalArguments(req, arguments, 1);
120 req.setParameter("username", userName);
121 return req;
122 },
123
124 /**
125 * @return {qx.io.remote.Request}
126 */
127 getCreateUserService : function(userObject){
128 var req = org.argeo.security.ria.SecurityAPI.getServiceRequest(org.argeo.security.ria.SecurityAPI.CREATE_USER_SERVICE);
129 req.setMethod("POST");
130 org.argeo.security.ria.SecurityAPI.parseOptionalArguments(req, arguments, 1);
131 var jsonString = qx.util.Json.stringify(userObject);
132 req.setData(jsonString);
133 return req;
134 },
135
136 /**
137 * @return {qx.io.remote.Request}
138 */
139 getUpdatePassService : function(oldPassword, newPassword){
140 var req = org.argeo.security.ria.SecurityAPI.getServiceRequest(org.argeo.security.ria.SecurityAPI.UPDATE_USER_PASS_SERVICE);
141 org.argeo.security.ria.SecurityAPI.parseOptionalArguments(req, arguments, 2);
142 req.setParameter("password", newPassword);
143 req.setParameter("oldpassword", oldPassword);
144 return req;
145 },
146
147 /**
148 * @return {qx.io.remote.Request}
149 */
150 getUpdateUserPassService : function(userName, userPassword){
151 var req = org.argeo.security.ria.SecurityAPI.getServiceRequest(org.argeo.security.ria.SecurityAPI.UPDATE_USER_PASS_SERVICE);
152 org.argeo.security.ria.SecurityAPI.parseOptionalArguments(req, arguments, 2);
153 req.setParameter("username", userName);
154 req.setParameter("password", userPassword);
155 return req;
156 },
157
158 /**
159 * @return {qx.io.remote.Request}
160 */
161 getListRolesService : function(){
162 var req = org.argeo.security.ria.SecurityAPI.getServiceRequest(org.argeo.security.ria.SecurityAPI.ROLES_LIST_SERVICE);
163 org.argeo.security.ria.SecurityAPI.parseOptionalArguments(req, arguments, 0);
164 return req;
165 },
166
167 /**
168 * @return {qx.io.remote.Request}
169 */
170 getCreateRoleService : function(roleName){
171 var req = org.argeo.security.ria.SecurityAPI.getServiceRequest(org.argeo.security.ria.SecurityAPI.CREATE_ROLE_SERVICE);
172 org.argeo.security.ria.SecurityAPI.parseOptionalArguments(req, arguments, 1);
173 req.setParameter("role", roleName);
174 return req;
175 },
176
177 /**
178 * @return {qx.io.remote.Request}
179 */
180 getDeleteRoleService : function(roleName){
181 var req = org.argeo.security.ria.SecurityAPI.getServiceRequest(org.argeo.security.ria.SecurityAPI.DELETE_ROLE_SERVICE);
182 org.argeo.security.ria.SecurityAPI.parseOptionalArguments(req, arguments, 1);
183 req.setParameter("role", roleName);
184 return req;
185 }
186 }
187 });