001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.client;
017:
018: import java.io.IOException;
019: import java.io.ObjectInput;
020: import java.io.ObjectOutput;
021:
022: public class AuthenticationResponse implements Response {
023:
024: private transient int responseCode = -1;
025: private transient ClientMetaData identity;
026: private transient ServerMetaData server;
027: private transient Throwable deniedCause;
028:
029: public AuthenticationResponse() {
030: }
031:
032: public AuthenticationResponse(int code) {
033: responseCode = code;
034: }
035:
036: public int getResponseCode() {
037: return responseCode;
038: }
039:
040: public ClientMetaData getIdentity() {
041: return identity;
042: }
043:
044: public ServerMetaData getServer() {
045: return server;
046: }
047:
048: public void setResponseCode(int responseCode) {
049: this .responseCode = responseCode;
050: }
051:
052: public void setIdentity(ClientMetaData identity) {
053: this .identity = identity;
054: }
055:
056: public void setServer(ServerMetaData server) {
057: this .server = server;
058: }
059:
060: public Throwable getDeniedCause() {
061: return deniedCause;
062: }
063:
064: public void setDeniedCause(Throwable deniedCause) {
065: this .deniedCause = deniedCause;
066: }
067:
068: public void readExternal(ObjectInput in) throws IOException,
069: ClassNotFoundException {
070: byte version = in.readByte(); // future use
071:
072: responseCode = in.readByte();
073: switch (responseCode) {
074: case ResponseCodes.AUTH_GRANTED:
075: identity = new ClientMetaData();
076: identity.readExternal(in);
077: break;
078: case ResponseCodes.AUTH_REDIRECT:
079: identity = new ClientMetaData();
080: identity.readExternal(in);
081: server = new ServerMetaData();
082: server.readExternal(in);
083: break;
084: case ResponseCodes.AUTH_DENIED:
085: ThrowableArtifact ta = new ThrowableArtifact();
086: ta.readExternal(in);
087: deniedCause = ta.getThrowable();
088: break;
089: }
090: }
091:
092: public void writeExternal(ObjectOutput out) throws IOException {
093: // write out the version of the serialized data for future use
094: out.writeByte(1);
095:
096: out.writeByte((byte) responseCode);
097: switch (responseCode) {
098: case ResponseCodes.AUTH_GRANTED:
099: identity.writeExternal(out);
100: break;
101: case ResponseCodes.AUTH_REDIRECT:
102: identity.writeExternal(out);
103: server.writeExternal(out);
104: break;
105: case ResponseCodes.AUTH_DENIED:
106: ThrowableArtifact ta = new ThrowableArtifact(deniedCause);
107: ta.writeExternal(out);
108: break;
109: }
110: }
111:
112: public String toString() {
113: StringBuilder sb = new StringBuilder(50);
114:
115: switch (responseCode) {
116: case ResponseCodes.AUTH_GRANTED: {
117: sb.append("AUTH_GRANTED:");
118: sb.append(identity);
119: break;
120: }
121: case ResponseCodes.AUTH_REDIRECT: {
122: sb.append("AUTH_REDIRECT:");
123: sb.append(server);
124: break;
125: }
126: case ResponseCodes.AUTH_DENIED: {
127: sb.append("AUTH_DENIED:");
128: sb.append(deniedCause.toString());
129: break;
130: }
131: }
132: return sb.toString();
133: }
134:
135: }
|