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
d98fd039
Unverified
Commit
d98fd039
authored
Oct 24, 2017
by
Rafa Hernandez
Browse files
feat(initsession): add synchronous init session by credentials method
parent
1313763b
Changes
2
Hide whitespace changes
Inline
Side-by-side
glpi/src/androidTest/java/org/flyve/glpi/GLPITest.java
0 → 100644
View file @
d98fd039
package
org.flyve.glpi
;
import
android.content.Context
;
import
android.support.test.InstrumentationRegistry
;
import
android.support.test.runner.AndroidJUnit4
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
static
org
.
junit
.
Assert
.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith
(
AndroidJUnit4
.
class
)
public
class
ExampleInstrumentedTest
{
@Test
public
void
useAppContext
()
throws
Exception
{
// Context of the app under test.
Context
appContext
=
InstrumentationRegistry
.
getTargetContext
();
assertEquals
(
"org.flyve.glpi.test"
,
appContext
.
getPackageName
());
}
}
glpi/src/main/java/org/flyve/glpi/GLPI.java
View file @
d98fd039
...
...
@@ -27,8 +27,10 @@ package org.flyve.glpi;
import
android.content.Context
;
import
android.util.Log
;
import
com.google.gson.JsonArray
;
import
com.google.gson.JsonObject
;
import
org.flyve.glpi.query.GetAllItemQuery
;
import
org.flyve.glpi.query.GetAnItemQuery
;
import
org.flyve.glpi.query.GetSubItemQuery
;
...
...
@@ -38,8 +40,10 @@ import org.flyve.glpi.request.LostPasswordRequest;
import
org.flyve.glpi.request.RecoveryPasswordRequest
;
import
org.flyve.glpi.response.InitSession
;
import
org.flyve.glpi.utils.Helpers
;
import
java.util.HashMap
;
import
java.util.Map
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
...
...
@@ -113,6 +117,24 @@ public class GLPI extends ServiceGenerator {
});
}
/**
* Synchronous Request a session token to uses other api endpoints. with a couple login & password: 2 parameters to login with user authentication
* @param user valid user on GLPI
* @param password valid password on GLPI
* @return SessionToken
*/
public
String
initSessionByCredentialsSync
(
String
user
,
String
password
)
{
String
authorization
=
Helpers
.
base64encode
(
user
+
":"
+
password
);
Call
<
InitSession
>
responseCall
=
interfaces
.
initSessionByCredentials
(
"Basic "
+
authorization
.
trim
());
try
{
return
responseCall
.
execute
().
body
().
getSessionToken
();
}
catch
(
Exception
ex
)
{
return
""
;
}
}
/**
* Request a session token to uses other api endpoints. with a couple login & password: 2 parameters to login with user authentication
* @param user valid user on GLPI
...
...
Write
Preview
Supports
Markdown
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