View Javadoc
1   /*
2    * Copyright 2002-2013 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.web.socket.handler;
18  
19  import java.security.Principal;
20  
21  /**
22   * An implementation of {@link Principal} for testing.
23   *
24   * @author Rossen Stoyanchev
25   */
26  public class TestPrincipal implements Principal {
27  
28  	private String name;
29  
30  	public TestPrincipal(String name) {
31  		this.name = name;
32  	}
33  
34  	@Override
35  	public String getName() {
36  		return this.name;
37  	}
38  
39  	@Override
40  	public boolean equals(Object obj) {
41  		if (obj == this) {
42  			return true;
43  		}
44  		if (!(obj instanceof TestPrincipal)) {
45  			return false;
46  		}
47  		TestPrincipal p = (TestPrincipal) obj;
48  		return this.name.equals(p.name);
49  	}
50  
51  	@Override
52  	public int hashCode() {
53  		return this.name.hashCode();
54  	}
55  
56  }