View Javadoc
1   /*
2    * Copyright 2021–2026 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  	/** @throws UnsupportedOperationException always throws because not implemented */
50  	@Override
51  	public GSSName canonicalize(Oid mech) throws GSSException {
52  		throw new UnsupportedOperationException("method canonicalize() is not supported");
53  	}
54  
55  	/** @throws UnsupportedOperationException always throws because not implemented */
56  	@Override
57  	public byte[] export() throws GSSException {
58  		throw new UnsupportedOperationException("method export() is not supported");
59  	}
60  
61  	@Override
62  	public Oid getStringNameType() throws GSSException {
63  		return oid;
64  	}
65  
66  	/** @throws UnsupportedOperationException always throws because not implemented */
67  	@Override
68  	public boolean isAnonymous() {
69  		throw new UnsupportedOperationException("method isAnonymous() is not supported");
70  	}
71  
72  	/** @throws UnsupportedOperationException always throws because not implemented */
73  	@Override
74  	public boolean isMN() {
75  		throw new UnsupportedOperationException("method isNM() is not supported");
76  	}
77  
78  	@Override
79  	public int hashCode() {
80  		return name.hashCode();
81  	}
82  
83  	@Override
84  	public boolean equals(Object another) {
85  		if (another instanceof GSSName)
86  			try {
87  				return equals((GSSName) another);
88  			} catch (GSSException e) {
89  				; // Ignore
90  			}
91  
92  		return false;
93  	}
94  
95  	@Override
96  	public String toString() {
97  		return name;
98  	}
99  }