You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by le...@apache.org on 2007/10/12 08:48:00 UTC
svn commit: r584076 - in /harmony/enhanced/classlib/trunk/modules/auth/src:
main/java/common/org/apache/harmony/auth/jgss/
main/java/common/org/apache/harmony/auth/jgss/kerberos/
test/java/common/org/apache/harmony/auth/tests/jgss/ test/java/common/org...
Author: leoli
Date: Thu Oct 11 23:47:58 2007
New Revision: 584076
URL: http://svn.apache.org/viewvc?rev=584076&view=rev
Log:
Apply patch for HARMONY-4721 ([classlib][auth]Harmony lacks default JGSS provider)(1) JGSS framework.
Added:
harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/
harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSCredentialElement.java (with props)
harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSCredentialImpl.java (with props)
harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSManagerImpl.java (with props)
harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSMechSpi.java (with props)
harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSNameImpl.java (with props)
harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSUtils.java (with props)
harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/
harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosName.java (with props)
harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosProvider.java (with props)
harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosSpiImpl.java (with props)
harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosUtils.java (with props)
harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/
harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/GSSManagerImplTest.java (with props)
harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/GSSUtilsTest.java (with props)
harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/kerberos/
harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/kerberos/KerberosNameTest.java (with props)
Added: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSCredentialElement.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSCredentialElement.java?rev=584076&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSCredentialElement.java (added)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSCredentialElement.java Thu Oct 11 23:47:58 2007
@@ -0,0 +1,38 @@
+/*
+ * 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.harmony.auth.jgss;
+
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.GSSName;
+import org.ietf.jgss.Oid;
+
+public interface GSSCredentialElement {
+
+ public GSSName getName();
+
+ public Oid getMech();
+
+ public int getUsage();
+
+ public int getRemainingAcceptLifetime();
+
+ public int getRemainingInitLifetime();
+
+ public void dispose() throws GSSException;
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSCredentialElement.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSCredentialImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSCredentialImpl.java?rev=584076&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSCredentialImpl.java (added)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSCredentialImpl.java Thu Oct 11 23:47:58 2007
@@ -0,0 +1,289 @@
+/*
+ * 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.harmony.auth.jgss;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map.Entry;
+
+import org.ietf.jgss.GSSCredential;
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.GSSName;
+import org.ietf.jgss.Oid;
+
+public class GSSCredentialImpl implements GSSCredential {
+
+ private GSSCredentialElement defaultCredentialElement;
+
+ private HashMap<GSSCredentialType, GSSCredentialElement> credentials = new HashMap<GSSCredentialType, GSSCredentialElement>();
+
+ private boolean disposed;
+
+ private final GSSManagerImpl managerImpl;
+
+ public GSSCredentialImpl(GSSManagerImpl managerImpl) {
+ this.managerImpl = managerImpl;
+ }
+
+ public void add(GSSName name, int initLifetime, int acceptLifetime,
+ Oid mech, int usage) throws GSSException {
+ checkDisposed();
+
+ if (mech == null) {
+ mech = managerImpl.getDefaultMech();
+ }
+
+ GSSCredentialType credentialType = new GSSCredentialType(mech, usage);
+ if (credentials.containsKey(credentialType)) {
+ throw new GSSException(GSSException.DUPLICATE_ELEMENT,
+ GSSUtils.DEFAULT_GSSEXCEPTION_MINOR_CODE, mech + " "
+ + usage);
+ }
+
+ GSSCredentialElement credentialElement = managerImpl
+ .createCredentialElement(name, initLifetime, acceptLifetime,
+ mech, usage);
+ defaultCredentialElement = credentialElement;
+ credentials.put(credentialType, credentialElement);
+ }
+
+ public void dispose() throws GSSException {
+ if (disposed) {
+ return;
+ }
+
+ for (GSSCredentialElement credential : credentials.values()) {
+ credential.dispose();
+ }
+ disposed = true;
+ }
+
+ public Oid[] getMechs() throws GSSException {
+ checkDisposed();
+ ArrayList<Oid> mechs = new ArrayList<Oid>();
+ for (GSSCredentialType credentialType : credentials.keySet()) {
+ Oid mech = credentialType.mech;
+ if (!mechs.contains(mech)) {
+ mechs.add(mech);
+ }
+ }
+ return mechs.toArray(new Oid[mechs.size()]);
+ }
+
+ public GSSName getName() throws GSSException {
+ checkDisposed();
+ return defaultCredentialElement.getName();
+ }
+
+ public GSSName getName(Oid mech) throws GSSException {
+ checkDisposed();
+ GSSCredentialElement credential = null;
+ for (Entry<GSSCredentialType, GSSCredentialElement> entry : credentials
+ .entrySet()) {
+ if (entry.getKey().mech.equals(mech)) {
+ credential = entry.getValue();
+ break;
+ }
+ }
+ if (null == credential) {
+ throw new GSSException(GSSException.BAD_MECH,
+ GSSUtils.DEFAULT_GSSEXCEPTION_MINOR_CODE,
+ "fail to get name for " + mech);
+ }
+ return credential.getName();
+ }
+
+ public int getRemainingAcceptLifetime(Oid mech) throws GSSException {
+ checkDisposed();
+ GSSCredentialElement credential = null;
+ int remainingAcceptLifetime = Integer.MIN_VALUE;
+ credential = credentials.get(new GSSCredentialType(mech,
+ GSSCredential.INITIATE_ONLY));
+ if (credential != null) {
+ remainingAcceptLifetime = credential.getRemainingAcceptLifetime();
+ }
+ GSSCredentialElement tempCredential = credentials
+ .get(new GSSCredentialType(mech,
+ GSSCredential.INITIATE_AND_ACCEPT));
+ if (tempCredential != null) {
+ credential = tempCredential;
+ remainingAcceptLifetime = Math.max(remainingAcceptLifetime,
+ credential.getRemainingAcceptLifetime());
+ }
+
+ if (credential == null) {
+ throw new GSSException(GSSException.BAD_MECH,
+ GSSUtils.DEFAULT_GSSEXCEPTION_MINOR_CODE,
+ "no credential for mech " + mech);
+ }
+ return remainingAcceptLifetime;
+ }
+
+ public int getRemainingInitLifetime(Oid mech) throws GSSException {
+ checkDisposed();
+ GSSCredentialElement credential = null;
+ int remainingInitLifetime = Integer.MIN_VALUE;
+ credential = credentials.get(new GSSCredentialType(mech,
+ GSSCredential.INITIATE_ONLY));
+ if (credential != null) {
+ remainingInitLifetime = credential.getRemainingInitLifetime();
+ }
+ GSSCredentialElement tempCredential = credentials
+ .get(new GSSCredentialType(mech,
+ GSSCredential.INITIATE_AND_ACCEPT));
+ if (tempCredential != null) {
+ credential = tempCredential;
+ remainingInitLifetime = Math.max(remainingInitLifetime, credential
+ .getRemainingInitLifetime());
+ }
+
+ if (credential == null) {
+ throw new GSSException(GSSException.BAD_MECH,
+ GSSUtils.DEFAULT_GSSEXCEPTION_MINOR_CODE,
+ "no credential for mech " + mech);
+ }
+ return remainingInitLifetime;
+ }
+
+ public int getRemainingLifetime() throws GSSException {
+ checkDisposed();
+ int remainingLifeTime = GSSCredential.INDEFINITE_LIFETIME;
+ for (Entry<GSSCredentialType, GSSCredentialElement> credential : credentials
+ .entrySet()) {
+ GSSCredentialType credentialType = credential.getKey();
+ GSSCredentialElement credentialElement = credential.getValue();
+ int credentialRemainingLifeTime;
+ switch (credentialType.usage) {
+ case GSSCredential.INITIATE_ONLY:
+ credentialRemainingLifeTime = credentialElement
+ .getRemainingInitLifetime();
+ break;
+ case GSSCredential.ACCEPT_ONLY:
+ credentialRemainingLifeTime = credentialElement
+ .getRemainingAcceptLifetime();
+ break;
+ default: // INITIATE_AND_ACCEPT
+ credentialRemainingLifeTime = Math.min(credentialElement
+ .getRemainingInitLifetime(), credentialElement
+ .getRemainingAcceptLifetime());
+ break;
+ }
+ remainingLifeTime = Math.min(remainingLifeTime,
+ credentialRemainingLifeTime);
+
+ }
+ return remainingLifeTime;
+ }
+
+ public int getUsage() throws GSSException {
+ checkDisposed();
+ boolean isInitiate = false;
+ boolean isAccept = false;
+ for (GSSCredentialType credentialType : credentials.keySet()) {
+ switch (credentialType.usage) {
+ case GSSCredential.INITIATE_ONLY:
+ isInitiate = true;
+ break;
+ case GSSCredential.ACCEPT_ONLY:
+ isAccept = true;
+ break;
+ case GSSCredential.INITIATE_AND_ACCEPT:
+ isInitiate = isAccept = true;
+ }
+ }
+
+ if (isInitiate) {
+ if (isAccept) {
+ return GSSCredential.INITIATE_AND_ACCEPT;
+ }
+ return GSSCredential.INITIATE_ONLY;
+ }
+ if (isAccept) {
+ return GSSCredential.ACCEPT_ONLY;
+ }
+ throw new GSSException(GSSException.FAILURE,
+ GSSUtils.DEFAULT_GSSEXCEPTION_MINOR_CODE,
+ "no credential element in this credential");
+ }
+
+ public int getUsage(Oid mech) throws GSSException {
+ checkDisposed();
+ boolean isInitiate = false;
+ boolean isAccept = false;
+ for (GSSCredentialType credentialType : credentials.keySet()) {
+ if (credentialType.mech.equals(mech)) {
+ switch (credentialType.usage) {
+ case GSSCredential.INITIATE_ONLY:
+ isInitiate = true;
+ break;
+ case GSSCredential.ACCEPT_ONLY:
+ isAccept = true;
+ break;
+ case GSSCredential.INITIATE_AND_ACCEPT:
+ isInitiate = isAccept = true;
+ }
+ }
+ }
+
+ if (isInitiate) {
+ if (isAccept) {
+ return GSSCredential.INITIATE_AND_ACCEPT;
+ }
+ return GSSCredential.INITIATE_ONLY;
+ }
+ if (isAccept) {
+ return GSSCredential.ACCEPT_ONLY;
+ }
+ throw new GSSException(GSSException.BAD_MECH,
+ GSSUtils.DEFAULT_GSSEXCEPTION_MINOR_CODE,
+ "no credential for mech " + mech);
+ }
+
+ private void checkDisposed() throws GSSException {
+ if (disposed) {
+ throw new GSSException(GSSUtils.DEFAULT_GSSEXCEPTION_MAJOR_CODE,
+ GSSUtils.DEFAULT_GSSEXCEPTION_MINOR_CODE,
+ "credential disposed");
+ }
+ }
+
+ private static class GSSCredentialType {
+ public final Oid mech;
+
+ public final int usage;
+
+ public GSSCredentialType(Oid mech, int usage) {
+ this.mech = mech;
+ this.usage = usage;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof GSSCredentialType)) {
+ return false;
+ }
+ GSSCredentialType otherType = (GSSCredentialType) other;
+ return mech.equals(otherType.mech) && usage == otherType.usage;
+ }
+
+ @Override
+ public int hashCode() {
+ return mech.hashCode() + usage;
+ }
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSCredentialImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSManagerImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSManagerImpl.java?rev=584076&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSManagerImpl.java (added)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSManagerImpl.java Thu Oct 11 23:47:58 2007
@@ -0,0 +1,226 @@
+/*
+ * 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.harmony.auth.jgss;
+
+import java.security.Provider;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.apache.harmony.auth.jgss.kerberos.KerberosSpiImpl;
+import org.apache.harmony.auth.jgss.kerberos.KerberosProvider;
+import org.ietf.jgss.GSSContext;
+import org.ietf.jgss.GSSCredential;
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.GSSManager;
+import org.ietf.jgss.GSSName;
+import org.ietf.jgss.Oid;
+
+public class GSSManagerImpl extends GSSManager {
+
+ private static Oid DEFAULT_MECH;
+
+ private static Provider DEFAULT_PROVIDER = new KerberosProvider("kerberos provider", 0, "");
+
+ private static GSSMechSpi DEFAULT_API = new KerberosSpiImpl();
+
+
+ static {
+ try {
+ DEFAULT_MECH = new Oid("1.2.840.113554.1.2.2");
+ } catch (GSSException e) {
+
+ }
+ }
+
+ public GSSManagerImpl() throws GSSException{
+ addProviderAtFront(DEFAULT_PROVIDER, null);
+ }
+
+ private Hashtable<Oid, GSSMechSpi> spis = new Hashtable<Oid, GSSMechSpi>();
+
+ private static final String JGSSAPI = "GssApiMechanism.";
+
+ private void enumApisFromProvider(Provider p, Oid mech, boolean override) {
+ for (Entry entry : p.entrySet()) {
+ String key = (String) entry.getKey();
+
+ String value = (String) entry.getValue();
+
+ if (!key.startsWith(JGSSAPI)) {
+ continue;
+ }
+
+ String currentMechName = key.substring(JGSSAPI.length()).trim();
+ Oid currentMech;
+ try {
+ currentMech = new Oid(currentMechName);
+ } catch (GSSException e) {
+ continue;
+ }
+
+ if (mech != null && !mech.equals(currentMech)) {
+ continue;
+ }
+
+ if (!override && spis.get(currentMech) != null) {
+ continue;
+ }
+
+ GSSMechSpi gssApi;
+ try {
+ gssApi = (GSSMechSpi) Class.forName(value).newInstance();
+ } catch (Exception e) {
+ continue;
+ }
+ spis.put(currentMech, gssApi);
+ }
+ }
+
+ @Override
+ public void addProviderAtEnd(Provider p, Oid mech) throws GSSException {
+ enumApisFromProvider(p, mech, false);
+ }
+
+ @Override
+ public void addProviderAtFront(Provider p, Oid mech) throws GSSException {
+ enumApisFromProvider(p, mech, true);
+ }
+
+ @Override
+ public GSSContext createContext(GSSName peer, Oid mech,
+ GSSCredential myCred, int lifetime) throws GSSException {
+
+ return null;
+ }
+
+ @Override
+ public GSSContext createContext(GSSCredential myCred) throws GSSException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public GSSContext createContext(byte[] interProcessToken)
+ throws GSSException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public GSSCredential createCredential(int usage) throws GSSException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public GSSCredential createCredential(GSSName name, int lifetime, Oid mech,
+ int usage) throws GSSException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public GSSCredential createCredential(GSSName name, int lifetime,
+ Oid[] mechs, int usage) throws GSSException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public GSSName createName(String nameStr, Oid nameType) throws GSSException {
+ if(nameType != null && nameType.equals(GSSName.NT_EXPORT_NAME)){
+ return GSSNameImpl.importFromString(GSSUtils.getBytes(nameStr), this);
+ }
+ return DEFAULT_API.createName(nameStr, nameType);
+ }
+
+ @Override
+ public GSSName createName(byte[] name, Oid nameType) throws GSSException {
+ if (nameType != null && nameType.equals(GSSName.NT_EXPORT_NAME)) {
+ return GSSNameImpl.importFromString(name, this);
+ }
+ return DEFAULT_API.createName(GSSUtils.toString(name), nameType);
+ }
+
+ @Override
+ public GSSName createName(String nameStr, Oid nameType, Oid mech)
+ throws GSSException {
+ return createName(nameStr, nameType).canonicalize(mech);
+ }
+
+ @Override
+ public GSSName createName(byte[] name, Oid nameType, Oid mech)
+ throws GSSException {
+ return createName(GSSUtils.toString(name), nameType, mech);
+ }
+
+ @Override
+ public Oid[] getMechs() {
+ Set<Oid> oids = spis.keySet();
+ Oid[] mechs = new Oid[oids.size()];
+ int i = 0;
+ for (Oid oid : oids) {
+ mechs[i++] = oid;
+ }
+ return mechs;
+ }
+
+ @Override
+ public Oid[] getMechsForName(Oid nameType) {
+ ArrayList<Oid> mechs = new ArrayList<Oid>();
+ Oid[] oids = getMechs();
+ for (Oid oid : oids) {
+ GSSMechSpi api = spis.get(oid);
+ Oid[] mechNames = api.getNameMechs();
+ boolean support = false;
+ for (Oid mechName : mechNames) {
+ if (mechName.equals(nameType)) {
+ support = true;
+ break;
+ }
+ }
+ if (support) {
+ mechs.add(oid);
+ }
+ }
+ return mechs.toArray(new Oid[mechs.size()]);
+ }
+
+ @Override
+ public Oid[] getNamesForMech(Oid mech) throws GSSException {
+ GSSMechSpi api = getSpi(mech);
+ return api.getNameMechs();
+ }
+
+ GSSMechSpi getSpi(Oid mech){
+ return spis.get(mech);
+ }
+
+ Oid getDefaultMech(){
+ return DEFAULT_MECH;
+ }
+
+
+
+ GSSCredentialElement createCredentialElement(GSSName name, int initLifetime, int acceptLifetime, Oid mech, int usage) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSManagerImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSMechSpi.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSMechSpi.java?rev=584076&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSMechSpi.java (added)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSMechSpi.java Thu Oct 11 23:47:58 2007
@@ -0,0 +1,32 @@
+/*
+ * 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.harmony.auth.jgss;
+
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.GSSName;
+import org.ietf.jgss.Oid;
+
+public interface GSSMechSpi {
+
+ public Oid[] getNameMechs();
+
+ public GSSName createName(String name, Oid nameType) throws GSSException;
+
+ public GSSName createName(String name) throws GSSException;
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSMechSpi.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSNameImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSNameImpl.java?rev=584076&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSNameImpl.java (added)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSNameImpl.java Thu Oct 11 23:47:58 2007
@@ -0,0 +1,107 @@
+/*
+ * 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.harmony.auth.jgss;
+
+import org.apache.harmony.auth.jgss.GSSUtils;
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.GSSName;
+import org.ietf.jgss.Oid;
+
+public abstract class GSSNameImpl implements GSSName {
+private static final byte EXPORTED_TOKEN_FIRST_BYTE = 0x04;
+
+ private static final byte EXPORTED_TOKEN_SECOND_BYTE = 0x01;
+
+ private static final int EXPORTED_TOKEN_LENGTH = 2;
+
+ private static final int OID_LENGTH_ENCODED_LENGTH = 2;
+
+ private static final int NAME_LENGTH_ENCODED_LENGTH = 4;
+
+ private static final int FIX_CONTENT_LENGTH = EXPORTED_TOKEN_LENGTH + OID_LENGTH_ENCODED_LENGTH + NAME_LENGTH_ENCODED_LENGTH;
+
+
+
+ static GSSName importFromString(byte[] encodedGSSName,
+ GSSManagerImpl gssManagerImpl) throws GSSException {
+ byte[] encoded = encodedGSSName;
+ int index = 0;
+
+ if (encoded[index++] != EXPORTED_TOKEN_FIRST_BYTE
+ || encoded[index++] != EXPORTED_TOKEN_SECOND_BYTE) {
+ throw new GSSException(GSSUtils.DEFAULT_GSSEXCEPTION_MAJOR_CODE,
+ GSSUtils.DEFAULT_GSSEXCEPTION_MINOR_CODE,
+ "Illegal token in importing string to GSSName");
+ }
+
+ int oidLength = GSSUtils.toInt(encoded, index,
+ OID_LENGTH_ENCODED_LENGTH);
+ index += OID_LENGTH_ENCODED_LENGTH;
+
+ byte[] encodedMech = new byte[oidLength];
+ System.arraycopy(encoded, index, encodedMech, 0, oidLength);
+ index += oidLength;
+ Oid mech = new Oid(encodedMech);
+ GSSMechSpi gssApi = gssManagerImpl.getSpi(mech);
+
+ int nameLength = GSSUtils.toInt(encoded, index,
+ NAME_LENGTH_ENCODED_LENGTH);
+ index += NAME_LENGTH_ENCODED_LENGTH;
+
+ byte[] encodedName = new byte[nameLength];
+ System.arraycopy(encoded, index, encodedName, 0, nameLength);
+ String name = GSSUtils.toString(encodedName);
+ return gssApi.createName(name);
+ }
+
+ public boolean equals(Object o){
+ if( o instanceof GSSName){
+ try {
+ return equals((GSSName) o);
+ } catch (GSSException e) {
+ }
+ }
+ return false;
+ }
+
+ public byte[] export() throws GSSException {
+ byte[] name = exportMechDependent();
+ byte[] oid = getMech().getDER();
+
+ byte[] encoded = new byte[FIX_CONTENT_LENGTH + oid.length + name.length];
+ int index = 0;
+ encoded[index++] = EXPORTED_TOKEN_FIRST_BYTE;
+ encoded[index++] = EXPORTED_TOKEN_SECOND_BYTE;
+
+ byte[] oid_length = GSSUtils.getBytes(oid.length, OID_LENGTH_ENCODED_LENGTH);
+ System.arraycopy(oid_length, 0, encoded, index, OID_LENGTH_ENCODED_LENGTH);
+ index += OID_LENGTH_ENCODED_LENGTH;
+ System.arraycopy(oid, 0, encoded, index, oid.length);
+ index += oid.length;
+
+
+ byte[] name_length = GSSUtils.getBytes(name.length, NAME_LENGTH_ENCODED_LENGTH);
+ System.arraycopy(name_length, 0, encoded, index, NAME_LENGTH_ENCODED_LENGTH);
+ index += NAME_LENGTH_ENCODED_LENGTH;
+ System.arraycopy(name, 0, encoded, index, name.length);
+ return encoded;
+ }
+
+ protected abstract byte[] exportMechDependent() throws GSSException;
+ protected abstract Oid getMech();
+}
Propchange: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSNameImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSUtils.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSUtils.java?rev=584076&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSUtils.java (added)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSUtils.java Thu Oct 11 23:47:58 2007
@@ -0,0 +1,85 @@
+/*
+ * 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.harmony.auth.jgss;
+
+import java.io.UnsupportedEncodingException;
+
+import org.ietf.jgss.GSSException;
+
+public class GSSUtils {
+
+ public static final String DEFAULT_CHARSET_NAME = "UTF-8";
+
+ public static final int DEFAULT_GSSEXCEPTION_MAJOR_CODE = 3;
+
+ public static final int DEFAULT_GSSEXCEPTION_MINOR_CODE = 0;
+
+ public static String toString(byte[] bytes) throws GSSException {
+ try {
+ return new String(bytes, DEFAULT_CHARSET_NAME);
+ } catch (UnsupportedEncodingException e) {
+ throw new GSSException(DEFAULT_GSSEXCEPTION_MAJOR_CODE,
+ DEFAULT_GSSEXCEPTION_MINOR_CODE, e.getMessage());
+ }
+ }
+
+ public static byte[] getBytes(String s) throws GSSException {
+ try {
+ return s.getBytes(DEFAULT_CHARSET_NAME);
+ } catch (UnsupportedEncodingException e) {
+ throw new GSSException(DEFAULT_GSSEXCEPTION_MAJOR_CODE,
+ DEFAULT_GSSEXCEPTION_MINOR_CODE, e.getMessage());
+ }
+ }
+
+ public static byte[] getBytes(int source, int length) {
+ if (source < 0) {
+ throw new Error(
+ "org.apache.harmony.auth.jgss.GSSUtils.getBytes(int i, int length) does not support negative integer");
+ }
+ if (length <= 0 || length > 4) {
+ throw new Error(
+ "org.apache.harmony.auth.jgss.GSSUtils.getBytes(int i, int length) must have 0<length<=4");
+ }
+ byte[] target = new byte[length];
+ int shift = (length - 1) * 8;
+ for (int j = 0; j < length; j++) {
+ target[j] = (byte) (source >>> shift);
+ shift -=8;
+ }
+ return target;
+ }
+
+ public static int toInt(byte[] source, int offset, int length) {
+ if (length == 0 || length > 4) {
+ throw new Error(
+ "org.apache.harmony.auth.jgss.GSSUtils.toInt(byte[] source) must have 0<source.length<=4");
+ }
+ if (source[0] < 0) {
+ throw new Error(
+ "org.apache.harmony.auth.jgss.GSSUtils.toInt(byte[] source) does not support negative integer.");
+ }
+ int target = 0;
+ for (int index = offset; index <offset +length; index++) {
+ byte b = source[index];
+ target <<= 8;
+ target += (b & 0xFF);
+ }
+ return target;
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/GSSUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosName.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosName.java?rev=584076&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosName.java (added)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosName.java Thu Oct 11 23:47:58 2007
@@ -0,0 +1,129 @@
+/*
+ * 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.harmony.auth.jgss.kerberos;
+
+import org.apache.harmony.auth.jgss.GSSNameImpl;
+import org.apache.harmony.auth.jgss.GSSUtils;
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.GSSName;
+import org.ietf.jgss.Oid;
+
+/**
+ * Current the org.apache.harmony.auth.jgss.GSSNameImpl just supports kerberos
+ * related GSSName.
+ */
+public class KerberosName extends GSSNameImpl {
+
+ private String name;
+
+ private Oid nameType;
+
+ public KerberosName(String name, Oid nameType) throws GSSException {
+ if (null == name) {
+ throw new GSSException(KerberosUtils.DEFAULT_GSSEXCEPTION_MAJOR_CODE,
+ KerberosUtils.DEFAULT_GSSEXCEPTION_MINOR_CODE,
+ "Cannot import null GSSName");
+ }
+
+ if (null == nameType) {
+ nameType = KerberosUtils.KRB5_PRINCIPAL_NAMETYPE;
+ }
+
+ if(nameType.equals(GSSName.NT_HOSTBASED_SERVICE)){
+ name = name.replaceAll("@", "/");
+ }
+
+ if (!(nameType.equals(GSSName.NT_HOSTBASED_SERVICE)
+ || nameType.equals(GSSName.NT_USER_NAME) || nameType
+ .equals(KerberosUtils.KRB5_PRINCIPAL_NAMETYPE))) {
+ throw new GSSException(
+ KerberosUtils.DEFAULT_GSSEXCEPTION_MAJOR_CODE,
+ KerberosUtils.DEFAULT_GSSEXCEPTION_MINOR_CODE,
+ "Unsupported OID");
+ }
+ this.name = name;
+ this.nameType = nameType;
+ }
+
+ String getName() {
+ return name;
+ }
+
+ public GSSName canonicalize(Oid mech) throws GSSException {
+ return new KerberosName(getName(), mech);
+ }
+
+ public boolean equals(GSSName another) throws GSSException {
+ if (isAnonymous() && another.isAnonymous()) {
+ return true;
+ }
+
+ if (!(another instanceof KerberosName)) {
+
+ return false;
+ }
+
+ KerberosName anotherNameImpl = (KerberosName) another;
+ String thisName = getName();
+ String anotherName = anotherNameImpl.getName();
+
+ if (!thisName.equals(anotherName)) {
+ return false;
+ }
+
+ Oid thisOid = getStringNameType();
+ Oid anotherOid = anotherNameImpl.getStringNameType();
+
+ if (thisOid.equals(KerberosUtils.KRB5_PRINCIPAL_NAMETYPE)
+ || anotherOid.equals(KerberosUtils.KRB5_PRINCIPAL_NAMETYPE)) {
+ return true;
+ }
+ return thisOid.equals(anotherOid);
+ }
+
+
+
+ public Oid getStringNameType() throws GSSException {
+ return nameType;
+ }
+
+ // org.apache.harmoy.auth.jgss.GSSNameImpl actually does not support
+ // GSSNAME.NT_ANONYMOUS, so it always returns false.
+ public boolean isAnonymous() {
+ return nameType.equals(GSSName.NT_ANONYMOUS);
+ }
+
+ // org.apache.harmoy.auth.jgss.GSSNameImpl only supports MN GSSNAME.
+ public boolean isMN() {
+ return true;
+ }
+
+ public String toString(){
+ return name;
+ }
+
+ @Override
+ protected byte[] exportMechDependent() throws GSSException {
+ return GSSUtils.getBytes(name);
+ }
+
+ @Override
+ protected Oid getMech() {
+ return KerberosUtils.KRB5_MECH;
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosName.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosProvider.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosProvider.java?rev=584076&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosProvider.java (added)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosProvider.java Thu Oct 11 23:47:58 2007
@@ -0,0 +1,35 @@
+/*
+ * 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.harmony.auth.jgss.kerberos;
+
+import java.security.Provider;
+
+public class KerberosProvider extends Provider
+{
+
+ public KerberosProvider(String arg0, double arg1, String arg2) {
+ super(arg0, arg1, arg2);
+ this.put("GssApiMechanism.1.2.840.113554.1.2.2", "org.apache.harmony.auth.jgss.kerberos.KerberosSpiImpl");
+ }
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosSpiImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosSpiImpl.java?rev=584076&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosSpiImpl.java (added)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosSpiImpl.java Thu Oct 11 23:47:58 2007
@@ -0,0 +1,43 @@
+/*
+ * 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.harmony.auth.jgss.kerberos;
+
+import org.apache.harmony.auth.jgss.GSSMechSpi;
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.GSSName;
+import org.ietf.jgss.Oid;
+
+public class KerberosSpiImpl implements GSSMechSpi {
+
+ public GSSName createName(String name, Oid nameType) throws GSSException {
+ return new KerberosName(name, nameType);
+ }
+
+ public GSSName createName(String name) throws GSSException{
+ return createName(name, KerberosUtils.KRB5_PRINCIPAL_NAMETYPE);
+ }
+
+ public GSSName createName(byte[] encodedName){
+ return null;
+ }
+
+ public Oid[] getNameMechs(){
+ return KerberosUtils.SUPPORTED_NAME_MECHS;
+ }
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosSpiImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosUtils.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosUtils.java?rev=584076&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosUtils.java (added)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosUtils.java Thu Oct 11 23:47:58 2007
@@ -0,0 +1,50 @@
+/*
+ * 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.harmony.auth.jgss.kerberos;
+
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.GSSName;
+import org.ietf.jgss.Oid;
+
+public class KerberosUtils {
+ public static final String DEFAULT_CHARSET_NAME = "UTF-8";
+
+ public static final int DEFAULT_GSSEXCEPTION_MAJOR_CODE = 3;
+
+ public static final int DEFAULT_GSSEXCEPTION_MINOR_CODE = 0;
+
+ public static final Oid KRB5_MECH;
+
+ public static final Oid KRB5_PRINCIPAL_NAMETYPE;
+
+ public static final Oid[] SUPPORTED_NAME_MECHS;
+
+ static {
+ try {
+ KRB5_MECH = new Oid("1.2.840.113554.1.2.2");
+ KRB5_PRINCIPAL_NAMETYPE = new Oid("1.2.840.113554.1.2.2.1");
+
+ } catch (GSSException e) {
+ throw new Error();
+ }
+ SUPPORTED_NAME_MECHS = new Oid[] { GSSName.NT_USER_NAME,
+ GSSName.NT_HOSTBASED_SERVICE, GSSName.NT_EXPORT_NAME,
+ KRB5_PRINCIPAL_NAMETYPE };
+ }
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/KerberosUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/GSSManagerImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/GSSManagerImplTest.java?rev=584076&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/GSSManagerImplTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/GSSManagerImplTest.java Thu Oct 11 23:47:58 2007
@@ -0,0 +1,121 @@
+/*
+ * 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.harmony.auth.tests.jgss;
+
+import java.util.Arrays;
+
+import org.apache.harmony.auth.jgss.kerberos.KerberosUtils;
+import org.ietf.jgss.GSSManager;
+import org.ietf.jgss.GSSName;
+import org.ietf.jgss.Oid;
+
+import junit.framework.TestCase;
+
+public class GSSManagerImplTest extends TestCase {
+
+ private GSSManager gssManager;
+
+ public void testGetMechs() throws Exception{
+ Oid[] mechs = gssManager.getMechs();
+ Oid kerberosMech = new Oid("1.2.840.113554.1.2.2");
+ Oid[] expectedMechs = new Oid[]{kerberosMech};
+ assertTrue(Arrays.equals(expectedMechs, mechs));
+ }
+
+ public void testGetMechsForName() throws Exception {
+ Oid nameType = GSSName.NT_ANONYMOUS;
+ Oid[] mechs = gssManager.getMechsForName(nameType);
+ assertEquals(0, mechs.length);
+
+ nameType = GSSName.NT_MACHINE_UID_NAME;
+ mechs = gssManager.getMechsForName(nameType);
+ assertEquals(0, mechs.length);
+
+ nameType = GSSName.NT_STRING_UID_NAME;
+ mechs = gssManager.getMechsForName(nameType);
+ assertEquals(0, mechs.length);
+
+ nameType = GSSName.NT_USER_NAME;
+ mechs = gssManager.getMechsForName(nameType);
+ Oid kerberosMech = new Oid("1.2.840.113554.1.2.2");
+ Oid[] expectedMechs = new Oid[] { kerberosMech };
+ assertTrue(Arrays.equals(expectedMechs, mechs));
+
+ nameType = GSSName.NT_HOSTBASED_SERVICE;
+ mechs = gssManager.getMechsForName(nameType);
+ assertTrue(Arrays.equals(expectedMechs, mechs));
+
+ nameType = GSSName.NT_EXPORT_NAME;
+ mechs = gssManager.getMechsForName(nameType);
+ assertTrue(Arrays.equals(expectedMechs, mechs));
+
+ nameType = KerberosUtils.KRB5_PRINCIPAL_NAMETYPE;
+ mechs = gssManager.getMechsForName(nameType);
+ assertTrue(Arrays.equals(expectedMechs, mechs));
+ }
+
+ public void testGetNamesForMech() throws Exception {
+ Oid kerberosMech = new Oid("1.2.840.113554.1.2.2");
+ Oid[] nameTypes = gssManager.getNamesForMech(kerberosMech);
+ Oid[] expectedNameTypes = new Oid[] { GSSName.NT_USER_NAME,
+ GSSName.NT_HOSTBASED_SERVICE, GSSName.NT_EXPORT_NAME,
+ KerberosUtils.KRB5_PRINCIPAL_NAMETYPE };
+ assertEquals(expectedNameTypes.length, nameTypes.length);
+ for (Oid expectedNameType : expectedNameTypes) {
+ boolean got = false;
+ for (Oid nameType : nameTypes) {
+ if (nameType.equals(expectedNameType)) {
+ got = true;
+ break;
+ }
+ }
+ if (!got) {
+ fail("Missing expected NameType " + expectedNameType);
+ }
+ }
+ }
+
+ public void testCreateName() throws Exception {
+
+ GSSName gssName = gssManager.createName("username",
+ GSSName.NT_USER_NAME);
+ assertEquals(GSSName.NT_USER_NAME, gssName.getStringNameType());
+
+ gssName = gssManager.createName("service@host",
+ GSSName.NT_HOSTBASED_SERVICE);
+ assertEquals(GSSName.NT_HOSTBASED_SERVICE, gssName.getStringNameType());
+
+ final Oid kerberosPrincipalOid = new Oid("1.2.840.113554.1.2.2.1");
+ gssName = gssManager.createName("kerberosPrincipal",
+ kerberosPrincipalOid);
+ assertEquals(kerberosPrincipalOid, gssName.getStringNameType());
+
+ byte[] encoded = new byte[] { 4, 1, 0, 11, 6, 9, 42, -122, 72, -122,
+ -9, 18, 1, 2, 2, 0, 0, 0, 17, 115, 101, 114, 118, 105, 99, 101,
+ 47, 108, 111, 99, 97, 108, 104, 111, 115, 116 };
+ gssName = gssManager.createName(encoded, GSSName.NT_EXPORT_NAME);
+ assertEquals(kerberosPrincipalOid, gssName.getStringNameType());
+ GSSName expectedGSSName = gssManager.createName("service/localhost", kerberosPrincipalOid);
+ assertEquals(expectedGSSName, gssName);
+ }
+
+ public void setUp() throws Exception{
+ gssManager = GSSManager.getInstance();
+ }
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/GSSManagerImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/GSSUtilsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/GSSUtilsTest.java?rev=584076&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/GSSUtilsTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/GSSUtilsTest.java Thu Oct 11 23:47:58 2007
@@ -0,0 +1,57 @@
+/*
+ * 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.harmony.auth.tests.jgss;
+
+import org.apache.harmony.auth.jgss.GSSUtils;
+
+import junit.framework.TestCase;
+
+public class GSSUtilsTest extends TestCase {
+
+ public void testGSSUtils_getBytes_and_getInt() throws Exception {
+ int i = 0x7F;
+ byte[] bytes = GSSUtils.getBytes(i, 1);
+ int j = GSSUtils.toInt(bytes, 0 , 1);
+ assertEquals(i, j);
+
+ i = 0x0F;
+ bytes = GSSUtils.getBytes(i, 1);
+ j = GSSUtils.toInt(bytes, 0 , 1);
+ assertEquals(i, j);
+
+ i = 0x01FF;
+ bytes = GSSUtils.getBytes(i, 2);
+ j = GSSUtils.toInt(bytes, 0, 2);
+ assertEquals(i, j);
+
+ i = 0x0503;
+ bytes = GSSUtils.getBytes(i, 2);
+ j = GSSUtils.toInt(bytes, 0, 2);
+ assertEquals(i, j);
+
+ i = 0x05804E;
+ bytes = GSSUtils.getBytes(i, 3);
+ j = GSSUtils.toInt(bytes, 0 , 3);
+ assertEquals(i, j);
+
+ i = 0x0580E2;
+ bytes = GSSUtils.getBytes(i, 4);
+ j = GSSUtils.toInt(bytes, 0, 4);
+ assertEquals(i, j);
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/GSSUtilsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/kerberos/KerberosNameTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/kerberos/KerberosNameTest.java?rev=584076&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/kerberos/KerberosNameTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/kerberos/KerberosNameTest.java Thu Oct 11 23:47:58 2007
@@ -0,0 +1,84 @@
+/*
+ * 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.harmony.auth.tests.jgss.kerberos;
+
+import java.util.Arrays;
+
+import org.apache.harmony.auth.jgss.kerberos.KerberosName;
+import org.ietf.jgss.GSSName;
+import org.ietf.jgss.Oid;
+
+import junit.framework.TestCase;
+
+public class KerberosNameTest extends TestCase {
+
+
+ public void testExport() throws Exception {
+ KerberosName kerberosName = new KerberosName("service@localhost", GSSName.NT_HOSTBASED_SERVICE);
+ byte[] exported = kerberosName.export();
+ byte[] expected = new byte[] { 4,1,0,11,6,9,42,-122,72,-122,-9,18,1,2,2,0,0,0,17,115,101,114,118,105,99,101,47,108,111,99,97,108,104,111,115,116 };
+ assertTrue(Arrays.equals(expected, exported));
+ }
+
+ public void testEquals() throws Exception{
+ KerberosName one = new KerberosName("service@localhost", GSSName.NT_HOSTBASED_SERVICE);
+ KerberosName another = new KerberosName("service@localhost", GSSName.NT_HOSTBASED_SERVICE);
+ assertEquals(one, another);
+
+ one = new KerberosName("service@localhost", GSSName.NT_HOSTBASED_SERVICE);
+ another = new KerberosName("service/localhost", GSSName.NT_HOSTBASED_SERVICE);
+ assertEquals(one, another);
+
+ one = new KerberosName("service@localhost", GSSName.NT_USER_NAME);
+ another = new KerberosName("service@localhost", GSSName.NT_USER_NAME);
+ assertEquals(one, another);
+
+ one = new KerberosName("service@localhost", GSSName.NT_USER_NAME);
+ another = new KerberosName("service/localhost", GSSName.NT_USER_NAME);
+ assertFalse(one.equals(another));
+
+ final Oid KRB5_PRINCIPAL_NAMETYPE = new Oid("1.2.840.113554.1.2.2.1");
+ one = new KerberosName("service@localhost", KRB5_PRINCIPAL_NAMETYPE);
+ another = new KerberosName("service@localhost", KRB5_PRINCIPAL_NAMETYPE);
+ assertEquals(one, another);
+
+ one = new KerberosName("service@localhost", KRB5_PRINCIPAL_NAMETYPE);
+ another = new KerberosName("service/localhost",KRB5_PRINCIPAL_NAMETYPE);
+ assertFalse(one.equals(another));
+
+ one = new KerberosName("service@localhost", KRB5_PRINCIPAL_NAMETYPE);
+ another = new KerberosName("service@localhost", GSSName.NT_USER_NAME);
+ assertEquals(one,another);
+
+ one = new KerberosName("service@localhost", KRB5_PRINCIPAL_NAMETYPE);
+ another = new KerberosName("service@localhost", GSSName.NT_HOSTBASED_SERVICE);
+ assertFalse(one.equals(another));
+
+ one = new KerberosName("service/localhost", KRB5_PRINCIPAL_NAMETYPE);
+ another = new KerberosName("service@localhost", GSSName.NT_HOSTBASED_SERVICE);
+ assertEquals(one,another);
+
+ one = new KerberosName("service@localhost", GSSName.NT_USER_NAME);
+ another = new KerberosName("service@localhost", GSSName.NT_HOSTBASED_SERVICE);
+ assertFalse(one.equals(another));
+
+ one = new KerberosName("service/localhost", GSSName.NT_USER_NAME);
+ another = new KerberosName("service@localhost", GSSName.NT_HOSTBASED_SERVICE);
+ assertFalse(one.equals(another));
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/jgss/kerberos/KerberosNameTest.java
------------------------------------------------------------------------------
svn:eol-style = native