Search in sources :

Example 6 with ServiceContext

use of org.omg.IOP.ServiceContext in project wildfly by wildfly.

the class SASTargetInterceptor method receive_request.

@Override
public void receive_request(ServerRequestInfo ri) {
    IIOPLogger.ROOT_LOGGER.tracef("receive_request: %s", ri.operation());
    CurrentRequestInfo threadLocal = threadLocalData.get();
    threadLocal.sasContextReceived = false;
    threadLocal.authenticationTokenReceived = false;
    threadLocal.incomingUsername = empty;
    threadLocal.incomingPassword = empty;
    threadLocal.incomingTargetName = empty;
    threadLocal.incomingIdentity = absent;
    threadLocal.incomingPrincipalName = empty;
    threadLocal.sasReply = null;
    threadLocal.sasReplyIsAccept = false;
    try {
        ServiceContext sc = ri.get_request_service_context(sasContextId);
        Any any = codec.decode_value(sc.context_data, SASContextBodyHelper.type());
        SASContextBody contextBody = SASContextBodyHelper.extract(any);
        if (contextBody != null) {
            if (contextBody.discriminator() == MTMessageInContext.value) {
                // should not happen, as stateful context requests are always negotiated down to stateless in this implementation.
                long contextId = contextBody.in_context_msg().client_context_id;
                threadLocal.sasReply = createMsgCtxError(contextId, 4);
                throw IIOPLogger.ROOT_LOGGER.missingSASContext();
            } else if (contextBody.discriminator() == MTEstablishContext.value) {
                EstablishContext message = contextBody.establish_msg();
                threadLocal.contextId = message.client_context_id;
                threadLocal.sasContextReceived = true;
                if (message.client_authentication_token != null && message.client_authentication_token.length > 0) {
                    IIOPLogger.ROOT_LOGGER.trace("Received client authentication token");
                    InitialContextToken authToken = CSIv2Util.decodeInitialContextToken(message.client_authentication_token, codec);
                    if (authToken == null) {
                        threadLocal.sasReply = createMsgCtxError(message.client_context_id, 2);
                        throw IIOPLogger.ROOT_LOGGER.errorDecodingInitContextToken();
                    }
                    threadLocal.incomingUsername = authToken.username;
                    threadLocal.incomingPassword = authToken.password;
                    threadLocal.incomingTargetName = CSIv2Util.decodeGssExportedName(authToken.target_name);
                    if (threadLocal.incomingTargetName == null) {
                        threadLocal.sasReply = createMsgCtxError(message.client_context_id, 2);
                        throw IIOPLogger.ROOT_LOGGER.errorDecodingTargetInContextToken();
                    }
                    threadLocal.authenticationTokenReceived = true;
                }
                if (message.identity_token != null) {
                    IIOPLogger.ROOT_LOGGER.trace("Received identity token");
                    threadLocal.incomingIdentity = message.identity_token;
                    if (message.identity_token.discriminator() == ITTPrincipalName.value) {
                        // Extract the RFC2743-encoded name from CDR encapsulation.
                        Any a = codec.decode_value(message.identity_token.principal_name(), GSS_NT_ExportedNameHelper.type());
                        byte[] encodedName = GSS_NT_ExportedNameHelper.extract(a);
                        // Decode the principal name.
                        threadLocal.incomingPrincipalName = CSIv2Util.decodeGssExportedName(encodedName);
                        if (threadLocal.incomingPrincipalName == null) {
                            threadLocal.sasReply = createMsgCtxError(message.client_context_id, 2);
                            throw IIOPLogger.ROOT_LOGGER.errorDecodingPrincipalName();
                        }
                    }
                }
                threadLocal.sasReply = (threadLocal.contextId == 0) ? msgCtx0Accepted : createMsgCtxAccepted(threadLocal.contextId);
                threadLocal.sasReplyIsAccept = true;
            }
        }
    } catch (BAD_PARAM e) {
    // no service context with sasContextId: do nothing.
    } catch (FormatMismatch e) {
        throw IIOPLogger.ROOT_LOGGER.errorDecodingContextData(this.name(), e);
    } catch (TypeMismatch e) {
        throw IIOPLogger.ROOT_LOGGER.errorDecodingContextData(this.name(), e);
    }
}
Also used : ServiceContext(org.omg.IOP.ServiceContext) InitialContextToken(org.omg.GSSUP.InitialContextToken) BAD_PARAM(org.omg.CORBA.BAD_PARAM) SASContextBody(org.omg.CSI.SASContextBody) CompleteEstablishContext(org.omg.CSI.CompleteEstablishContext) EstablishContext(org.omg.CSI.EstablishContext) MTEstablishContext(org.omg.CSI.MTEstablishContext) Any(org.omg.CORBA.Any) FormatMismatch(org.omg.IOP.CodecPackage.FormatMismatch) TypeMismatch(org.omg.IOP.CodecPackage.TypeMismatch)

Example 7 with ServiceContext

use of org.omg.IOP.ServiceContext in project wildfly by wildfly.

the class SASTargetInterceptor method send_reply.

@Override
public void send_reply(ServerRequestInfo ri) {
    IIOPLogger.ROOT_LOGGER.tracef("send_reply: %s", ri.operation());
    CurrentRequestInfo threadLocal = (CurrentRequestInfo) threadLocalData.get();
    if (threadLocal.sasReply != null) {
        try {
            ServiceContext sc = new ServiceContext(sasContextId, codec.encode_value(threadLocal.sasReply));
            ri.add_reply_service_context(sc, true);
        } catch (InvalidTypeForEncoding e) {
            throw IIOPLogger.ROOT_LOGGER.unexpectedException(e);
        }
    }
}
Also used : ServiceContext(org.omg.IOP.ServiceContext) InvalidTypeForEncoding(org.omg.IOP.CodecPackage.InvalidTypeForEncoding)

Example 8 with ServiceContext

use of org.omg.IOP.ServiceContext in project wildfly by wildfly.

the class SASTargetInterceptor method send_exception.

@Override
public void send_exception(ServerRequestInfo ri) {
    IIOPLogger.ROOT_LOGGER.tracef("send_exception: %s", ri.operation());
    CurrentRequestInfo threadLocal = (CurrentRequestInfo) threadLocalData.get();
    // The CSIv2 spec does not explicitly disallow an SAS accept in an IIOP exception reply.
    if (threadLocal.sasReply != null) {
        try {
            ServiceContext sc = new ServiceContext(sasContextId, codec.encode_value(threadLocal.sasReply));
            ri.add_reply_service_context(sc, true);
        } catch (InvalidTypeForEncoding e) {
            throw IIOPLogger.ROOT_LOGGER.unexpectedException(e);
        }
    }
}
Also used : ServiceContext(org.omg.IOP.ServiceContext) InvalidTypeForEncoding(org.omg.IOP.CodecPackage.InvalidTypeForEncoding)

Example 9 with ServiceContext

use of org.omg.IOP.ServiceContext in project wildfly by wildfly.

the class TxServerInterceptor method receive_request_service_contexts.

public void receive_request_service_contexts(ServerRequestInfo ri) {
    IIOPLogger.ROOT_LOGGER.tracef("Intercepting receive_request_service_contexts, operation: %s", ri.operation());
    try {
        ServiceContext sc = ri.get_request_service_context(txContextId);
        Any any = codec.decode_value(sc.context_data, PropagationContextHelper.type());
        ri.set_slot(slotId, any);
    } catch (BAD_PARAM e) {
    // no service context with txContextId: do nothing
    } catch (FormatMismatch e) {
        throw IIOPLogger.ROOT_LOGGER.errorDecodingContextData(this.name(), e);
    } catch (TypeMismatch e) {
        throw IIOPLogger.ROOT_LOGGER.errorDecodingContextData(this.name(), e);
    } catch (InvalidSlot e) {
        throw IIOPLogger.ROOT_LOGGER.errorSettingSlotInTxInterceptor(e);
    }
}
Also used : ServiceContext(org.omg.IOP.ServiceContext) BAD_PARAM(org.omg.CORBA.BAD_PARAM) InvalidSlot(org.omg.PortableInterceptor.InvalidSlot) Any(org.omg.CORBA.Any) FormatMismatch(org.omg.IOP.CodecPackage.FormatMismatch) TypeMismatch(org.omg.IOP.CodecPackage.TypeMismatch)

Example 10 with ServiceContext

use of org.omg.IOP.ServiceContext in project wildfly by wildfly.

the class SASClientIdentityInterceptor method receive_exception.

@Override
public void receive_exception(ClientRequestInfo ri) {
    try {
        ServiceContext sc = ri.get_reply_service_context(sasContextId);
        Any msg = codec.decode_value(sc.context_data, SASContextBodyHelper.type());
        SASContextBody contextBody = SASContextBodyHelper.extract(msg);
        // At this point contextBody may contain either a CompleteEstablishContext message or a ContextError message.
        // Neither message requires any treatment. We decoded the contextbody just to check that it contains a
        // well-formed message.
        IIOPLogger.ROOT_LOGGER.tracef("receive_exception: got SAS reply, type %d", contextBody.discriminator());
    } catch (BAD_PARAM e) {
    // no service context with sasContextId: do nothing.
    } catch (FormatMismatch e) {
        throw IIOPLogger.ROOT_LOGGER.errorParsingSASReply(e, 0, CompletionStatus.COMPLETED_MAYBE);
    } catch (TypeMismatch e) {
        throw IIOPLogger.ROOT_LOGGER.errorParsingSASReply(e, 0, CompletionStatus.COMPLETED_MAYBE);
    }
}
Also used : ServiceContext(org.omg.IOP.ServiceContext) BAD_PARAM(org.omg.CORBA.BAD_PARAM) SASContextBody(org.omg.CSI.SASContextBody) Any(org.omg.CORBA.Any) FormatMismatch(org.omg.IOP.CodecPackage.FormatMismatch) TypeMismatch(org.omg.IOP.CodecPackage.TypeMismatch)

Aggregations

ServiceContext (org.omg.IOP.ServiceContext)13 Any (org.omg.CORBA.Any)11 SASContextBody (org.omg.CSI.SASContextBody)10 BAD_PARAM (org.omg.CORBA.BAD_PARAM)8 FormatMismatch (org.omg.IOP.CodecPackage.FormatMismatch)8 TypeMismatch (org.omg.IOP.CodecPackage.TypeMismatch)8 EstablishContext (org.omg.CSI.EstablishContext)4 InvalidTypeForEncoding (org.omg.IOP.CodecPackage.InvalidTypeForEncoding)4 Principal (java.security.Principal)3 CompoundSecMech (org.omg.CSIIOP.CompoundSecMech)3 InitialContextToken (org.omg.GSSUP.InitialContextToken)3 IdentityToken (org.omg.CSI.IdentityToken)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)1 RunAs (org.jboss.security.RunAs)1 LocalObject (org.omg.CORBA.LocalObject)1 CompleteEstablishContext (org.omg.CSI.CompleteEstablishContext)1 MTEstablishContext (org.omg.CSI.MTEstablishContext)1 InvalidSlot (org.omg.PortableInterceptor.InvalidSlot)1