]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/SecurityAPI.js
1 qx
.Class
.define("org.argeo.security.ria.SecurityAPI", {
2 extend
: qx
.core
.Object
,
5 DEFAULT_CONTEXT
: "/org.argeo.security.webapp",
7 CREDENTIALS_SERVICE
: "getCredentials.security",
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",
18 ROLES_LIST_SERVICE
: "getRolesList.security",
19 CREATE_ROLE_SERVICE
: "createRole.security",
20 DELETE_ROLE_SERVICE
: "deleteRole.security",
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}
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
,
39 * @param {qx.io.remote.Request} request
40 * @param {Array} argumentsArray
41 * @param {Integer} startIndex
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();
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
);
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);
73 * @return {qx.io.remote.Request}
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));
83 * @return {qx.io.remote.Request}
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
);
93 * @return {qx.io.remote.Request}
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
);
103 * @return {qx.io.remote.Request}
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
);
115 * @return {qx.io.remote.Request}
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
);
125 * @return {qx.io.remote.Request}
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
);
137 * @return {qx.io.remote.Request}
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
);
148 * @return {qx.io.remote.Request}
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
);
159 * @return {qx.io.remote.Request}
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);
168 * @return {qx.io.remote.Request}
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
);
178 * @return {qx.io.remote.Request}
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
);