View Javadoc
1   /**
2    * Waffle (https://github.com/dblock/waffle)
3    *
4    * Copyright (c) 2010 - 2015 Application Security, Inc.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of the Eclipse Public License v1.0
8    * which accompanies this distribution, and is available at
9    * http://www.eclipse.org/legal/epl-v10.html
10   *
11   * Contributors:
12   *     Application Security, Inc.
13   */
14  package waffle.mock;
15  
16  import waffle.windows.auth.IWindowsAccount;
17  
18  /**
19   * The Class MockWindowsAccount.
20   *
21   * @author dblock[at]dblock[dot]org
22   */
23  public class MockWindowsAccount implements IWindowsAccount {
24  
25      /** The Constant TEST_USER_NAME. */
26      public static final String TEST_USER_NAME = "WaffleTestUser";
27      
28      /** The Constant TEST_PASSWORD. */
29      public static final String TEST_PASSWORD  = "!WAFFLEP$$Wrd0";
30  
31      /** The fqn. */
32      private final String             fqn;
33      
34      /** The name. */
35      private String             name;
36      
37      /** The domain. */
38      private String             domain;
39      
40      /** The sid. */
41      private final String             sid;
42  
43      /**
44       * Instantiates a new mock windows account.
45       *
46       * @param newFqn
47       *            the new fqn
48       */
49      public MockWindowsAccount(final String newFqn) {
50          this(newFqn, "S-" + newFqn.hashCode());
51      }
52  
53      /**
54       * Instantiates a new mock windows account.
55       *
56       * @param newFqn
57       *            the new fqn
58       * @param newSid
59       *            the new sid
60       */
61      public MockWindowsAccount(final String newFqn, final String newSid) {
62          this.fqn = newFqn;
63          this.sid = newSid;
64          final String[] userNameDomain = newFqn.split("\\\\", 2);
65          if (userNameDomain.length == 2) {
66              this.name = userNameDomain[1];
67              this.domain = userNameDomain[0];
68          } else {
69              this.name = newFqn;
70          }
71      }
72  
73      /* (non-Javadoc)
74       * @see waffle.windows.auth.IWindowsAccount#getDomain()
75       */
76      @Override
77      public String getDomain() {
78          return this.domain;
79      }
80  
81      /* (non-Javadoc)
82       * @see waffle.windows.auth.IWindowsAccount#getFqn()
83       */
84      @Override
85      public String getFqn() {
86          return this.fqn;
87      }
88  
89      /* (non-Javadoc)
90       * @see waffle.windows.auth.IWindowsAccount#getName()
91       */
92      @Override
93      public String getName() {
94          return this.name;
95      }
96  
97      /* (non-Javadoc)
98       * @see waffle.windows.auth.IWindowsAccount#getSidString()
99       */
100     @Override
101     public String getSidString() {
102         return this.sid;
103     }
104 }