diff --git a/docs-android/app/build.gradle b/docs-android/app/build.gradle index 062f5655..8351f7ed 100644 --- a/docs-android/app/build.gradle +++ b/docs-android/app/build.gradle @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.0' + classpath 'com.android.tools.build:gradle:2.1.2' } } apply plugin: 'com.android.application' @@ -14,7 +14,7 @@ repositories { android { compileSdkVersion 23 - buildToolsVersion '23.0.3' + buildToolsVersion '24' defaultConfig { minSdkVersion 14 @@ -50,13 +50,13 @@ android { dependencies { compile fileTree(dir: 'libs', include: '*.jar') - compile 'com.android.support:appcompat-v7:23.3.0' - compile 'com.android.support:recyclerview-v7:23.3.0' - compile 'com.android.support:design:23.3.0' + compile 'com.android.support:appcompat-v7:23.4.0' + compile 'com.android.support:recyclerview-v7:23.4.0' + compile 'com.android.support:design:23.4.0' compile 'it.sephiroth.android.library.imagezoom:imagezoom:1.0.5' compile 'org.greenrobot:eventbus:3.0.0' compile 'com.squareup.picasso:picasso:2.5.2' - compile 'com.squareup.okhttp3:okhttp:3.1.1' - compile "com.squareup.okhttp3:okhttp-urlconnection:3.1.1" + compile 'com.squareup.okhttp3:okhttp:3.3.1' + compile "com.squareup.okhttp3:okhttp-urlconnection:3.3.1" compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.0.2' } diff --git a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentEditActivity.java b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentEditActivity.java index c15d04fc..7072bbbb 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentEditActivity.java +++ b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentEditActivity.java @@ -101,7 +101,7 @@ public class DocumentEditActivity extends AppCompatActivity { finish(); return; } - JSONArray tagArray = tags.optJSONArray("stats"); + JSONArray tagArray = tags.optJSONArray("tags"); List tagList = new ArrayList<>(); for (int i = 0; i < tagArray.length(); i++) { diff --git a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java index ec38eae4..06297596 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java +++ b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java @@ -16,6 +16,7 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.text.format.DateFormat; +import android.text.method.LinkMovementMethod; import android.view.ContextMenu; import android.view.Menu; import android.view.MenuInflater; @@ -51,7 +52,7 @@ import com.sismics.docs.resource.FileResource; import com.sismics.docs.service.FileUploadService; import com.sismics.docs.util.NetworkUtil; import com.sismics.docs.util.PreferenceUtil; -import com.sismics.docs.util.TagUtil; +import com.sismics.docs.util.SpannableUtil; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -176,9 +177,11 @@ public class DocumentViewActivity extends AppCompatActivity { } // Fill the layout + // Create date TextView createdDateTextView = (TextView) findViewById(R.id.createdDateTextView); createdDateTextView.setText(date); + // Description TextView descriptionTextView = (TextView) findViewById(R.id.descriptionTextView); if (description.isEmpty() || document.isNull("description")) { descriptionTextView.setVisibility(View.GONE); @@ -187,17 +190,20 @@ public class DocumentViewActivity extends AppCompatActivity { descriptionTextView.setText(description); } + // Tags TextView tagTextView = (TextView) findViewById(R.id.tagTextView); if (tags.length() == 0) { tagTextView.setVisibility(View.GONE); } else { tagTextView.setVisibility(View.VISIBLE); - tagTextView.setText(TagUtil.buildSpannable(tags)); + tagTextView.setText(SpannableUtil.buildSpannableTags(tags)); } + // Language ImageView languageImageView = (ImageView) findViewById(R.id.languageImageView); languageImageView.setImageResource(getResources().getIdentifier(language, "drawable", getPackageName())); + // Shared status ImageView sharedImageView = (ImageView) findViewById(R.id.sharedImageView); sharedImageView.setVisibility(shared ? View.VISIBLE : View.GONE); @@ -642,10 +648,10 @@ public class DocumentViewActivity extends AppCompatActivity { } // Action only available if the document is writable - findViewById(R.id.actionEditDocument).setVisibility(writable ? View.VISIBLE : View.INVISIBLE); - findViewById(R.id.actionUploadFile).setVisibility(writable ? View.VISIBLE : View.INVISIBLE); - findViewById(R.id.actionSharing).setVisibility(writable ? View.VISIBLE : View.INVISIBLE); - findViewById(R.id.actionDelete).setVisibility(writable ? View.VISIBLE : View.INVISIBLE); + findViewById(R.id.actionEditDocument).setVisibility(writable ? View.VISIBLE : View.GONE); + findViewById(R.id.actionUploadFile).setVisibility(writable ? View.VISIBLE : View.GONE); + findViewById(R.id.actionSharing).setVisibility(writable ? View.VISIBLE : View.GONE); + findViewById(R.id.actionDelete).setVisibility(writable ? View.VISIBLE : View.GONE); // ACLs ListView aclListView = (ListView) findViewById(R.id.aclListView); @@ -679,10 +685,54 @@ public class DocumentViewActivity extends AppCompatActivity { startActivity(intent); } }); + + // Contributors + TextView contributorsTextView = (TextView) findViewById(R.id.contributorsTextView); + contributorsTextView.setText(SpannableUtil.buildSpannableContributors(document.optJSONArray("contributors"))); + + // Relations + JSONArray relations = document.optJSONArray("relations"); + if (relations.length() > 0) { + TextView relationsTextView = (TextView) findViewById(R.id.relationsTextView); + relationsTextView.setMovementMethod(LinkMovementMethod.getInstance()); + relationsTextView.setText(SpannableUtil.buildSpannableRelations(relations)); + } else { + findViewById(R.id.relationsLayout).setVisibility(View.GONE); + } + + // Additional dublincore metadata + displayDublincoreMetadata(R.id.subjectTextView, R.id.subjectLayout, "subject"); + displayDublincoreMetadata(R.id.identifierTextView, R.id.identifierLayout, "identifier"); + displayDublincoreMetadata(R.id.publisherTextView, R.id.publisherLayout, "publisher"); + displayDublincoreMetadata(R.id.formatTextView, R.id.formatLayout, "format"); + displayDublincoreMetadata(R.id.sourceTextView, R.id.sourceLayout, "source"); + displayDublincoreMetadata(R.id.typeTextView, R.id.typeLayout, "type"); + displayDublincoreMetadata(R.id.coverageTextView, R.id.coverageLayout, "coverage"); + displayDublincoreMetadata(R.id.rightsTextView, R.id.rightsLayout, "rights"); } }); } + /** + * Display a dublincore metadata. + * + * @param textViewId TextView ID + * @param blockViewId View ID + * @param name Name + */ + private void displayDublincoreMetadata(int textViewId, int blockViewId, String name) { + if (document == null) return; + String value = document.optString(name); + if (document.isNull(name) || value.isEmpty()) { + findViewById(blockViewId).setVisibility(View.GONE); + return; + } + + findViewById(blockViewId).setVisibility(View.VISIBLE); + TextView textView = (TextView) findViewById(textViewId); + textView.setText(value); + } + @Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { switch (view.getId()) { diff --git a/docs-android/app/src/main/java/com/sismics/docs/adapter/DocListAdapter.java b/docs-android/app/src/main/java/com/sismics/docs/adapter/DocListAdapter.java index bd68ddce..5450db0a 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/adapter/DocListAdapter.java +++ b/docs-android/app/src/main/java/com/sismics/docs/adapter/DocListAdapter.java @@ -9,7 +9,7 @@ import android.widget.ImageView; import android.widget.TextView; import com.sismics.docs.R; -import com.sismics.docs.util.TagUtil; +import com.sismics.docs.util.SpannableUtil; import org.json.JSONArray; import org.json.JSONObject; @@ -69,7 +69,7 @@ public class DocListAdapter extends RecyclerView.Adapter tagList = new ArrayList<>(); for (int i = 0; i < tagArray.length(); i++) { diff --git a/docs-android/app/src/main/java/com/sismics/docs/ui/view/NonScrollListView.java b/docs-android/app/src/main/java/com/sismics/docs/ui/view/NonScrollListView.java new file mode 100644 index 00000000..f40f4dce --- /dev/null +++ b/docs-android/app/src/main/java/com/sismics/docs/ui/view/NonScrollListView.java @@ -0,0 +1,33 @@ +package com.sismics.docs.ui.view; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.ViewGroup; +import android.widget.ListView; + +/** + * Non-scrollable ListView. + * All items are visible from the start. + * + * @author http://stackoverflow.com/questions/18813296/non-scrollable-listview-inside-scrollview/24629341#24629341 + */ +public class NonScrollListView extends ListView { + + public NonScrollListView(Context context) { + super(context); + } + public NonScrollListView(Context context, AttributeSet attrs) { + super(context, attrs); + } + public NonScrollListView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + @Override + public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec( + Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); + super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom); + ViewGroup.LayoutParams params = getLayoutParams(); + params.height = getMeasuredHeight(); + } +} \ No newline at end of file diff --git a/docs-android/app/src/main/java/com/sismics/docs/util/SpannableUtil.java b/docs-android/app/src/main/java/com/sismics/docs/util/SpannableUtil.java new file mode 100644 index 00000000..5fdf712f --- /dev/null +++ b/docs-android/app/src/main/java/com/sismics/docs/util/SpannableUtil.java @@ -0,0 +1,85 @@ +package com.sismics.docs.util; + +import android.graphics.Color; +import android.text.Spannable; +import android.text.SpannableStringBuilder; +import android.text.Spanned; +import android.text.style.BackgroundColorSpan; +import android.text.style.ForegroundColorSpan; + +import org.json.JSONArray; +import org.json.JSONObject; + +/** + * Utility class for spannable. + * + * @author bgamard. + */ +public class SpannableUtil { + /** + * Create a colored spannable from tags. + * + * @param tags Tags + * @return Colored spannable + */ + public static Spannable buildSpannableTags(JSONArray tags) { + return buildSpannable(tags, "name", "color"); + } + + /** + * Create a spannable for contributors. + * + * @param contributors Contributors + * @return Spannable + */ + public static Spannable buildSpannableContributors(JSONArray contributors) { + return buildSpannable(contributors, "username", null); + } + + /** + * Create a spannable for relations. + * + * @param relations Relations + * @return Spannable + */ + public static Spannable buildSpannableRelations(JSONArray relations) { + return buildSpannable(relations, "title", null); + } + + /** + * Create a spannable from a JSONArray. + * + * @param array JSONArray + * @param valueName Name of the value part + * @param colorName Name of the color part (optional) + * @return Spannable + */ + private static Spannable buildSpannable(JSONArray array, String valueName, String colorName) { + SpannableStringBuilder builder = new SpannableStringBuilder(); + + for (int i = 0; i < array.length(); i++) { + final JSONObject tag = array.optJSONObject(i); + int start = builder.length(); + builder.append(" ").append(tag.optString(valueName)).append(" "); + builder.setSpan(new ForegroundColorSpan(Color.WHITE), start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + builder.setSpan(new BackgroundColorSpan(Color.parseColor(tag.optString(colorName, "#5bc0de"))), start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + /* + TODO : Make tags, relations and contributors clickable + builder.setSpan(new ClickableSpan() { + @Override + public void onClick(View widget) { + } + + @Override + public void updateDrawState(TextPaint ds) { + super.updateDrawState(ds); + ds.setColor(Color.WHITE); + ds.setUnderlineText(false); + } + }, start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);*/ + builder.append(" "); + } + + return builder; + } +} diff --git a/docs-android/app/src/main/java/com/sismics/docs/util/TagUtil.java b/docs-android/app/src/main/java/com/sismics/docs/util/TagUtil.java deleted file mode 100644 index d2af026d..00000000 --- a/docs-android/app/src/main/java/com/sismics/docs/util/TagUtil.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.sismics.docs.util; - -import android.graphics.Color; -import android.text.Spannable; -import android.text.SpannableStringBuilder; -import android.text.Spanned; -import android.text.style.BackgroundColorSpan; -import android.text.style.ForegroundColorSpan; - -import org.json.JSONArray; -import org.json.JSONObject; - -/** - * Utility class for tags. - * - * @author bgamard. - */ -public class TagUtil { - /** - * Create a colored spannable from tags. - * - * @param tags Tags - * @return Colored spannable - */ - public static Spannable buildSpannable(JSONArray tags) { - SpannableStringBuilder builder = new SpannableStringBuilder(); - - for (int i = 0; i < tags.length(); i++) { - JSONObject tag = tags.optJSONObject(i); - int start = builder.length(); - builder.append(" ").append(tag.optString("name")).append(" "); - builder.setSpan(new ForegroundColorSpan(Color.WHITE), start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - builder.setSpan(new BackgroundColorSpan(Color.parseColor(tag.optString("color"))), start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - builder.append(" "); - } - - return builder; - } -} diff --git a/docs-android/app/src/main/res/layout/document_view_activity.xml b/docs-android/app/src/main/res/layout/document_view_activity.xml index 13c3e0f3..fb50540a 100644 --- a/docs-android/app/src/main/res/layout/document_view_activity.xml +++ b/docs-android/app/src/main/res/layout/document_view_activity.xml @@ -142,241 +142,523 @@ - - - + android:elevation="5dp" + android:layout_gravity="end"> + android:orientation="vertical"> + + + android:orientation="vertical" + android:gravity="center"> - + +

 

+ + \ No newline at end of file diff --git a/docs-web/src/main/webapp/src/partial/docs/settings.theme.html b/docs-web/src/main/webapp/src/partial/docs/settings.config.html similarity index 77% rename from docs-web/src/main/webapp/src/partial/docs/settings.theme.html rename to docs-web/src/main/webapp/src/partial/docs/settings.config.html index 5f046bc5..b909bbe1 100644 --- a/docs-web/src/main/webapp/src/partial/docs/settings.theme.html +++ b/docs-web/src/main/webapp/src/partial/docs/settings.config.html @@ -1,3 +1,18 @@ +

+ Guest access + + {{ app.guest_login ? 'Enabled' : 'Disabled' }} + +

+

+ Guest access is a mode where anyone can access {{ appName }} without password.
+ Like a normal user, the guest user can only access its documents and those accessible through permissions.
+

+
+ + +
+

Theme customization

diff --git a/docs-web/src/main/webapp/src/partial/docs/settings.group.html b/docs-web/src/main/webapp/src/partial/docs/settings.group.html index 284706ec..84b6e535 100644 --- a/docs-web/src/main/webapp/src/partial/docs/settings.group.html +++ b/docs-web/src/main/webapp/src/partial/docs/settings.group.html @@ -1,4 +1,4 @@ -

Groups management Add

+

Groups management Add a group

diff --git a/docs-web/src/main/webapp/src/partial/docs/settings.html b/docs-web/src/main/webapp/src/partial/docs/settings.html index 6594764f..6c574a65 100644 --- a/docs-web/src/main/webapp/src/partial/docs/settings.html +++ b/docs-web/src/main/webapp/src/partial/docs/settings.html @@ -9,14 +9,14 @@
-
-
General settings
+
diff --git a/docs-web/src/main/webapp/src/partial/docs/settings.session.html b/docs-web/src/main/webapp/src/partial/docs/settings.session.html index 8d32a86d..2b5c015b 100644 --- a/docs-web/src/main/webapp/src/partial/docs/settings.session.html +++ b/docs-web/src/main/webapp/src/partial/docs/settings.session.html @@ -13,10 +13,12 @@ {{ session.create_date | date: 'yyyy-MM-dd HH:mm' }} {{ session.last_connection_date | date: 'yyyy-MM-dd HH:mm' }} {{ session.ip }} - + + +
- +
\ No newline at end of file diff --git a/docs-web/src/main/webapp/src/partial/docs/settings.user.edit.html b/docs-web/src/main/webapp/src/partial/docs/settings.user.edit.html index d9033895..88d44636 100644 --- a/docs-web/src/main/webapp/src/partial/docs/settings.user.edit.html +++ b/docs-web/src/main/webapp/src/partial/docs/settings.user.edit.html @@ -62,7 +62,7 @@ Number required
-
+
@@ -76,7 +76,7 @@ Too long
-
+
@@ -94,7 +94,7 @@ -
diff --git a/docs-web/src/main/webapp/src/partial/docs/settings.user.html b/docs-web/src/main/webapp/src/partial/docs/settings.user.html index c4fb3c1b..2f4e991e 100644 --- a/docs-web/src/main/webapp/src/partial/docs/settings.user.html +++ b/docs-web/src/main/webapp/src/partial/docs/settings.user.html @@ -1,4 +1,4 @@ -

Users management Add

+

Users management Add a user

diff --git a/docs-web/src/prod/resources/config.properties b/docs-web/src/prod/resources/config.properties index 04b5153a..f935e8fa 100644 --- a/docs-web/src/prod/resources/config.properties +++ b/docs-web/src/prod/resources/config.properties @@ -1,3 +1,3 @@ api.current_version=${project.version} api.min_version=1.0 -db.version=9 \ No newline at end of file +db.version=10 \ No newline at end of file diff --git a/docs-web/src/stress/resources/config.properties b/docs-web/src/stress/resources/config.properties index 04b5153a..f935e8fa 100644 --- a/docs-web/src/stress/resources/config.properties +++ b/docs-web/src/stress/resources/config.properties @@ -1,3 +1,3 @@ api.current_version=${project.version} api.min_version=1.0 -db.version=9 \ No newline at end of file +db.version=10 \ No newline at end of file diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestAppResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestAppResource.java index e8fc889c..41185645 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestAppResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestAppResource.java @@ -1,5 +1,13 @@ package com.sismics.docs.rest; +import com.sismics.docs.core.constant.PermType; +import com.sismics.docs.core.dao.jpa.AclDao; +import com.sismics.util.context.ThreadLocalContext; +import com.sismics.util.filter.TokenBasedSecurityFilter; +import com.sismics.util.jpa.EMF; +import org.junit.Assert; +import org.junit.Test; + import javax.json.JsonArray; import javax.json.JsonObject; import javax.persistence.EntityManager; @@ -9,15 +17,6 @@ import javax.ws.rs.core.Form; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; -import com.sismics.docs.core.constant.PermType; -import com.sismics.docs.core.dao.jpa.AclDao; -import com.sismics.util.context.ThreadLocalContext; -import com.sismics.util.jpa.EMF; -import org.junit.Assert; -import org.junit.Test; - -import com.sismics.util.filter.TokenBasedSecurityFilter; - /** * Test the app resource. @@ -35,17 +34,15 @@ public class TestAppResource extends BaseJerseyTest { // Check the application info JsonObject json = target().path("/app").request() - .cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken) .get(JsonObject.class); - String currentVersion = json.getString("current_version"); - Assert.assertNotNull(currentVersion); - String minVersion = json.getString("min_version"); - Assert.assertNotNull(minVersion); + Assert.assertNotNull(json.getString("current_version")); + Assert.assertNotNull(json.getString("min_version")); Long freeMemory = json.getJsonNumber("free_memory").longValue(); Assert.assertTrue(freeMemory > 0); Long totalMemory = json.getJsonNumber("total_memory").longValue(); Assert.assertTrue(totalMemory > 0 && totalMemory > freeMemory); - + Assert.assertFalse(json.getBoolean("guest_login")); + // Rebuild Lucene index Response response = target().path("/app/batch/reindex").request() .cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken) @@ -127,4 +124,69 @@ public class TestAppResource extends BaseJerseyTest { Long date4 = logs.getJsonObject(9).getJsonNumber("date").longValue(); Assert.assertTrue(date3 >= date4); } + + /** + * Test the guest login. + */ + @Test + public void testGuestLogin() { + // Login admin + String adminToken = clientUtil.login("admin", "admin", false); + + // Try to login as guest + Response response = target().path("/user/login").request() + .post(Entity.form(new Form() + .param("username", "guest"))); + Assert.assertEquals(Status.FORBIDDEN.getStatusCode(), response.getStatus()); + + // Enable guest login + target().path("/app/guest_login").request() + .cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken) + .post(Entity.form(new Form() + .param("enabled", "true")), JsonObject.class); + + // Login as guest + String guestToken = clientUtil.login("guest", "", false); + + // Guest cannot delete himself + response = target().path("/user").request() + .cookie(TokenBasedSecurityFilter.COOKIE_NAME, guestToken) + .delete(); + Assert.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); + + // Guest cannot see opened sessions + JsonObject json = target().path("/user/session").request() + .cookie(TokenBasedSecurityFilter.COOKIE_NAME, guestToken) + .get(JsonObject.class); + Assert.assertEquals(0, json.getJsonArray("sessions").size()); + + // Guest cannot delete opened sessions + response = target().path("/user/session").request() + .cookie(TokenBasedSecurityFilter.COOKIE_NAME, guestToken) + .delete(); + Assert.assertEquals(Status.FORBIDDEN.getStatusCode(), response.getStatus()); + + // Guest cannot enable TOTP + response = target().path("/user/enable_totp").request() + .cookie(TokenBasedSecurityFilter.COOKIE_NAME, guestToken) + .post(Entity.form(new Form())); + Assert.assertEquals(Status.FORBIDDEN.getStatusCode(), response.getStatus()); + + // Guest cannot disable TOTP + response = target().path("/user/disable_totp").request() + .cookie(TokenBasedSecurityFilter.COOKIE_NAME, guestToken) + .post(Entity.form(new Form())); + Assert.assertEquals(Status.FORBIDDEN.getStatusCode(), response.getStatus()); + + // Guest cannot update itself + response = target().path("/user").request() + .cookie(TokenBasedSecurityFilter.COOKIE_NAME, guestToken) + .post(Entity.form(new Form())); + Assert.assertEquals(Status.FORBIDDEN.getStatusCode(), response.getStatus()); + + // Guest can see its documents + target().path("/document/list").request() + .cookie(TokenBasedSecurityFilter.COOKIE_NAME, guestToken) + .get(JsonObject.class); + } } \ No newline at end of file diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestSecurity.java b/docs-web/src/test/java/com/sismics/docs/rest/TestSecurity.java index ccf1f6c9..602415a3 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestSecurity.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestSecurity.java @@ -6,6 +6,7 @@ import javax.ws.rs.core.Form; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; +import com.sismics.util.filter.HeaderBasedSecurityFilter; import org.junit.Assert; import org.apache.commons.lang.StringUtils; @@ -28,7 +29,7 @@ public class TestSecurity extends BaseJerseyTest { clientUtil.createUser("testsecurity"); // Changes a user's email KO : the user is not connected - Response response = target().path("/user/update").request() + Response response = target().path("/user").request() .post(Entity.form(new Form().param("email", "testsecurity2@docs.com"))); Assert.assertEquals(Status.FORBIDDEN, Status.fromStatusCode(response.getStatus())); JsonObject json = response.readEntity(JsonObject.class); @@ -73,4 +74,29 @@ public class TestSecurity extends BaseJerseyTest { // User testsecurity logs out clientUtil.logout(testSecurityToken); } + + @Test + public void testHeaderBasedAuthentication() { + clientUtil.createUser("header_auth_test"); + + Assert.assertEquals(Status.FORBIDDEN.getStatusCode(), target() + .path("/user/session") + .request() + .get() + .getStatus()); + + Assert.assertEquals(Status.OK.getStatusCode(), target() + .path("/user/session") + .request() + .header(HeaderBasedSecurityFilter.AUTHENTICATED_USER_HEADER, "header_auth_test") + .get() + .getStatus()); + + Assert.assertEquals(Status.FORBIDDEN.getStatusCode(), target() + .path("/user/session") + .request() + .header(HeaderBasedSecurityFilter.AUTHENTICATED_USER_HEADER, "idontexist") + .get() + .getStatus()); + } } \ No newline at end of file diff --git a/docs-web/src/test/resources/hibernate.properties b/docs-web/src/test/resources/hibernate.properties index 2c068af9..7e4efc32 100644 --- a/docs-web/src/test/resources/hibernate.properties +++ b/docs-web/src/test/resources/hibernate.properties @@ -4,7 +4,7 @@ hibernate.connection.username=sa hibernate.connection.password= hibernate.hbm2ddl.auto= hibernate.dialect=org.hibernate.dialect.HSQLDialect -hibernate.show_sql=true +hibernate.show_sql=false hibernate.format_sql=false hibernate.max_fetch_depth=5 hibernate.cache.use_second_level_cache=false diff --git a/docs-web/src/test/resources/log4j.properties b/docs-web/src/test/resources/log4j.properties index 5d76e55b..1d786f52 100644 --- a/docs-web/src/test/resources/log4j.properties +++ b/docs-web/src/test/resources/log4j.properties @@ -1,10 +1,10 @@ -log4j.rootCategory=DEBUG, CONSOLE, MEMORY +log4j.rootCategory=INFO, CONSOLE, MEMORY log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=%d{DATE} %p %l %m %n log4j.appender.MEMORY=com.sismics.util.log4j.MemoryAppender log4j.appender.MEMORY.size=1000 -log4j.logger.com.sismics=DEBUG +log4j.logger.com.sismics=INFO log4j.logger.org.hibernate=INFO log4j.logger.org.apache.pdfbox=INFO \ No newline at end of file