use of org.apache.shiro.subject.Subject in project graylog2-server by Graylog2.
the class ShiroSecurityContext method loginSubject.
public void loginSubject() throws AuthenticationException {
subject.login(token);
// the subject instance will change to include the session
final Subject newSubject = ThreadContext.getSubject();
if (newSubject != null) {
subject = newSubject;
}
}
use of org.apache.shiro.subject.Subject in project graylog2-server by Graylog2.
the class ShiroPrincipalTest method testGetNameWithNull.
@Test
public void testGetNameWithNull() throws Exception {
final Subject subject = mock(Subject.class);
final ShiroPrincipal shiroPrincipal = new ShiroPrincipal(subject);
assertThat(shiroPrincipal.getName()).isNull();
}
use of org.apache.shiro.subject.Subject in project vaadin-samples by xpoft.
the class MainView method enter.
@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
Subject subject = SecurityUtils.getSubject();
usernameLabel.setValue((String) subject.getPrincipal());
//rolesLabel.setValue("");
}
use of org.apache.shiro.subject.Subject in project geode by apache.
the class IntegratedSecurityService method login.
/**
* @return null if security is not enabled, otherwise return a shiro subject
*/
public Subject login(Properties credentials) {
if (!isIntegratedSecurity()) {
return null;
}
if (credentials == null)
return null;
// this makes sure it starts with a clean user object
ThreadContext.remove();
Subject currentUser = SecurityUtils.getSubject();
GeodeAuthenticationToken token = new GeodeAuthenticationToken(credentials);
try {
logger.debug("Logging in " + token.getPrincipal());
currentUser.login(token);
} catch (ShiroException e) {
logger.info(e.getMessage(), e);
throw new AuthenticationFailedException("Authentication error. Please check your credentials.", e);
}
return currentUser;
}
use of org.apache.shiro.subject.Subject in project geode by apache.
the class IntegratedSecurityService method getSubject.
/**
* It first looks the shiro subject in AccessControlContext since JMX will use multiple threads to
* process operations from the same client, then it looks into Shiro's thead context.
*
* @return the shiro subject, null if security is not enabled
*/
public Subject getSubject() {
if (!isIntegratedSecurity()) {
return null;
}
Subject currentUser = null;
// First try get the principal out of AccessControlContext instead of Shiro's Thread context
// since threads can be shared between JMX clients.
javax.security.auth.Subject jmxSubject = javax.security.auth.Subject.getSubject(AccessController.getContext());
if (jmxSubject != null) {
Set<ShiroPrincipal> principals = jmxSubject.getPrincipals(ShiroPrincipal.class);
if (principals.size() > 0) {
ShiroPrincipal principal = principals.iterator().next();
currentUser = principal.getSubject();
ThreadContext.bind(currentUser);
return currentUser;
}
}
// in other cases like rest call, client operations, we get it from the current thread
currentUser = SecurityUtils.getSubject();
if (currentUser == null || currentUser.getPrincipal() == null) {
throw new GemFireSecurityException("Error: Anonymous User");
}
return currentUser;
}
Aggregations