Search in sources :

Example 1 with PrincipalHolder

use of ddf.security.common.PrincipalHolder in project ddf by codice.

the class LogoutServiceImplTest method initialize.

@BeforeClass
public static void initialize() {
    sessionFactory = mock(SessionFactory.class);
    HttpSession httpSession = mock(HttpSession.class);
    PrincipalHolder principalHolder = mock(PrincipalHolder.class);
    sm = mock(SecurityManager.class);
    when(sessionFactory.getOrCreateSession(null)).thenReturn(httpSession);
    when(httpSession.getAttribute(SecurityConstants.SECURITY_TOKEN_KEY)).thenReturn(principalHolder);
    when(principalHolder.getPrincipals()).thenReturn(new SimplePrincipalCollection());
}
Also used : SessionFactory(ddf.security.http.SessionFactory) SecurityManager(ddf.security.service.SecurityManager) HttpSession(javax.servlet.http.HttpSession) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) PrincipalHolder(ddf.security.common.PrincipalHolder) BeforeClass(org.junit.BeforeClass)

Example 2 with PrincipalHolder

use of ddf.security.common.PrincipalHolder in project ddf by codice.

the class LogoutServiceImpl method getActionProviders.

@Override
public String getActionProviders(HttpServletRequest request, HttpServletResponse response) throws SecurityServiceException {
    HttpSession session = httpSessionFactory.getOrCreateSession(request);
    Object principalCollection = ((PrincipalHolder) session.getAttribute(SecurityConstants.SECURITY_TOKEN_KEY)).getPrincipals();
    SessionToken sessionToken = new SessionToken(principalCollection, session.getId(), "127.0.0.1");
    Subject subject = securityManager.getSubject(sessionToken);
    Map<String, Object> subjectMap = new HashMap<>();
    subjectMap.put("http_request", request);
    subjectMap.put("http_response", response);
    subjectMap.put(SecurityConstants.SECURITY_SUBJECT, subject);
    Map<String, String> actionProperties = new HashMap<>();
    for (ActionProvider actionProvider : logoutActionProviders) {
        Action action = actionProvider.getAction(subjectMap);
        if (action != null) {
            String displayName = subjectOperations.getName(subject, "", true);
            actionProperties.put("title", action.getTitle());
            actionProperties.put("auth", displayName);
            actionProperties.put("description", action.getDescription());
            actionProperties.put("url", action.getUrl().toString());
        }
    }
    return GSON.toJson(actionProperties);
}
Also used : ActionProvider(ddf.action.ActionProvider) Action(ddf.action.Action) SessionToken(org.codice.ddf.security.handler.SessionToken) HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) PrincipalHolder(ddf.security.common.PrincipalHolder) Subject(org.apache.shiro.subject.Subject)

Example 3 with PrincipalHolder

use of ddf.security.common.PrincipalHolder in project ddf by codice.

the class LogoutServletTest method testNullSubject.

@Test()
public void testNullSubject() throws Exception {
    ThreadContext.bind((Subject) null);
    // Used for detecting basic auth
    when(request.getHeaders(anyString())).thenReturn(new LogoutServletEnumeration());
    // used for detecting pki
    when(request.getAttribute("javax.servlet.request.X509Certificate")).thenReturn(new X509Certificate[] { mock(X509Certificate.class) });
    PrincipalHolder principalHolderMock = mock(PrincipalHolder.class);
    when(httpSession.getAttribute(SecurityConstants.SECURITY_TOKEN_KEY)).thenReturn(principalHolderMock);
    localLogoutServlet.doGet(request, response);
    verify(httpSession).invalidate();
}
Also used : PrincipalHolder(ddf.security.common.PrincipalHolder) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test)

Example 4 with PrincipalHolder

use of ddf.security.common.PrincipalHolder in project ddf by codice.

the class LogoutServletTest method testNullSystemProperty.

@Test
public void testNullSystemProperty() throws Exception {
    // Used for detecting basic auth
    when(request.getHeaders(anyString())).thenReturn(new LogoutServletEnumeration());
    // used for detecting pki
    when(request.getAttribute("javax.servlet.request.X509Certificate")).thenReturn(new X509Certificate[] { mock(X509Certificate.class) });
    PrincipalHolder principalHolderMock = mock(PrincipalHolder.class);
    when(httpSession.getAttribute(SecurityConstants.SECURITY_TOKEN_KEY)).thenReturn(principalHolderMock);
    localLogoutServlet.doGet(request, response);
    verify(httpSession).invalidate();
}
Also used : PrincipalHolder(ddf.security.common.PrincipalHolder) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test)

Example 5 with PrincipalHolder

use of ddf.security.common.PrincipalHolder in project ddf by codice.

the class LogoutServletTest method testLocalLogout.

@Test
public void testLocalLogout() throws Exception {
    PrincipalHolder principalHolderMock = mock(PrincipalHolder.class);
    when(principalHolderMock.getPrincipals()).thenReturn(mock(PrincipalCollection.class));
    when(httpSession.getAttribute(SecurityConstants.SECURITY_TOKEN_KEY)).thenReturn(principalHolderMock);
    localLogoutServlet.doGet(request, response);
    verify(httpSession).invalidate();
    verify(response).sendRedirect("https://localhost:8993/logout?mustCloseBrowser=true");
    verify(principalHolderMock).remove();
}
Also used : PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) PrincipalHolder(ddf.security.common.PrincipalHolder) Test(org.junit.Test)

Aggregations

PrincipalHolder (ddf.security.common.PrincipalHolder)17 HttpSession (javax.servlet.http.HttpSession)12 Test (org.junit.Test)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 SecurityAssertion (ddf.security.assertion.SecurityAssertion)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)4 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)4 HandlerResult (org.codice.ddf.security.handler.api.HandlerResult)4 Before (org.junit.Before)3 SessionFactory (ddf.security.http.SessionFactory)2 X509Certificate (java.security.cert.X509Certificate)2 ServletRequest (javax.servlet.ServletRequest)2 ServletResponse (javax.servlet.ServletResponse)2 SecurityFilterChain (org.codice.ddf.platform.filter.SecurityFilterChain)2 BaseAuthenticationToken (org.codice.ddf.security.handler.BaseAuthenticationToken)2 HandlerResultImpl (org.codice.ddf.security.handler.HandlerResultImpl)2 SessionToken (org.codice.ddf.security.handler.SessionToken)2 AuthenticationHandler (org.codice.ddf.security.handler.api.AuthenticationHandler)2 ContextPolicy (org.codice.ddf.security.policy.context.ContextPolicy)2