Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
GLPI
java-library-glpi
Commits
80242a37
Commit
80242a37
authored
Nov 30, 2018
by
Ivan Del Pino
Committed by
Rafael Jesus Hernández Vasquez
Dec 03, 2018
Browse files
feat(routes): added full session, pluginFlyve and pluginFlyveID
Signed-off-by:
Ivan Del Pino
<
idelpino@teclib.com
>
parent
f5be9d34
Changes
4
Hide whitespace changes
Inline
Side-by-side
example/src/main/java/org/glpi/glpiproject/ExampleData.java
View file @
80242a37
...
...
@@ -9,6 +9,8 @@ public class ExampleData {
private
String
url
;
private
String
userToken
;
private
String
website
;
private
String
sessionToken
;
private
String
agentID
;
public
String
getEmail
()
{
return
email
;
...
...
@@ -65,4 +67,20 @@ public class ExampleData {
public
void
setWebsite
(
String
website
)
{
this
.
website
=
website
;
}
public
void
setSessionToken
(
String
sessionToken
)
{
this
.
sessionToken
=
sessionToken
;
}
public
String
getSessionToken
()
{
return
sessionToken
;
}
public
void
setAgentID
(
String
agentID
)
{
this
.
agentID
=
agentID
;
}
public
String
getAgentID
()
{
return
agentID
;
}
}
example/src/main/java/org/glpi/glpiproject/MainActivity.java
View file @
80242a37
...
...
@@ -46,6 +46,8 @@ import org.glpi.api.GLPI;
import
org.glpi.api.itemType
;
import
org.glpi.api.response.FullSessionModel
;
import
org.glpi.api.response.InitSession
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -59,6 +61,7 @@ public class MainActivity extends AppCompatActivity {
private
ExampleData
data
;
private
ProgressBar
progressBar
;
private
RecyclerView
recyclerView
;
private
GLPI
.
GLPIModel
glpiModel
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
...
@@ -84,6 +87,7 @@ public class MainActivity extends AppCompatActivity {
Logger
.
addLogAdapter
(
new
AndroidLogAdapter
(
formatStrategy
));
glpi
=
new
GLPI
(
MainActivity
.
this
,
data
.
getUrl
());
glpiModel
=
glpi
.
new
GLPIModel
();
progressBar
=
findViewById
(
R
.
id
.
progressBar
);
...
...
@@ -96,6 +100,7 @@ public class MainActivity extends AppCompatActivity {
spinnerTest
=
findViewById
(
R
.
id
.
spinnerTest
);
ArrayList
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
"Init Session"
);
list
.
add
(
"Full Session"
);
list
.
add
(
"Kill session"
);
list
.
add
(
"Call Request"
);
ArrayAdapter
<
String
>
adapter
=
new
ArrayAdapter
<>(
this
,
R
.
layout
.
spinner_item
,
list
);
...
...
@@ -110,6 +115,13 @@ public class MainActivity extends AppCompatActivity {
case
"Init Session"
:
btnInit
();
break
;
case
"Full Session"
:
try
{
btnSession
();
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
break
;
case
"Kill session"
:
btnKill
();
break
;
...
...
@@ -149,6 +161,7 @@ public class MainActivity extends AppCompatActivity {
glpi
.
initSessionByUserToken
(
data
.
getUserToken
(),
new
GLPI
.
ResponseHandle
<
InitSession
,
String
>()
{
@Override
public
void
onResponse
(
InitSession
response
)
{
data
.
setSessionToken
(
response
.
getSessionToken
());
updateAdapter
(
"Success: Init Session User Token"
);
}
...
...
@@ -159,20 +172,11 @@ public class MainActivity extends AppCompatActivity {
});
String
token
=
glpi
.
initSessionByCredentialsSync
(
BuildConfig
.
GLPI_USER
,
BuildConfig
.
GLPI_PASSWORD
);
FlyveLog
.
i
(
"initSession: %s"
,
token
);
updateAdapter
(
"Success: Init Session Credentials"
);
glpi
.
fullSession
(
new
GLPI
.
ResponseHandle
<
FullSessionModel
,
String
>()
{
@Override
public
void
onResponse
(
FullSessionModel
response
)
{
FlyveLog
.
i
(
"Full Session: %s"
,
response
.
toString
());
updateAdapter
(
"Success: Full Session"
);
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
FlyveLog
.
i
(
"Full Session: %s"
,
errorMessage
);
updateAdapter
(
"Error: Full Session"
);
}
});
if
(
""
.
equalsIgnoreCase
(
token
))
{
updateAdapter
(
"Error: Synchronous Init Session Credentials, Token Empty"
);
}
else
{
updateAdapter
(
"Success: Synchronous Init Session Credentials"
);
}
GLPI
.
ResponseHandle
<
InitSession
,
String
>
handle
=
new
GLPI
.
ResponseHandle
<
InitSession
,
String
>()
{
@Override
public
void
onResponse
(
InitSession
response
)
{
...
...
@@ -192,9 +196,75 @@ public class MainActivity extends AppCompatActivity {
glpi
.
initSessionByCredentials
(
BuildConfig
.
GLPI_USER
,
BuildConfig
.
GLPI_PASSWORD
,
handle
);
}
private
void
btnSession
()
throws
JSONException
{
progressBar
.
setVisibility
(
View
.
VISIBLE
);
resultList
.
clear
();
JSONObject
payload
=
new
JSONObject
();
payload
.
put
(
"_email"
,
"Test@gmail.com"
);
payload
.
put
(
"_invitation_token"
,
""
);
payload
.
put
(
"_serial"
,
""
);
payload
.
put
(
"_uuid"
,
""
);
payload
.
put
(
"csr"
,
""
);
payload
.
put
(
"firstname"
,
"Test"
);
payload
.
put
(
"lastname"
,
"Testing"
);
payload
.
put
(
"phone"
,
""
);
payload
.
put
(
"version"
,
BuildConfig
.
VERSION_NAME
);
payload
.
put
(
"type"
,
"android"
);
payload
.
put
(
"has_system_permission"
,
""
);
payload
.
put
(
"inventory"
,
""
);
JSONObject
input
=
new
JSONObject
();
input
.
put
(
"input"
,
payload
);
glpi
.
getPluginFlyve
(
data
.
getSessionToken
(),
input
,
new
GLPI
.
ResponseHandle
<
JsonObject
,
String
>()
{
@Override
public
void
onResponse
(
JsonObject
response
)
{
FlyveLog
.
i
(
"Plugin Flyve: %s"
,
response
.
toString
());
data
.
setAgentID
(
response
.
toString
());
updateAdapter
(
"Success: Plugin Flyve"
);
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
FlyveLog
.
i
(
"Plugin Flyve: %s"
,
errorMessage
);
updateAdapter
(
"Error: Plugin Flyve"
+
errorMessage
);
}
});
glpi
.
fullSession
(
data
.
getSessionToken
(),
new
GLPI
.
ResponseHandle
<
FullSessionModel
,
String
>()
{
@Override
public
void
onResponse
(
FullSessionModel
response
)
{
FlyveLog
.
i
(
"Full Session: %s"
,
response
.
toString
());
glpiModel
.
setProfileId
(
response
.
getSession
().
getPluginFlyvemdmGuestProfilesId
());
updateAdapter
(
"Success: Full Session"
);
progressBar
.
setVisibility
(
View
.
GONE
);
recyclerView
.
setVisibility
(
View
.
VISIBLE
);
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
FlyveLog
.
i
(
"Full Session: %s"
,
errorMessage
);
updateAdapter
(
"Error: Full Session"
+
errorMessage
);
progressBar
.
setVisibility
(
View
.
GONE
);
recyclerView
.
setVisibility
(
View
.
VISIBLE
);
}
});
}
private
void
btnCall
()
{
progressBar
.
setVisibility
(
View
.
VISIBLE
);
resultList
.
clear
();
glpi
.
getPluginFlyveAgentID
(
data
.
getSessionToken
(),
data
.
getAgentID
(),
new
GLPI
.
ResponseHandle
<
JsonObject
,
String
>()
{
@Override
public
void
onResponse
(
JsonObject
response
)
{
FlyveLog
.
i
(
"Plugin Flyve Agent: %s"
,
response
);
updateAdapter
(
"Success: Plugin Flyve Agent"
);
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
FlyveLog
.
i
(
"Plugin Flyve Agent: %s"
,
errorMessage
);
updateAdapter
(
"Error: Plugin Flyve Agent"
+
errorMessage
);
}
});
glpi
.
getMyProfiles
(
new
GLPI
.
ResponseHandle
<
JsonObject
,
String
>()
{
@Override
public
void
onResponse
(
JsonObject
response
)
{
...
...
@@ -251,20 +321,6 @@ public class MainActivity extends AppCompatActivity {
}
});
glpi
.
getFullSession
(
new
GLPI
.
ResponseHandle
<
JsonObject
,
String
>()
{
@Override
public
void
onResponse
(
JsonObject
response
)
{
FlyveLog
.
i
(
"getFullSession: %s"
,
response
.
toString
());
updateAdapter
(
"Success: Full Session"
);
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
FlyveLog
.
e
(
"getFullSession: %s"
,
errorMessage
);
updateAdapter
(
"Error: Full Session"
);
}
});
glpi
.
getGlpiConfig
(
new
GLPI
.
ResponseHandle
<
JsonObject
,
String
>()
{
@Override
public
void
onResponse
(
JsonObject
response
)
{
...
...
@@ -322,7 +378,7 @@ public class MainActivity extends AppCompatActivity {
};
glpi
.
getSubItems
(
itemType
.
Computer
,
"2"
,
itemType
.
ComputerType
,
responseHandle
);
glpi
.
changeActiveProfile
(
"9"
,
new
GLPI
.
ResponseHandle
<
String
,
String
>()
{
glpi
.
changeActiveProfile
(
glpiModel
.
getProfileId
()
,
new
GLPI
.
ResponseHandle
<
String
,
String
>()
{
@Override
public
void
onResponse
(
String
response
)
{
FlyveLog
.
i
(
"changeActiveProfile: %s"
,
response
);
...
...
glpi/src/main/java/org/glpi/api/GLPI.java
View file @
80242a37
...
...
@@ -42,6 +42,7 @@ import org.glpi.api.request.ResetPasswordRequest;
import
org.glpi.api.response.FullSessionModel
;
import
org.glpi.api.response.InitSession
;
import
org.glpi.api.utils.Helpers
;
import
org.json.JSONObject
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -113,14 +114,14 @@ public class GLPI extends ServiceGenerator {
responseInitSession
(
callback
,
interfaces
.
initSessionByCredentials
(
"Basic "
+
authorization
.
trim
()));
}
public
void
fullSession
(
final
ResponseHandle
<
FullSessionModel
,
String
>
callback
)
{
public
void
fullSession
(
String
userToken
,
final
ResponseHandle
<
FullSessionModel
,
String
>
callback
)
{
HashMap
<
String
,
String
>
header
=
new
HashMap
<>();
header
.
put
(
"Session-Token"
,
se
ssion
Token
);
header
.
put
(
"Session-Token"
,
u
se
r
Token
);
header
.
put
(
"Accept"
,
"application/json"
);
header
.
put
(
"Content-Type"
,
"application/json"
+
";"
+
"charset=UTF-8"
);
header
.
put
(
"User-Agent"
,
"Flyve MDM"
);
header
.
put
(
"Referer"
,
"/getFullSession"
);
interfaces
.
f
ullSession
(
header
).
enqueue
(
new
Callback
<
FullSessionModel
>()
{
interfaces
.
getF
ullSession
(
header
).
enqueue
(
new
Callback
<
FullSessionModel
>()
{
@Override
public
void
onResponse
(
@NonNull
Call
<
FullSessionModel
>
call
,
@NonNull
Response
<
FullSessionModel
>
response
)
{
if
(
response
.
isSuccessful
())
{
...
...
@@ -193,6 +194,35 @@ public class GLPI extends ServiceGenerator {
responseJsonObject
(
callback
,
interfaces
.
getMyProfiles
(
getHeader
()));
}
/**
* Return the current active profile.
*
* @param data
* @param callback here you are going to get the asynchronous response
*/
public
void
getPluginFlyve
(
String
sessionToken
,
JSONObject
data
,
final
ResponseHandle
<
JsonObject
,
String
>
callback
)
{
HashMap
<
String
,
String
>
header
=
new
HashMap
<>();
header
.
put
(
"Session-Token"
,
sessionToken
);
header
.
put
(
"Accept"
,
"application/json"
);
header
.
put
(
"Content-Type"
,
"application/json"
+
";"
+
"charset=UTF-8"
);
responseJsonObject
(
callback
,
interfaces
.
getPluginFlyve
(
header
,
data
));
}
/**
* Return the current active profile.
*
* @param callback here you are going to get the asynchronous response
*/
public
void
getPluginFlyveAgentID
(
String
sessionToken
,
String
agentID
,
final
ResponseHandle
<
JsonObject
,
String
>
callback
)
{
HashMap
<
String
,
String
>
header
=
new
HashMap
<>();
header
.
put
(
"Session-Token"
,
sessionToken
);
header
.
put
(
"Accept"
,
"application/json"
);
header
.
put
(
"Content-Type"
,
"application/json"
+
";"
+
"charset=UTF-8"
);
header
.
put
(
"User-Agent"
,
"Flyve MDM"
);
header
.
put
(
"Referer"
,
"/getFullSession"
);
responseJsonObject
(
callback
,
interfaces
.
getPluginFlyveAgentID
(
header
,
agentID
));
}
/**
* Return the current active profile.
*
...
...
@@ -220,15 +250,6 @@ public class GLPI extends ServiceGenerator {
responseJsonObject
(
callback
,
interfaces
.
getActiveEntities
(
getHeader
()));
}
/**
* Return the current php $_SESSION.
*
* @param callback here you are going to get the asynchronous response
*/
public
void
getFullSession
(
final
ResponseHandle
<
JsonObject
,
String
>
callback
)
{
responseJsonObject
(
callback
,
interfaces
.
getFullSession
(
getHeader
()));
}
/**
* Return the current $CFG_GLPI.
*
...
...
@@ -406,7 +427,7 @@ public class GLPI extends ServiceGenerator {
public
void
changeActiveProfile
(
String
profilesId
,
final
ResponseHandle
<
String
,
String
>
callback
)
{
ChangeActiveProfileRequest
requestPost
=
new
ChangeActiveProfileRequest
(
profilesId
);
int
message
=
R
.
string
.
change_active_profile_success
;
responseVoid
(
callback
,
interfaces
.
changeActiveProfile
(
getHeader
(),
requestPost
),
message
);
responseVoid
(
callback
,
interfaces
.
changeActiveProfile
(
getHeader
(),
profilesId
,
requestPost
),
message
);
}
/**
...
...
@@ -512,11 +533,16 @@ public class GLPI extends ServiceGenerator {
/**
* Interface definition for a callback to be invoked when an endpoint return void.
*/
public
interface
FullSessionCallback
{
void
onResponse
(
FullSessionModel
response
)
;
public
class
GLPIModel
{
private
String
profileId
;
void
onFailure
(
String
errorMessage
);
}
public
String
getProfileId
()
{
return
profileId
;
}
public
void
setProfileId
(
String
profileId
)
{
this
.
profileId
=
profileId
;
}
}
}
glpi/src/main/java/org/glpi/api/Routes.java
View file @
80242a37
...
...
@@ -34,6 +34,7 @@ import org.glpi.api.request.RecoveryPasswordRequest;
import
org.glpi.api.request.ResetPasswordRequest
;
import
org.glpi.api.response.FullSessionModel
;
import
org.glpi.api.response.InitSession
;
import
org.json.JSONObject
;
import
java.util.Map
;
...
...
@@ -62,7 +63,15 @@ public interface Routes {
@Headers
(
"Content-Type: application/json"
)
@GET
(
"getFullSession"
)
Call
<
FullSessionModel
>
fullSession
(
@HeaderMap
Map
<
String
,
String
>
headers
);
Call
<
FullSessionModel
>
getFullSession
(
@HeaderMap
Map
<
String
,
String
>
headers
);
@Headers
(
"Content-Type: application/json"
)
@POST
(
"PluginFlyvemdmAgent"
)
Call
<
JsonObject
>
getPluginFlyve
(
@HeaderMap
Map
<
String
,
String
>
headers
,
@Body
JSONObject
data
);
@Headers
(
"Content-Type: application/json"
)
@GET
(
"PluginFlyvemdmAgent/{agentId}"
)
Call
<
JsonObject
>
getPluginFlyveAgentID
(
@HeaderMap
Map
<
String
,
String
>
headers
,
@Path
(
"agentId"
)
String
agentId
);
@Headers
(
"Content-Type: application/json"
)
@GET
(
"killSession"
)
...
...
@@ -84,10 +93,6 @@ public interface Routes {
@GET
(
"getActiveEntities"
)
Call
<
JsonObject
>
getActiveEntities
(
@HeaderMap
Map
<
String
,
String
>
headers
);
@Headers
(
"Content-Type: application/json"
)
@GET
(
"getFullSession"
)
Call
<
JsonObject
>
getFullSession
(
@HeaderMap
Map
<
String
,
String
>
headers
);
@Headers
(
"Content-Type: application/json"
)
@GET
(
"getGlpiConfig"
)
Call
<
JsonObject
>
getGlpiConfig
(
@HeaderMap
Map
<
String
,
String
>
headers
);
...
...
@@ -106,7 +111,7 @@ public interface Routes {
@Headers
(
"Content-Type: application/json"
)
@POST
(
"changeActiveProfile"
)
Call
<
Void
>
changeActiveProfile
(
@HeaderMap
Map
<
String
,
String
>
headers
,
@Body
ChangeActiveProfileRequest
requestPost
);
Call
<
Void
>
changeActiveProfile
(
@HeaderMap
Map
<
String
,
String
>
headers
,
@Query
(
"profiles_id"
)
String
profileId
,
@Body
ChangeActiveProfileRequest
requestPost
);
@Headers
(
"Content-Type: application/json"
)
@POST
(
"changeActiveEntities"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment