use of javax.security.auth.Subject in project robovm by robovm.
the class myPrivilegedExceptionAction method test_doAs_02.
/**
* javax.security.auth.Subject#doAs(Subject subject, PrivilegedExceptionAction action)
*/
public void test_doAs_02() {
Subject subj = new Subject();
PrivilegedExceptionAction<Object> pea = new myPrivilegedExceptionAction();
PrivilegedExceptionAction<Object> peaNull = null;
try {
Object obj = Subject.doAs(null, pea);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
try {
Object obj = Subject.doAs(subj, pea);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
try {
Object obj = Subject.doAs(subj, peaNull);
fail("NullPointerException wasn't thrown");
} catch (NullPointerException npe) {
} catch (Exception e) {
fail(e + " was thrown instead of NullPointerException");
}
try {
Subject.doAs(subj, new PrivilegedExceptionAction<Object>() {
public Object run() throws PrivilegedActionException {
throw new PrivilegedActionException(null);
}
});
fail("PrivilegedActionException wasn't thrown");
} catch (PrivilegedActionException e) {
}
}
use of javax.security.auth.Subject in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testInitSecurityAwarePrototypeBean.
@SuppressWarnings("unchecked")
@Test
public void testInitSecurityAwarePrototypeBean() {
final DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(TestSecuredBean.class);
bd.setScope(ConfigurableBeanFactory.SCOPE_PROTOTYPE);
bd.setInitMethodName("init");
lbf.registerBeanDefinition("test", bd);
final Subject subject = new Subject();
subject.getPrincipals().add(new TestPrincipal("user1"));
TestSecuredBean bean = (TestSecuredBean) Subject.doAsPrivileged(subject, new PrivilegedAction() {
@Override
public Object run() {
return lbf.getBean("test");
}
}, null);
assertNotNull(bean);
assertEquals("user1", bean.getUserName());
}
use of javax.security.auth.Subject in project spring-framework by spring-projects.
the class CallbacksSecurityTests method testInitSecurityAwarePrototypeBean.
@Test
public void testInitSecurityAwarePrototypeBean() {
final DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(NonPrivilegedBean.class).setScope(ConfigurableBeanFactory.SCOPE_PROTOTYPE).setInitMethodName("init").setDestroyMethodName("destroy").addConstructorArgValue("user1");
lbf.registerBeanDefinition("test", bdb.getBeanDefinition());
final Subject subject = new Subject();
subject.getPrincipals().add(new TestPrincipal("user1"));
NonPrivilegedBean bean = Subject.doAsPrivileged(subject, new PrivilegedAction<NonPrivilegedBean>() {
@Override
public NonPrivilegedBean run() {
return lbf.getBean("test", NonPrivilegedBean.class);
}
}, null);
assertNotNull(bean);
}
use of javax.security.auth.Subject in project jstorm by alibaba.
the class BlobStoreTest method getSubject.
public Subject getSubject(String name) {
Subject subject = new Subject();
SingleUserPrincipal user = new SingleUserPrincipal(name);
subject.getPrincipals().add(user);
return subject;
}
use of javax.security.auth.Subject in project jstorm by alibaba.
the class KerberosSaslTransportPlugin method getServerTransportFactory.
public TTransportFactory getServerTransportFactory() throws IOException {
// create an authentication callback handler
CallbackHandler server_callback_handler = new ServerCallbackHandler(login_conf, storm_conf);
// login our principal
Subject subject = null;
try {
// specify a configuration object to be used
Configuration.setConfiguration(login_conf);
// now login
Login login = new Login(AuthUtils.LOGIN_CONTEXT_SERVER, server_callback_handler);
subject = login.getSubject();
} catch (LoginException ex) {
LOG.error("Server failed to login in principal:" + ex, ex);
throw new RuntimeException(ex);
}
// check the credential of our principal
if (subject.getPrivateCredentials(KerberosTicket.class).isEmpty()) {
throw new RuntimeException("Fail to verify user principal with section \"" + AuthUtils.LOGIN_CONTEXT_SERVER + "\" in login configuration file " + login_conf);
}
String principal = AuthUtils.get(login_conf, AuthUtils.LOGIN_CONTEXT_SERVER, "principal");
LOG.debug("principal:" + principal);
KerberosName serviceKerberosName = new KerberosName(principal);
String serviceName = serviceKerberosName.getServiceName();
String hostName = serviceKerberosName.getHostName();
Map<String, String> props = new TreeMap<String, String>();
props.put(Sasl.QOP, "auth");
props.put(Sasl.SERVER_AUTH, "false");
// create a transport factory that will invoke our auth callback for digest
TSaslServerTransport.Factory factory = new TSaslServerTransport.Factory();
factory.addServerDefinition(KERBEROS, serviceName, hostName, props, server_callback_handler);
// create a wrap transport factory so that we could apply user credential during connections
TUGIAssumingTransportFactory wrapFactory = new TUGIAssumingTransportFactory(factory, subject);
LOG.info("SASL GSSAPI transport factory will be used");
return wrapFactory;
}
Aggregations