Commit c2c2c3c2 by Szénási Dániel

initial commit

parents
Pipeline #97 skipped in 0 seconds
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
CircleAndroid2
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<component name="CopyrightManager">
<settings default="" />
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.10" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="myModules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
<component name="masterDetails">
<states>
<state key="ProjectJDKs.UI">
<settings>
<last-edited>1.8</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
</states>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/CircleAndroid2.iml" filepath="$PROJECT_DIR$/CircleAndroid2.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
buildscript {
repositories {
mavenCentral()
maven { url 'https://plugins.gradle.org/m2/' }
maven { url 'http://jcenter.bintray.com/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "hu.bme.dszenasi.circleandroid"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/maven/com.squareup.retrofit/retrofit/pom.properties'
exclude 'META-INF/maven/com.squareup.retrofit/retrofit/pom.xml'
}
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
apt 'com.google.dagger:dagger-compiler:2.0.2'
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.android.support:cardview-v7:23.3.0'
compile 'com.google.dagger:dagger:2.0.2'
provided 'org.glassfish:javax.annotation:10.0-b28'
compile ('com.squareup.retrofit2:retrofit:2.0.2') {
exclude module: 'okhttp'
}
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.2.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0'
compile 'io.reactivex:rxandroid:1.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
compile 'com.squareup.retrofit:converter-jackson:2.0.0-beta2'
}
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
package hu.bme.dszenasi.circleandroid;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="hu.bme.dszenasi.circleandroid">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".login.ui.LoginActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".vmlist.ui.VmListActivity"
android:label="@string/app_name"
/>
<activity
android:name=".managevm.ui.ManageVmActivity"
android:label="@string/app_name"
/>
<activity
android:name=".createvm.ui.CreateVmActivity"
android:label="@string/app_name"
/>
</application>
</manifest>
\ No newline at end of file
package hu.bme.dszenasi.circleandroid;
import android.app.Application;
import android.content.Context;
import android.preference.PreferenceManager;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
/**
* Created by danielszenasi on 05/05/16.
*/
@Module
public class AppModule {
Application mApplication;
public AppModule(Application application) {
mApplication = application;
}
@Provides
@Singleton
Application providesApplication() {
return mApplication;
}
@Provides
@Singleton
Context providesContext() {
return mApplication;
}
}
\ No newline at end of file
package hu.bme.dszenasi.circleandroid;
import android.app.Application;
import hu.bme.dszenasi.circleandroid.createvm.module.CreateVmComponent;
import hu.bme.dszenasi.circleandroid.createvm.module.CreateVmModule;
import hu.bme.dszenasi.circleandroid.createvm.module.DaggerCreateVmComponent;
import hu.bme.dszenasi.circleandroid.login.module.DaggerLoginComponent;
import hu.bme.dszenasi.circleandroid.login.module.LoginComponent;
import hu.bme.dszenasi.circleandroid.login.module.LoginModule;
import hu.bme.dszenasi.circleandroid.managevm.module.DaggerManageVmComponent;
import hu.bme.dszenasi.circleandroid.managevm.module.ManageVmComponent;
import hu.bme.dszenasi.circleandroid.managevm.module.ManageVmModule;
import hu.bme.dszenasi.circleandroid.vmlist.module.DaggerVmListComponent;
import hu.bme.dszenasi.circleandroid.vmlist.module.VmListComponent;
import hu.bme.dszenasi.circleandroid.vmlist.module.VmListModule;
/**
* Created by mszenasi on 2016-04-26.
*/
public class MyApplication extends Application {
LoginComponent logincomponent;
VmListComponent vmListComponent;
ManageVmComponent manageVmComponent;
CreateVmComponent createVmComponent;
@Override
public void onCreate() {
super.onCreate();
logincomponent = DaggerLoginComponent.builder()
.appModule(new AppModule(this))
.loginModule(new LoginModule("https://vm.ik.bme.hu:1415/"))
.build();
vmListComponent = DaggerVmListComponent.builder()
.appModule(new AppModule(this))
.vmListModule(new VmListModule("https://vm.ik.bme.hu:1415/"))
.build();
manageVmComponent = DaggerManageVmComponent.builder()
.appModule(new AppModule(this))
.manageVmModule(new ManageVmModule("https://vm.ik.bme.hu:1415/"))
.build();
createVmComponent = DaggerCreateVmComponent.builder()
.appModule(new AppModule(this))
.createVmModule(new CreateVmModule("https://vm.ik.bme.hu:1415/"))
.build();
}
public LoginComponent getloginComponent() {
return logincomponent;
}
public ManageVmComponent getManageVmComponent() {
return manageVmComponent;
}
public CreateVmComponent getCreateVmComponent() {
return createVmComponent;
}
public VmListComponent getVmListComponent() {
return vmListComponent;
}
}
\ No newline at end of file
package hu.bme.dszenasi.circleandroid.core.api;
import hu.bme.dszenasi.circleandroid.occicore.Action;
import hu.bme.dszenasi.circleandroid.occicore.ActionWithAttributes;
import hu.bme.dszenasi.circleandroid.occicore.CreateVmData;
import hu.bme.dszenasi.circleandroid.occicore.LoginData;
import hu.bme.dszenasi.circleandroid.occicore.OCCIComputeResponse;
import hu.bme.dszenasi.circleandroid.occicore.OCCILoginResponse;
import hu.bme.dszenasi.circleandroid.occicore.Resource;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Path;
/**
* Created by danielszenasi on 03/05/16.
*/
public interface OCCICircleApi {
@GET("/occi/login/")
Call<OCCILoginResponse> loginGet();
@POST("/occi/login/")
Call<OCCILoginResponse> loginPost(@Body LoginData loginData);
@GET("/occi/compute/")
Call<OCCIComputeResponse> allCompute();
@GET("/occi/-/")
Call<OCCILoginResponse> queryInterface();
@DELETE("/occi/compute/{vmid}/")
Call<Resource> deleteCompute(@Path("vmid") int vmid);
@POST("/occi/compute/{vmid}/")
Call<Resource> startCompute(@Path("vmid") int vmid, @Body Action action);
@POST("/occi/compute/{vmid}/")
Call<Resource> startCompute(@Path("vmid") int vmid, @Body ActionWithAttributes action);
@PUT("/occi/compute/{vmid}/")
Call<Resource> createCompute(@Path("vmid") int vmid, @Body CreateVmData data);
}
package hu.bme.dszenasi.circleandroid.core.util;
import android.app.Application;
import android.content.Context;
import android.preference.PreferenceManager;
import android.util.Log;
import java.io.IOException;
import java.util.HashSet;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
/**
* This interceptor put all the Cookies in Preferences in the Request.
* Your implementation on how to get the Preferences MAY VARY.
*/
public class AddCookiesInterceptor implements Interceptor {
public static final String PREF_COOKIES = "PREF_COOKIES";
private Application application;
public AddCookiesInterceptor(Application application) {
this.application = application;
}
@Override
public Response intercept(Chain chain) throws IOException {
Request.Builder builder = chain.request().newBuilder();
String csessidc3c8 = PreferenceManager.getDefaultSharedPreferences(application).getString("csessidc3c8","csessidc3c8isnull");
String csrftoken = PreferenceManager.getDefaultSharedPreferences(application).getString("csrftoken", "csrftokenisnull");
builder.addHeader("Referer", "https://vm.ik.bme.hu:1415/");
if(csrftoken != "csrftokenisnull") {
builder.addHeader("X-CSRFToken", csrftoken);
}
if (csessidc3c8 != "csessidc3c8isnull" && csrftoken != "csrftokenisnull") {
builder.addHeader("Cookie", "csrftoken=" + csrftoken + ";" + "csessidc3c8=" + csessidc3c8);
}
return chain.proceed(builder.build());
}
}
\ No newline at end of file
package hu.bme.dszenasi.circleandroid.core.util;
import java.io.IOException;
import java.lang.annotation.Annotation;
import javax.inject.Inject;
import hu.bme.dszenasi.circleandroid.occicore.OCCILoginResponse;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Response;
import retrofit2.Retrofit;
/**
* Created by danielszenasi on 09/05/16.
*/
public class ErrorUtil {
private Retrofit retrofit;
public ErrorUtil(Retrofit retrofit) {
this.retrofit = retrofit;
}
public OCCILoginResponse parseError(Response<?> response) {
Converter<ResponseBody, OCCILoginResponse> converter =
retrofit.responseBodyConverter(OCCILoginResponse.class, new Annotation[0]);
OCCILoginResponse error;
try {
error = converter.convert(response.errorBody());
} catch (IOException e) {
return new OCCILoginResponse();
}
return error;
}
}
package hu.bme.dszenasi.circleandroid.core.util;
import android.app.Application;
import android.content.Context;
import android.preference.PreferenceManager;
import android.util.Log;
import java.io.IOException;
import java.util.HashSet;
import java.util.prefs.Preferences;
import okhttp3.Interceptor;
import okhttp3.Response;
/**
* Created by danielszenasi on 09/05/16.
*/
public class ReceivedCookiesInterceptor implements Interceptor {
public static final String PREF_COOKIES = "PREF_COOKIES";
private Application application;
public ReceivedCookiesInterceptor(Application application) {
this.application = application;
}
@Override
public Response intercept(Chain chain) throws IOException {
Response originalResponse = chain.proceed(chain.request());
if (!originalResponse.headers("Set-Cookie").isEmpty()) {
HashSet<String> cookies = new HashSet<>();
for (String cookie : originalResponse.headers("Set-Cookie")) {
for (String possibleSessionCookie : cookie.split(";")) {
if (possibleSessionCookie.startsWith("csessidc3c8") && cookie.contains("=")) {
String csessidc3c8 = possibleSessionCookie.split("=")[1];
PreferenceManager.getDefaultSharedPreferences(application).edit()
.putString("csessidc3c8",csessidc3c8)
.apply();
}
if (possibleSessionCookie.startsWith("csrftoken") && cookie.contains("=")) {
String csrftoken = possibleSessionCookie.split("=")[1];
PreferenceManager.getDefaultSharedPreferences(application).edit()
.putString("csrftoken",csrftoken)
.apply();
}
}
}
}
return originalResponse;
}
}
package hu.bme.dszenasi.circleandroid.core.util;
/**
* Created by danielszenasi on 05/05/16.
*/
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import java.io.IOException;
import java.io.InputStream;
import java.net.CookieHandler;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import hu.bme.dszenasi.circleandroid.R;
import okhttp3.JavaNetCookieJar;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Interceptor;
import okhttp3.Response;
public class SelfSigningClientBuilder {
public static OkHttpClient createClient(Application application) {
final TrustManager[] certs = new TrustManager[]{new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
@Override
public void checkServerTrusted(final X509Certificate[] chain,
final String authType) throws CertificateException {
}
@Override
public void checkClientTrusted(final X509Certificate[] chain,
final String authType) throws CertificateException {
}
}};
SSLContext ctx = null;
try {
ctx = SSLContext.getInstance("TLS");
ctx.init(null, certs, new SecureRandom());
} catch (final java.security.GeneralSecurityException ex) {
}
OkHttpClient.Builder builder = new OkHttpClient.Builder().sslSocketFactory(ctx.getSocketFactory());
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
//JavaNetCookieJar jncj = new JavaNetCookieJar(CookieHandler.getDefault());
//httpClient.cookieJar(jncj);
builder.addInterceptor(new AddCookiesInterceptor(application));
builder.addInterceptor(new ReceivedCookiesInterceptor(application));
return builder.build();
}
}