use of javax.security.auth.Subject in project orientdb by orientechnologies.
the class OKerberosCredentialInterceptor method intercept.
public void intercept(final String url, final String principal, final String spn) throws OSecurityException {
// it may contain multiple principals.
if (principal == null || principal.isEmpty())
throw new OSecurityException("OKerberosCredentialInterceptor Principal cannot be null!");
this.principal = principal;
String actualSPN = spn;
// spn should be the SPN of the service.
if (spn == null || spn.isEmpty()) {
// OrientDB/host
if (url == null || url.isEmpty())
throw new OSecurityException("OKerberosCredentialInterceptor URL and SPN cannot both be null!");
try {
String tempURL = url;
// Without the // URI can't parse URLs correctly, so we add //.
if (tempURL.startsWith("remote:") && !tempURL.startsWith("remote://"))
tempURL = tempURL.replace("remote:", "remote://");
URI remoteURI = new URI(tempURL);
String host = remoteURI.getHost();
if (host == null)
throw new OSecurityException("OKerberosCredentialInterceptor Could not create SPN from URL: " + url);
actualSPN = "OrientDB/" + host;
} catch (URISyntaxException ex) {
throw new OSecurityException("OKerberosCredentialInterceptor Could not create SPN from URL: " + url);
}
}
// Defaults to the environment variable.
String config = System.getenv("KRB5_CONFIG");
String ckc = OGlobalConfiguration.CLIENT_KRB5_CONFIG.getValueAsString();
if (ckc != null)
config = ckc;
// Defaults to the environment variable.
String ccname = System.getenv("KRB5CCNAME");
String ccn = OGlobalConfiguration.CLIENT_KRB5_CCNAME.getValueAsString();
if (ccn != null)
ccname = ccn;
// Defaults to the environment variable.
String ktname = System.getenv("KRB5_CLIENT_KTNAME");
String ckn = OGlobalConfiguration.CLIENT_KRB5_KTNAME.getValueAsString();
if (ckn != null)
ktname = ckn;
if (config == null)
throw new OSecurityException("OKerberosCredentialInterceptor KRB5 Config cannot be null!");
if (ccname == null && ktname == null)
throw new OSecurityException("OKerberosCredentialInterceptor KRB5 Credential Cache and KeyTab cannot both be null!");
LoginContext lc = null;
try {
System.setProperty("java.security.krb5.conf", config);
OKrb5ClientLoginModuleConfig cfg = new OKrb5ClientLoginModuleConfig(principal, ccname, ktname);
lc = new LoginContext("ignore", null, null, cfg);
lc.login();
} catch (LoginException lie) {
OLogManager.instance().debug(this, "intercept() LoginException", lie);
throw new OSecurityException("OKerberosCredentialInterceptor Client Validation Exception!");
}
Subject subject = lc.getSubject();
// Assign the client's principal name.
// this.principal = getFirstPrincipal(subject);
// if(this.principal == null) throw new OSecurityException("OKerberosCredentialInterceptor Cannot obtain client principal!");
this.serviceTicket = getServiceTicket(subject, principal, actualSPN);
try {
lc.logout();
} catch (LoginException loe) {
OLogManager.instance().debug(this, "intercept() LogoutException", loe);
}
if (this.serviceTicket == null)
throw new OSecurityException("OKerberosCredentialInterceptor Cannot obtain the service ticket!");
}
use of javax.security.auth.Subject in project powermock by powermock.
the class GitHub668Test method shouldMockJavaxSystemFinalClasses.
@Test
public void shouldMockJavaxSystemFinalClasses() {
Subject subject = mock(Subject.class);
final HashSet<Object> value = new HashSet<Object>();
when(subject.getPrivateCredentials()).thenReturn(value);
assertThat(subject.getPrivateCredentials()).isSameAs(value);
}
use of javax.security.auth.Subject in project presto by prestodb.
the class KerberosAuthentication method getSubject.
public Subject getSubject() {
Subject subject = new Subject(false, ImmutableSet.of(principal), emptySet(), emptySet());
try {
LoginContext loginContext = new LoginContext("", subject, null, configuration);
loginContext.login();
return loginContext.getSubject();
} catch (LoginException e) {
throw Throwables.propagate(e);
}
}
use of javax.security.auth.Subject in project robovm by robovm.
the class myPrivilegedExceptionAction method test_doAsPrivileged_01.
/**
* javax.security.auth.Subject#doAsPrivileged(Subject subject,
* PrivilegedAction action,
* AccessControlContext acc)
*/
public void test_doAsPrivileged_01() {
Subject subj = new Subject();
PrivilegedAction<Object> pa = new myPrivilegedAction();
PrivilegedAction<Object> paNull = null;
AccessControlContext acc = AccessController.getContext();
try {
Object obj = Subject.doAsPrivileged(null, pa, acc);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
try {
Object obj = Subject.doAsPrivileged(subj, pa, acc);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
try {
Object obj = Subject.doAsPrivileged(subj, paNull, acc);
fail("NullPointerException wasn't thrown");
} catch (NullPointerException npe) {
}
}
use of javax.security.auth.Subject in project robovm by robovm.
the class myPrivilegedExceptionAction method test_doAs_01.
/**
* javax.security.auth.Subject#doAs(Subject subject, PrivilegedAction action)
*/
public void test_doAs_01() {
Subject subj = new Subject();
PrivilegedAction<Object> pa = new myPrivilegedAction();
PrivilegedAction<Object> paNull = null;
try {
Object obj = Subject.doAs(null, pa);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
try {
Object obj = Subject.doAs(subj, pa);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
try {
Object obj = Subject.doAs(subj, paNull);
fail("NullPointerException wasn't thrown");
} catch (NullPointerException npe) {
}
}
Aggregations