cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [3/3] cxf git commit: Checkstyle update
Date Tue, 08 Mar 2016 15:38:18 GMT
Checkstyle update

# Conflicts:
#	systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/MapIdentityManager.java


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/e41d2352
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e41d2352
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e41d2352

Branch: refs/heads/3.1.x-fixes
Commit: e41d2352762c124401629d7295691de2b6db1d5c
Parents: ac05513
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Tue Mar 8 15:29:46 2016 +0000
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Tue Mar 8 15:38:10 2016 +0000

----------------------------------------------------------------------
 parent/pom.xml                                  |   7 +-
 .../http_undertow/MapIdentityManager.java       | 126 +++++++++++++++++++
 2 files changed, 127 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/e41d2352/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 56fd166..042bc5c 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -316,18 +316,13 @@
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-checkstyle-plugin</artifactId>
-                    <version>2.15</version>
+                    <version>2.17</version>
                     <dependencies>
                         <dependency>
                             <groupId>org.apache.cxf.build-utils</groupId>
                             <artifactId>cxf-buildtools</artifactId>
                             <version>${cxf.build-utils.version}</version>
                         </dependency>
-                        <dependency>
-                            <groupId>com.puppycrawl.tools</groupId>
-                            <artifactId>checkstyle</artifactId>
-                            <version>6.4.1</version>
-                        </dependency>
                     </dependencies>
                     <configuration>
                         <encoding>UTF-8</encoding>

http://git-wip-us.apache.org/repos/asf/cxf/blob/e41d2352/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/MapIdentityManager.java
----------------------------------------------------------------------
diff --git a/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/MapIdentityManager.java
b/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/MapIdentityManager.java
new file mode 100644
index 0000000..fb29c98
--- /dev/null
+++ b/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/MapIdentityManager.java
@@ -0,0 +1,126 @@
+/**
+ * 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.cxf.systest.http_undertow;
+
+import java.nio.charset.Charset;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.Principal;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+import io.undertow.security.idm.Account;
+import io.undertow.security.idm.Credential;
+import io.undertow.security.idm.DigestCredential;
+import io.undertow.security.idm.IdentityManager;
+import io.undertow.security.idm.PasswordCredential;
+import io.undertow.util.HexConverter;
+
+class MapIdentityManager implements IdentityManager {
+    
+    private static final Charset UTF_8 = Charset.forName("UTF-8");
+
+    private final Map<String, char[]> users;
+
+    MapIdentityManager(final Map<String, char[]> users) {
+        this.users = users;
+    }
+
+    @Override
+    public Account verify(Account account) {
+        // An existing account so for testing assume still valid.
+        return account;
+    }
+
+    @Override
+    public Account verify(String id, Credential credential) {
+        Account account = getAccount(id);
+        if (account != null && verifyCredential(account, credential)) {
+            return account;
+        }
+
+        return null;
+    }
+
+    @Override
+    public Account verify(Credential credential) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    private boolean verifyCredential(Account account, Credential credential) {
+        if (credential instanceof PasswordCredential) {
+            char[] password = ((PasswordCredential) credential).getPassword();
+            char[] expectedPassword = users.get(account.getPrincipal().getName());
+
+            return Arrays.equals(password, expectedPassword);
+        } else if (credential instanceof DigestCredential) {
+            DigestCredential digCred = (DigestCredential) credential;
+            MessageDigest digest = null;
+            try {
+                digest = digCred.getAlgorithm().getMessageDigest();
+
+                digest.update(account.getPrincipal().getName().getBytes(UTF_8));
+                digest.update((byte) ':');
+                digest.update(digCred.getRealm().getBytes(UTF_8));
+                digest.update((byte) ':');
+                char[] expectedPassword = users.get(account.getPrincipal().getName());
+                digest.update(new String(expectedPassword).getBytes(UTF_8));
+
+                return digCred.verifyHA1(HexConverter.convertToHexBytes(digest.digest()));
+            } catch (NoSuchAlgorithmException e) {
+                throw new IllegalStateException("Unsupported Algorithm", e);
+            } finally {
+                digest.reset();
+            }
+        }
+        return false;
+    }
+
+    private Account getAccount(final String id) {
+        if (users.containsKey(id)) {
+            return new Account() {
+
+                private final Principal principal = new Principal() {
+
+                    @Override
+                    public String getName() {
+                        return id;
+                    }
+                };
+
+                @Override
+                public Principal getPrincipal() {
+                    return principal;
+                }
+
+                @Override
+                public Set<String> getRoles() {
+                    return Collections.emptySet();
+                }
+
+            };
+        }
+        return null;
+    }
+
+}


Mime
View raw message