You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by jo...@apache.org on 2013/02/25 15:15:36 UTC
svn commit: r1449714 - in /commons/proper/vfs/trunk:
core/src/main/java/org/apache/commons/vfs2/auth/
core/src/test/java/org/apache/commons/vfs2/auth/ src/changes/
Author: joehni
Date: Mon Feb 25 14:15:36 2013
New Revision: 1449714
URL: http://svn.apache.org/r1449714
Log:
StaticUserAuthenticator should return only requested authentication data (VFS-464).
Added:
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/auth/
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/auth/StaticUserAuthenticatorTestCase.java (with props)
Modified:
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/auth/StaticUserAuthenticator.java
commons/proper/vfs/trunk/src/changes/changes.xml
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/auth/StaticUserAuthenticator.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/auth/StaticUserAuthenticator.java?rev=1449714&r1=1449713&r2=1449714&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/auth/StaticUserAuthenticator.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/auth/StaticUserAuthenticator.java Mon Feb 25 14:15:36 2013
@@ -16,6 +16,8 @@
*/
package org.apache.commons.vfs2.auth;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.commons.vfs2.UserAuthenticationData;
import org.apache.commons.vfs2.UserAuthenticator;
import org.apache.commons.vfs2.util.UserAuthenticatorUtils;
@@ -25,6 +27,8 @@ import org.apache.commons.vfs2.util.User
*/
public class StaticUserAuthenticator implements UserAuthenticator, Comparable<StaticUserAuthenticator>
{
+ private final static Log LOG = LogFactory.getLog(StaticUserAuthenticator.class);
+
/** The user name */
private final String username;
@@ -45,9 +49,30 @@ public class StaticUserAuthenticator imp
public UserAuthenticationData requestAuthentication(final UserAuthenticationData.Type[] types)
{
final UserAuthenticationData data = new UserAuthenticationData();
- data.setData(UserAuthenticationData.DOMAIN, UserAuthenticatorUtils.toChar(domain));
- data.setData(UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(username));
- data.setData(UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(password));
+ for(final UserAuthenticationData.Type type : types)
+ {
+ if (type == UserAuthenticationData.DOMAIN)
+ {
+ data.setData(UserAuthenticationData.DOMAIN, UserAuthenticatorUtils.toChar(domain));
+ }
+ else if (type == UserAuthenticationData.USERNAME)
+ {
+ data.setData(UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(username));
+ }
+ else if (type == UserAuthenticationData.PASSWORD)
+ {
+ data.setData(UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(password));
+ }
+ else
+ {
+ if (LOG.isInfoEnabled())
+ {
+ LOG.info(StaticUserAuthenticator.class.getSimpleName()
+ + " does not support authentication data type '" + type
+ + "'; authentication request ignored.");
+ }
+ }
+ }
return data;
}
Added: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/auth/StaticUserAuthenticatorTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/auth/StaticUserAuthenticatorTestCase.java?rev=1449714&view=auto
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/auth/StaticUserAuthenticatorTestCase.java (added)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/auth/StaticUserAuthenticatorTestCase.java Mon Feb 25 14:15:36 2013
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs2.auth;
+
+import static org.junit.Assert.*;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.vfs2.UserAuthenticationData;
+import org.apache.commons.vfs2.UserAuthenticator;
+
+import org.junit.Test;
+
+public class StaticUserAuthenticatorTestCase
+{
+ @Test
+ public void testAuthenticationRequest()
+ {
+ final UserAuthenticator userAuthenticator = new StaticUserAuthenticator("DOMAIN", "USER", "PWD");
+ UserAuthenticationData authenticationData =
+ userAuthenticator.requestAuthentication(ArrayUtils.toArray(UserAuthenticationData.DOMAIN));
+ assertArrayEquals("DOMAIN".toCharArray(), authenticationData.getData(UserAuthenticationData.DOMAIN));
+ assertNull(authenticationData.getData(UserAuthenticationData.USERNAME));
+ assertNull(authenticationData.getData(UserAuthenticationData.PASSWORD));
+ authenticationData = userAuthenticator.requestAuthentication(
+ ArrayUtils.toArray(UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD));
+ assertNull(authenticationData.getData(UserAuthenticationData.DOMAIN));
+ assertArrayEquals("USER".toCharArray(), authenticationData.getData(UserAuthenticationData.USERNAME));
+ assertArrayEquals("PWD".toCharArray(), authenticationData.getData(UserAuthenticationData.PASSWORD));
+ }
+
+ @Test
+ public void testEquality()
+ {
+ final UserAuthenticator userAuthenticator = new StaticUserAuthenticator("DOMAIN", "USER", "PWD");
+ assertEquals(new StaticUserAuthenticator("DOMAIN", "USER", "PWD"), userAuthenticator);
+ assertNotEquals(new StaticUserAuthenticator("DOMAIN", "USER", null), userAuthenticator);
+ assertNotEquals(new StaticUserAuthenticator("DOMAIN", null, "PWD"), userAuthenticator);
+ assertNotEquals(new StaticUserAuthenticator(null, "USER", "PWD"), userAuthenticator);
+ assertEquals(new StaticUserAuthenticator("DOMAIN", "USER", "PWD").hashCode(), userAuthenticator.hashCode());
+ }
+}
Propchange: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/auth/StaticUserAuthenticatorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/auth/StaticUserAuthenticatorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Author Id HeadURL Revision
Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1449714&r1=1449713&r2=1449714&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Mon Feb 25 14:15:36 2013
@@ -26,6 +26,9 @@
<!-- <action issue="VFS-443" dev="ggregory" type="update" due-to="nickallen"> -->
<!-- [Local] Need an easy way to convert from a FileObject to a File. -->
<!-- </action> -->
+ <action issue="VFS-464" dev="joehni" type="fix">
+ StaticUserAuthenticator should return only requested authentication data.
+ </action>
<action issue="VFS-463" dev="joehni" type="update">
FileSytemConfigBuilder supports system properties for the value of enum-based configuration entries.
</action>