add login

pull/5/head
Felix Prahl-Kamps 2019-07-05 03:45:04 +02:00
parent 5240ad3fe3
commit 7a53d5c6d5
17 changed files with 101 additions and 46 deletions

View File

@ -1,14 +1,17 @@
# Screenshots
## Login
![Login](./screenshots/mispbump-login.png)
## Home
Entrypoint of the app.
Actions: **Profile View** (Menubar) and **New Sync** (Floating Action Button)
![Home (Empty)](./screenshots/mispbump-home-0.png)
## Profile
Basic information about the organisation that is currently logged in.
Organisation information loaded automatically from your MISP instance
Actions: **Delete and logout** (Menubar) and **Update Info** (Floating Action Button)
@ -34,7 +37,7 @@ After a successfull exchange an entry for this organisation will appear.
Actions: **Delete Sync information** (Menubar) and **Upload** (Floating Action Button in settings tab)
**Credentials:** With this credentials you will be able to log in on the other MISP instance (SyncUser)
**Credentials:** With these credentials you will be able to log in on the other MISP instance (SyncUser)
![Profile](./screenshots/mispbump-sync-info-credentials.png)

View File

@ -33,6 +33,8 @@ import lu.circl.mispbump.models.restModels.User;
public class LoginActivity extends AppCompatActivity {
private PreferenceManager preferenceManager;
private MispRestClient mispRestClient;
private ConstraintLayout constraintLayout;
private TextInputLayout serverAutomationKey;
private TextInputLayout serverUrl;
@ -42,6 +44,12 @@ public class LoginActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
preferenceManager = PreferenceManager.getInstance(this);
mispRestClient = MispRestClient.getInstance(LoginActivity.this);
getWindow().setStatusBarColor(getColor(R.color.colorPrimary));
initializeViews();
}
@ -62,26 +70,25 @@ public class LoginActivity extends AppCompatActivity {
return super.onOptionsItemSelected(item);
}
private void initializeViews() {
constraintLayout = findViewById(R.id.rootLayout);
// populate Toolbar (Actionbar)
Toolbar myToolbar = findViewById(R.id.appbar);
setSupportActionBar(myToolbar);
ActionBar ab = getSupportActionBar();
if (ab != null) {
ab.setDisplayHomeAsUpEnabled(false);
ab.setDisplayShowTitleEnabled(false);
}
constraintLayout = findViewById(R.id.rootLayout);
Button downloadInfoButton = findViewById(R.id.login_download_button);
downloadInfoButton.setOnClickListener(onClickDownload);
serverUrl = findViewById(R.id.login_server_url);
serverAutomationKey = findViewById(R.id.login_automation_key);
progressBar = findViewById(R.id.login_progressbar);
preferenceManager = PreferenceManager.getInstance(this);
}
/**
@ -91,8 +98,8 @@ public class LoginActivity extends AppCompatActivity {
@Override
public void onClick(View v) {
String url = Objects.requireNonNull(serverUrl.getEditText()).getText().toString();
String authkey = Objects.requireNonNull(serverAutomationKey.getEditText()).getText().toString();
final String url = Objects.requireNonNull(serverUrl.getEditText()).getText().toString();
final String authkey = Objects.requireNonNull(serverAutomationKey.getEditText()).getText().toString();
boolean error = false;
@ -113,14 +120,7 @@ public class LoginActivity extends AppCompatActivity {
return;
}
// save authkey
preferenceManager.setAutomationKey(authkey);
// save url
preferenceManager.setServerUrl(url);
// instance of MispRestClient with given URL
final MispRestClient mispRestClient = MispRestClient.getInstance(getApplicationContext());
mispRestClient.initMispRestInterface(url);
// display progress bar
progressBar.setVisibility(View.VISIBLE);
@ -137,6 +137,13 @@ public class LoginActivity extends AppCompatActivity {
@Override
public void success(Organisation organisation) {
preferenceManager.setUserOrgInfo(organisation);
// save authkey
preferenceManager.setAutomationKey(authkey);
// save url
preferenceManager.setServerUrl(url);
progressBar.setVisibility(View.GONE);
Intent home = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(home);
@ -170,7 +177,7 @@ public class LoginActivity extends AppCompatActivity {
};
/**
* Check if url is valid.
* TODO: Check if url is valid.
*
* @param url url to check
* @return true or false
@ -186,7 +193,7 @@ public class LoginActivity extends AppCompatActivity {
}
/**
* Check if automation key is valid.
* TODO: Check if automation key is valid.
*
* @param automationKey the key to check
* @return true or false

View File

@ -59,26 +59,31 @@ public class MispRestClient {
public interface AllUsersCallback {
void success(User[] users);
void failure(String error);
}
public interface OrganisationCallback {
void success(Organisation organisation);
void failure(String error);
}
public interface AllOrganisationsCallback {
void success(Organisation[] organisations);
void failure(String error);
}
public interface ServerCallback {
void success(Server server);
void failure(String error);
}
public interface AllServersCallback {
void success(Server[] servers);
void failure(String error);
}
@ -97,21 +102,41 @@ public class MispRestClient {
return instance;
}
public static MispRestClient getInstance(Context context, String url) {
if (instance == null) {
instance = new MispRestClient(context, url);
}
return instance;
}
private MispRestClient(Context context) {
this(context, null);
}
/**
* Initializes the rest client to communicate with a MISP instance.
*
* @param context needed to access the preferences for loading credentials
*/
private MispRestClient(Context context) {
private MispRestClient(Context context, String url) {
preferenceManager = PreferenceManager.getInstance(context);
String url = preferenceManager.getServerUrl();
if (url == null) {
url = preferenceManager.getServerUrl();
}
initMispRestInterface(url);
}
public void initMispRestInterface(String url) {
try {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
.client(getCustomClient(true, true))
.client(getCustomClient(true, false))
.build();
mispRestInterface = retrofit.create(MispRestInterface.class);
@ -120,9 +145,9 @@ public class MispRestClient {
}
}
/**
*
* @param unsafe whether to accept all certificates or only trusted ones
* @param unsafe whether to accept all certificates or only trusted ones
* @param logging whether to log Retrofit calls (for debugging)
* @return {@link OkHttpClient}
*/
@ -159,7 +184,7 @@ public class MispRestClient {
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
builder.sslSocketFactory(sslSocketFactory, (X509TrustManager)trustAllCerts[0]);
builder.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0]);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
@ -224,7 +249,6 @@ public class MispRestClient {
}
/**
* Fetches information about the user that is associated with saved auth key.
*
@ -549,8 +573,9 @@ public class MispRestClient {
/**
* Converts error {@link Response}s to human readable info.
*
* @param response erroneous response
* @param <T> type of response
* @param <T> type of response
* @return human readable String that describes the error
*/
private <T> String extractError(Response<T> response) {
@ -603,6 +628,7 @@ public class MispRestClient {
/**
* Converts a {@link Throwable} to a human readable error message.
*
* @param t throwable
* @return human readable String that describes the error.
*/

View File

@ -1,23 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.LoginActivity">
tools:context=".activities.LoginActivity"
android:focusableInTouchMode="true"
android:animateLayoutChanges="true">
<androidx.appcompat.widget.Toolbar
android:id="@+id/appbar"
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:elevation="6dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:theme="@style/ToolbarTheme"
app:popupTheme="@style/PopupTheme"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:text="MISPbump"
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"/>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/login_server_url"
@ -71,13 +92,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="@string/login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/login_automation_key" />
app:layout_constraintTop_toBottomOf="@+id/login_progressbar" />
<ProgressBar
android:id="@+id/login_progressbar"
@ -87,19 +108,17 @@
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/appbar" />
app:layout_constraintTop_toBottomOf="@+id/login_automation_key" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
app:layout_constraintGuide_percent="0.4" />
</androidx.constraintlayout.widget.ConstraintLayout>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 KiB

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 169 KiB

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 MiB

After

Width:  |  Height:  |  Size: 539 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 118 KiB

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 MiB

After

Width:  |  Height:  |  Size: 574 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 119 KiB

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 110 KiB

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 170 KiB

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 115 KiB

After

Width:  |  Height:  |  Size: 55 KiB