You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by ad...@apache.org on 2015/03/13 21:45:32 UTC
[16/50] wicket git commit: WICKET-5823 DefaultAuthenticationStrategy
should be modified to reduce copy/paste while extending it's functionality
WICKET-5823 DefaultAuthenticationStrategy should be modified to reduce copy/paste while extending it's functionality
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/c36f95e9
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/c36f95e9
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/c36f95e9
Branch: refs/heads/pr-86-media_tags
Commit: c36f95e94bebd16cb5cfe50a8f4cbcdee4f5729f
Parents: 5a2ca37
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Wed Feb 25 23:36:51 2015 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Wed Feb 25 23:36:51 2015 +0200
----------------------------------------------------------------------
.../authentication/IAuthenticationStrategy.java | 19 ++++++++-----
.../strategy/DefaultAuthenticationStrategy.java | 28 ++++++++++++++++----
.../strategy/NoOpAuthenticationStrategy.java | 19 +------------
3 files changed, 36 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/c36f95e9/wicket-core/src/main/java/org/apache/wicket/authentication/IAuthenticationStrategy.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/authentication/IAuthenticationStrategy.java b/wicket-core/src/main/java/org/apache/wicket/authentication/IAuthenticationStrategy.java
index 95bae54..dacbafe 100644
--- a/wicket-core/src/main/java/org/apache/wicket/authentication/IAuthenticationStrategy.java
+++ b/wicket-core/src/main/java/org/apache/wicket/authentication/IAuthenticationStrategy.java
@@ -28,23 +28,28 @@ import org.apache.wicket.Application;
public interface IAuthenticationStrategy
{
/**
- * If "rememberMe" is enabled, than load login name and password from the persistence storage
+ * If "rememberMe" is enabled, then load the saved credentials (e.g. username and password) from the persistence storage
* (e.g. Cookie) for automatic sign in. This is useful for applications which users typically
* have open the whole day but where the server invalidates the session after a timeout and you
* want to force the user to sign in again and again during the day.
*
- * @return [0] = username, [1] = password, null if not found
+ * @return The {@link #save(String, String...) saved} credentials
*/
String[] load();
/**
- * If "rememberMe" is enabled and login was successful, than store username and password in the
+ * If "rememberMe" is enabled and login was successful, then store the given credentials in the
* persistence store (e.g. Cookie).
- *
- * @param username
- * @param password
+ *
+ * <p>The implementation of this method should be symmetrical with the implementation of
+ * {@link #load()}.</p>
+ *
+ * @param credential
+ * The credential to store. For example: a security token or username.
+ * @param extraCredentials
+ * Optional extra credentials. For example: a password
*/
- void save(final String username, final String password);
+ void save(final String credential, final String... extraCredentials);
/**
* When the user logs out (session invalidation), than remove username and password from the
http://git-wip-us.apache.org/repos/asf/wicket/blob/c36f95e9/wicket-core/src/main/java/org/apache/wicket/authentication/strategy/DefaultAuthenticationStrategy.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/authentication/strategy/DefaultAuthenticationStrategy.java b/wicket-core/src/main/java/org/apache/wicket/authentication/strategy/DefaultAuthenticationStrategy.java
index 62c324a..59bb484 100644
--- a/wicket-core/src/main/java/org/apache/wicket/authentication/strategy/DefaultAuthenticationStrategy.java
+++ b/wicket-core/src/main/java/org/apache/wicket/authentication/strategy/DefaultAuthenticationStrategy.java
@@ -141,19 +141,37 @@ public class DefaultAuthenticationStrategy implements IAuthenticationStrategy
/**
* @see org.apache.wicket.authentication.IAuthenticationStrategy#save(java.lang.String,
- * java.lang.String)
+ * java.lang.String...)
*/
@Override
- public void save(final String username, final String password)
+ public void save(final String credential, final String... extraCredentials)
{
- String value = username + VALUE_SEPARATOR + password;
-
- String encryptedValue = getCrypt().encryptUrlSafe(value);
+ String encryptedValue = getCrypt().encryptUrlSafe(encode(credential, extraCredentials));
getCookieUtils().save(cookieKey, encryptedValue);
}
/**
+ * This method can be overridden to provide different encoding mechanism
+ *
+ * @param credential
+ * @param extraCredentials
+ * @return String representation of the parameters given
+ */
+ protected String encode(final String credential, final String... extraCredentials)
+ {
+ StringBuilder value = new StringBuilder(credential);
+ if (extraCredentials != null)
+ {
+ for (String extraCredential : extraCredentials)
+ {
+ value.append(VALUE_SEPARATOR).append(extraCredential);
+ }
+ }
+ return value.toString();
+ }
+
+ /**
* @see org.apache.wicket.authentication.IAuthenticationStrategy#remove()
*/
@Override
http://git-wip-us.apache.org/repos/asf/wicket/blob/c36f95e9/wicket-core/src/main/java/org/apache/wicket/authentication/strategy/NoOpAuthenticationStrategy.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/authentication/strategy/NoOpAuthenticationStrategy.java b/wicket-core/src/main/java/org/apache/wicket/authentication/strategy/NoOpAuthenticationStrategy.java
index fb92047..2146063 100644
--- a/wicket-core/src/main/java/org/apache/wicket/authentication/strategy/NoOpAuthenticationStrategy.java
+++ b/wicket-core/src/main/java/org/apache/wicket/authentication/strategy/NoOpAuthenticationStrategy.java
@@ -25,34 +25,17 @@ import org.apache.wicket.authentication.IAuthenticationStrategy;
*/
public class NoOpAuthenticationStrategy implements IAuthenticationStrategy
{
- /**
- * Constructor
- */
- public NoOpAuthenticationStrategy()
- {
- }
-
- /**
- * @see org.apache.wicket.authentication.IAuthenticationStrategy#load()
- */
@Override
public String[] load()
{
return null;
}
- /**
- * @see org.apache.wicket.authentication.IAuthenticationStrategy#save(java.lang.String,
- * java.lang.String)
- */
@Override
- public void save(final String username, final String password)
+ public void save(final String credential, final String... extraCredentials)
{
}
- /**
- * @see org.apache.wicket.authentication.IAuthenticationStrategy#remove()
- */
@Override
public void remove()
{