1 22 package org.jboss.ejb.plugins; 23 24 import java.security.Principal ; 25 import javax.net.ssl.SSLSession; 26 import javax.net.ssl.SSLPeerUnverifiedException; 27 import java.security.cert.X509Certificate ; 28 import org.jboss.invocation.Invocation; 29 30 import org.jboss.security.ssl.DomainServerSocketFactory; 31 import org.jboss.security.CertificatePrincipal; 32 import org.jboss.security.auth.certs.SubjectDNMapping; 33 34 43 public class SSLSessionInterceptor extends AbstractInterceptor 44 { 45 46 private CertificatePrincipal cpMapping = new SubjectDNMapping(); 47 48 private String sessionIDKey = "SESSION_ID"; 49 50 public Object invokeHome(Invocation mi) throws Exception 51 { 52 extractSessionPrincipal(mi); 53 Object returnValue = getNext().invoke(mi); 54 return returnValue; 55 } 56 57 public CertificatePrincipal getPrincialMapping() 58 { 59 return cpMapping; 60 } 61 62 public void setPrincialMapping(CertificatePrincipal cpMapping) 63 { 64 this.cpMapping = cpMapping; 65 } 66 67 public String getSessionIDKey() 68 { 69 return sessionIDKey; 70 } 71 72 public void setSessionIDKey(String sessionIDKey) 73 { 74 this.sessionIDKey = sessionIDKey; 75 } 76 77 public Object invoke(Invocation mi) throws Exception 78 { 79 extractSessionPrincipal(mi); 80 Object returnValue = getNext().invoke(mi); 81 return returnValue; 82 } 83 84 92 private void extractSessionPrincipal(Invocation mi) 93 throws SSLPeerUnverifiedException 94 { 95 String sessionID = (String ) mi.getValue(sessionIDKey); 96 if( sessionID != null ) 97 { 98 SSLSession session = DomainServerSocketFactory.getSSLSession(sessionID); 99 if( session != null ) 100 { 101 X509Certificate [] certs = (X509Certificate []) session.getPeerCertificates(); 102 Principal caller = cpMapping.toPrinicipal(certs); 103 mi.setPrincipal(caller); 104 mi.setCredential(certs); 105 } 106 } 107 } 108 } 109 | Popular Tags |