Search in sources :

Example 51 with Subject

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;
    }
}
Also used : Subject(org.apache.shiro.subject.Subject)

Example 52 with Subject

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();
}
Also used : Subject(org.apache.shiro.subject.Subject) Test(org.junit.Test)

Example 53 with Subject

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("");
}
Also used : Subject(org.apache.shiro.subject.Subject)

Example 54 with Subject

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;
}
Also used : AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) GeodeAuthenticationToken(org.apache.geode.internal.security.shiro.GeodeAuthenticationToken) Subject(org.apache.shiro.subject.Subject) ShiroException(org.apache.shiro.ShiroException)

Example 55 with Subject

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;
}
Also used : GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) ShiroPrincipal(org.apache.geode.internal.security.shiro.ShiroPrincipal) Subject(org.apache.shiro.subject.Subject)

Aggregations

Subject (org.apache.shiro.subject.Subject)78 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)11 Test (org.junit.Test)9 IOException (java.io.IOException)8 Map (java.util.Map)8 Path (javax.ws.rs.Path)8 StopProcessingException (ddf.catalog.plugin.StopProcessingException)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 AccountVO (com.netsteadfast.greenstep.vo.AccountVO)5 Attribute (ddf.catalog.data.Attribute)5 KeyValueCollectionPermission (ddf.security.permission.KeyValueCollectionPermission)5 GET (javax.ws.rs.GET)5 AuthenticationException (org.apache.shiro.authc.AuthenticationException)5 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)4 Metacard (ddf.catalog.data.Metacard)4 ApiOperation (io.swagger.annotations.ApiOperation)4 POST (javax.ws.rs.POST)4 PersistenceException (org.codice.ddf.persistence.PersistenceException)4