Skip to content

Commit

Permalink
Fix some EJB/CORBA issues
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Feb 22, 2017
1 parent d124152 commit 17ed05b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Expand Up @@ -28,6 +28,7 @@
import java.security.AccessController; import java.security.AccessController;
import java.security.Principal; import java.security.Principal;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
Expand Down Expand Up @@ -326,7 +327,11 @@ public OutputStream _invoke(final String opName, final InputStream in, final Res
} }
final InterceptorContext interceptorContext = new InterceptorContext(); final InterceptorContext interceptorContext = new InterceptorContext();
this.prepareInterceptorContext(op, params, interceptorContext); this.prepareInterceptorContext(op, params, interceptorContext);
retVal = identity.runAs((PrivilegedExceptionAction<Object>) () -> this.componentView.invoke(interceptorContext)); try {
retVal = identity.runAs((PrivilegedExceptionAction<Object>) () -> this.componentView.invoke(interceptorContext));
} catch (PrivilegedActionException e) {
throw e.getCause();
}
} else { } else {
// legacy security behavior: setup the security context if a SASCurrent is available and invoke the component. // legacy security behavior: setup the security context if a SASCurrent is available and invoke the component.
// One of the EJB security interceptors will authenticate and authorize the client. // One of the EJB security interceptors will authenticate and authorize the client.
Expand Down Expand Up @@ -380,7 +385,7 @@ public OutputStream _invoke(final String opName, final InputStream in, final Res
if (op.isNonVoid()) { if (op.isNonVoid()) {
op.writeRetval(out, retVal); op.writeRetval(out, retVal);
} }
} catch (Exception e) { } catch (Throwable e) {
EjbLogger.ROOT_LOGGER.trace("Exception in EJBObject invocation", e); EjbLogger.ROOT_LOGGER.trace("Exception in EJBObject invocation", e);
if (e instanceof MBeanException) { if (e instanceof MBeanException) {
e = ((MBeanException) e).getTargetException(); e = ((MBeanException) e).getTargetException();
Expand Down
Expand Up @@ -25,6 +25,7 @@
import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback; import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback; import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;


import com.sun.corba.se.impl.interceptors.ClientRequestInfoImpl; import com.sun.corba.se.impl.interceptors.ClientRequestInfoImpl;
import com.sun.corba.se.impl.transport.SocketOrChannelContactInfoImpl; import com.sun.corba.se.impl.transport.SocketOrChannelContactInfoImpl;
Expand Down Expand Up @@ -161,6 +162,9 @@ public void send_request(ClientRequestInfo ri) throws ForwardRequest {
IdentityToken identityToken = ABSENT_IDENTITY_TOKEN; IdentityToken identityToken = ABSENT_IDENTITY_TOKEN;
byte[] encodedAuthenticationToken = NO_AUTHENTICATION_TOKEN; byte[] encodedAuthenticationToken = NO_AUTHENTICATION_TOKEN;
final URI uri = this.getURI(ri); final URI uri = this.getURI(ri);
if(uri == null) {
return;
}


AuthenticationContext authContext = this.authContext == null ? AuthenticationContext.captureCurrent() : this.authContext; AuthenticationContext authContext = this.authContext == null ? AuthenticationContext.captureCurrent() : this.authContext;


Expand Down Expand Up @@ -315,7 +319,11 @@ private URI getURI(final ClientRequestInfo clientRequestInfo) throws URISyntaxEx
final StringBuilder builder = new StringBuilder("iiop:"); final StringBuilder builder = new StringBuilder("iiop:");
if (clientRequestInfo instanceof ClientRequestInfoImpl) { if (clientRequestInfo instanceof ClientRequestInfoImpl) {
ClientRequestInfoImpl infoImpl = (ClientRequestInfoImpl) clientRequestInfo; ClientRequestInfoImpl infoImpl = (ClientRequestInfoImpl) clientRequestInfo;
ContactInfo info = ((CorbaConnection) infoImpl.connection()).getContactInfo(); CorbaConnection connection = (CorbaConnection) infoImpl.connection();
if(connection == null) {
return null;
}
ContactInfo info = connection.getContactInfo();
if (info instanceof SocketOrChannelContactInfoImpl) { if (info instanceof SocketOrChannelContactInfoImpl) {
String hostname = ((SocketOrChannelContactInfoImpl) info).getHost(); String hostname = ((SocketOrChannelContactInfoImpl) info).getHost();
if (hostname != null) if (hostname != null)
Expand All @@ -324,6 +332,8 @@ private URI getURI(final ClientRequestInfo clientRequestInfo) throws URISyntaxEx
if (port > 0) if (port > 0)
builder.append(":").append(port); builder.append(":").append(port);
} }
} else {
return null;
} }
return new URI(builder.toString()); return new URI(builder.toString());
} }
Expand All @@ -349,7 +359,11 @@ private byte[] createInitialContextToken(final URI uri, final String purpose, fi
final CallbackHandler handler = AUTH_CONFIG_CLIENT.getCallbackHandler(configuration); final CallbackHandler handler = AUTH_CONFIG_CLIENT.getCallbackHandler(configuration);
final NameCallback nameCallback = new NameCallback("Username: "); final NameCallback nameCallback = new NameCallback("Username: ");
final PasswordCallback passwordCallback = new PasswordCallback("Password: ", false); final PasswordCallback passwordCallback = new PasswordCallback("Password: ", false);
handler.handle(new Callback[]{nameCallback, passwordCallback}); try {
handler.handle(new Callback[]{nameCallback, passwordCallback});
} catch (UnsupportedCallbackException e) {
return NO_AUTHENTICATION_TOKEN;
}


// if the name callback contains a valid username we create the initial context token. // if the name callback contains a valid username we create the initial context token.
if (nameCallback.getName() != null && !nameCallback.getName().equals(AnonymousPrincipal.getInstance().getName())) { if (nameCallback.getName() != null && !nameCallback.getName().equals(AnonymousPrincipal.getInstance().getName())) {
Expand Down
Expand Up @@ -454,7 +454,7 @@ public static boolean isAbstractValueType(Class type) {
return cannotBeRemote && cannotBeAbstractInterface; return cannotBeRemote && cannotBeAbstractInterface;
} }


public static void rethrowIfCorbaSystemException(Exception e) { public static void rethrowIfCorbaSystemException(Throwable e) {
if (e instanceof java.rmi.MarshalException) if (e instanceof java.rmi.MarshalException)
throw new org.omg.CORBA.MARSHAL(e.toString()); throw new org.omg.CORBA.MARSHAL(e.toString());
else if (e instanceof java.rmi.NoSuchObjectException) else if (e instanceof java.rmi.NoSuchObjectException)
Expand Down
Expand Up @@ -157,7 +157,7 @@ public void writeRetval(OutputStream out, Object retVal) {
* @param out a CDR output stream * @param out a CDR output stream
* @param e the exception to be written. * @param e the exception to be written.
*/ */
public void writeException(OutputStream out, Exception e) { public void writeException(OutputStream out, Throwable e) {
int len = excepWriters.length; int len = excepWriters.length;
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
if (excepWriters[i].getExceptionClass().isInstance(e)) { if (excepWriters[i].getExceptionClass().isInstance(e)) {
Expand Down

0 comments on commit 17ed05b

Please sign in to comment.