View Javadoc
1   /*
2    * Copyright 2021 Michael Osipov
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  package net.sf.michaelo.tomcat.realm;
17  
18  import java.util.Objects;
19  
20  import org.ietf.jgss.GSSException;
21  import org.ietf.jgss.GSSManager;
22  import org.ietf.jgss.GSSName;
23  import org.ietf.jgss.Oid;
24  
25  /**
26   * Stub GSS name implementation to merely transport a name with its string name type. This class is not intended to be
27   * used in real with the {@link GSSManager}.
28   */
29  public class StubGSSName implements GSSName {
30  
31  	private final String name;
32  	private final Oid oid;
33  
34  	public StubGSSName(String name, Oid oid) {
35  		this.name = name;
36  		this.oid = oid;
37  	}
38  
39  	@Override
40  	public boolean equals(GSSName another) throws GSSException {
41  		if (another instanceof StubGSSName) {
42  			StubGSSName stubGssName = (StubGSSName) another;
43  			return Objects.equals(name, stubGssName.name) && Objects.equals(oid, stubGssName.oid);
44  		}
45  
46  		return false;
47  	}
48  
49  	/**
50  	 * @throws UnsupportedOperationException
51  	 *             always throws because not implemented
52  	 */
53  	@Override
54  	public GSSName canonicalize(Oid mech) throws GSSException {
55  		throw new UnsupportedOperationException("method canonicalize() is not supported");
56  	}
57  
58  	/**
59  	 * @throws UnsupportedOperationException
60  	 *             always throws because not implemented
61  	 */
62  	@Override
63  	public byte[] export() throws GSSException {
64  		throw new UnsupportedOperationException("method export() is not supported");
65  	}
66  
67  	@Override
68  	public Oid getStringNameType() throws GSSException {
69  		return oid;
70  	}
71  
72  	/**
73  	 * @throws UnsupportedOperationException
74  	 *             always throws because not implemented
75  	 */
76  	@Override
77  	public boolean isAnonymous() {
78  		throw new UnsupportedOperationException("method isAnonymous() is not supported");
79  	}
80  
81  	/**
82  	 * @throws UnsupportedOperationException
83  	 *             always throws because not implemented
84  	 */
85  	@Override
86  	public boolean isMN() {
87  		throw new UnsupportedOperationException("method isNM() is not supported");
88  	}
89  
90  	@Override
91  	public int hashCode() {
92  		return name.hashCode();
93  	}
94  
95  	@Override
96  	public boolean equals(Object another) {
97  		if (another instanceof GSSName)
98  			try {
99  				return equals((GSSName) another);
100 			} catch (GSSException e) {
101 				; // Ignore
102 			}
103 
104 		return false;
105 	}
106 
107 	@Override
108 	public String toString() {
109 		return name;
110 	}
111 
112 }