You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by er...@apache.org on 2004/11/03 20:24:57 UTC
svn commit: rev 56515 - in incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw: . io
Author: erodriguez
Date: Wed Nov 3 11:24:57 2004
New Revision: 56515
Added:
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/ChangePasswordErrorService.java
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/io/ChangePasswordErrorEncoder.java
Log:
Error message handling for change password service.
Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/ChangePasswordErrorService.java
==============================================================================
--- (empty file)
+++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/ChangePasswordErrorService.java Wed Nov 3 11:24:57 2004
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.kerberos.changepw;
+
+import org.apache.kerberos.changepw.messages.*;
+import org.apache.kerberos.kdc.*;
+import org.apache.kerberos.messages.*;
+import org.apache.kerberos.messages.value.*;
+
+public class ChangePasswordErrorService {
+
+ private KdcConfiguration _config;
+
+ public ChangePasswordErrorService(KdcConfiguration config) {
+ _config = config;
+ }
+
+ public ChangePasswordError getReplyFor(KerberosException exception) {
+
+ ErrorMessage errorMessage = getErrorMessage(exception);
+
+ ChangePasswordErrorModifier modifier = new ChangePasswordErrorModifier();
+ modifier.setErrorMessage(errorMessage);
+
+ return modifier.getChangePasswordError();
+ }
+
+ // TODO - near duplicate with main KDC error service; refactor
+ public ErrorMessage getErrorMessage(KerberosException exception) {
+ ErrorMessageModifier modifier = new ErrorMessageModifier();
+
+ KerberosTime now = new KerberosTime();
+
+ modifier.setErrorCode(exception.getOrdinal());
+ modifier.setExplanatoryText(exception.getMessage());
+
+ // this is the only difference with main KDC error service; refactor
+ modifier.setServerPrincipal(_config.getChangepwPrincipal());
+
+ modifier.setServerTime(now);
+ modifier.setServerMicroSecond(0);
+
+ return modifier.getErrorMessage();
+ }
+}
+
Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/io/ChangePasswordErrorEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/io/ChangePasswordErrorEncoder.java Wed Nov 3 11:24:57 2004
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.kerberos.changepw.io;
+
+import org.apache.kerberos.changepw.messages.*;
+import org.apache.kerberos.io.encoder.*;
+import org.apache.kerberos.messages.*;
+
+import java.io.*;
+import java.nio.*;
+
+public class ChangePasswordErrorEncoder {
+
+ public byte[] encode(ChangePasswordError message) throws IOException {
+
+ // Build error message bytes
+ ErrorMessage errorMessage = message.getErrorMessage();
+ ErrorMessageEncoder errorEncoder = new ErrorMessageEncoder();
+ byte[] errorBytes = errorEncoder.encode(errorMessage);
+
+ ByteBuffer buf = ByteBuffer.allocate(512);
+
+ short headerLength = 6;
+
+ short messageLength = (short)(headerLength + errorBytes.length);
+
+ short protocolVersion = 1;
+ short zeroIndicatesError = 0;
+
+ buf.putShort(messageLength);
+ buf.putShort(protocolVersion);
+ buf.putShort(zeroIndicatesError);
+
+ buf.put(errorBytes);
+
+ byte[] reply = new byte[buf.position()];
+ buf.rewind();
+ buf.get(reply, 0, reply.length);
+
+ return reply;
+ }
+}
+