Search in sources :

Example 6 with SubjectUtils

use of ddf.security.service.impl.SubjectUtils in project ddf by codice.

the class RoleClaimsHandlerTest method testRetrieveClaimsValuesIgnoredReferences.

@Test
public void testRetrieveClaimsValuesIgnoredReferences() throws LdapException, SearchResultReferenceIOException {
    BindResult bindResult = mock(BindResult.class);
    ClaimsParameters claimsParameters;
    Connection connection = mock(Connection.class);
    ConnectionEntryReader membershipReader = mock(ConnectionEntryReader.class);
    ConnectionEntryReader groupNameReader = mock(ConnectionEntryReader.class);
    LinkedAttribute membershipAttribute = new LinkedAttribute("uid");
    LinkedAttribute groupNameAttribute = new LinkedAttribute("cn");
    ClaimsCollection processedClaims;
    RoleClaimsHandler claimsHandler;
    SearchResultEntry membershipSearchResult = mock(SearchResultEntry.class);
    DN resultDN = DN.valueOf("uid=tstark,");
    SearchResultEntry groupNameSearchResult = mock(SearchResultEntry.class);
    String groupName = "avengers";
    when(bindResult.isSuccess()).thenReturn(true);
    membershipAttribute.add("tstark");
    when(membershipSearchResult.getAttribute(anyString())).thenReturn(membershipAttribute);
    // simulate two items in the list (a reference and an entry)
    when(membershipReader.hasNext()).thenReturn(true, true, false);
    // test a reference followed by entries thereafter
    when(membershipReader.isEntry()).thenReturn(false, true);
    when(membershipReader.readEntry()).thenReturn(membershipSearchResult);
    when(membershipSearchResult.getName()).thenReturn(resultDN);
    groupNameAttribute.add(groupName);
    when(groupNameSearchResult.getAttribute(anyString())).thenReturn(groupNameAttribute);
    when(groupNameReader.hasNext()).thenReturn(true, true, false);
    when(groupNameReader.isEntry()).thenReturn(false, true);
    when(groupNameReader.readEntry()).thenReturn(groupNameSearchResult);
    when(connection.bind(any())).thenReturn(bindResult);
    when(connection.search(any(), any(), eq("(&(objectClass=groupOfNames)(|(member=uid=tstark,)(member=uid=tstark,)))"), any())).thenReturn(groupNameReader);
    when(connection.search(anyString(), any(), anyString(), matches("uid"))).thenReturn(membershipReader);
    claimsHandler = new RoleClaimsHandler(new AttributeMapLoader(new SubjectUtils()));
    ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class);
    when(mockConnectionFactory.getConnection()).thenReturn(connection);
    claimsHandler.setLdapConnectionFactory(mockConnectionFactory);
    claimsHandler.setBindMethod("Simple");
    claimsHandler.setBindUserCredentials("foo");
    claimsHandler.setBindUserDN("bar");
    claimsParameters = new ClaimsParametersImpl(new UserPrincipal(USER_CN), new HashSet<>(), new HashMap<>());
    processedClaims = claimsHandler.retrieveClaims(claimsParameters);
    assertThat(processedClaims, hasSize(1));
    Claim claim = processedClaims.get(0);
    assertThat(claim.getValues(), hasSize(1));
    assertThat(claim.getValues().get(0), equalTo(groupName));
}
Also used : SubjectUtils(ddf.security.service.impl.SubjectUtils) HashMap(java.util.HashMap) Connection(org.forgerock.opendj.ldap.Connection) DN(org.forgerock.opendj.ldap.DN) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UserPrincipal(org.apache.karaf.jaas.boot.principal.UserPrincipal) ClaimsParameters(ddf.security.claims.ClaimsParameters) LinkedAttribute(org.forgerock.opendj.ldap.LinkedAttribute) ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) ConnectionFactory(org.forgerock.opendj.ldap.ConnectionFactory) ClaimsParametersImpl(ddf.security.claims.impl.ClaimsParametersImpl) BindResult(org.forgerock.opendj.ldap.responses.BindResult) ClaimsCollection(ddf.security.claims.ClaimsCollection) Claim(ddf.security.claims.Claim) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with SubjectUtils

use of ddf.security.service.impl.SubjectUtils in project ddf by codice.

the class OidcLogoutActionProviderTest method setup.

@Before
public void setup() {
    oidcLogoutActionBuilder = mock(OidcLogoutActionBuilder.class);
    OidcHandlerConfiguration handlerConfiguration = mock(OidcHandlerConfiguration.class);
    when(handlerConfiguration.getOidcLogoutActionBuilder()).thenReturn(oidcLogoutActionBuilder);
    oidcLogoutActionProvider = new OidcLogoutActionProvider(handlerConfiguration);
    oidcLogoutActionProvider.setSubjectOperations(new SubjectUtils());
    request = mock(HttpServletRequest.class);
    response = mock(HttpServletResponse.class);
    subject = mock(Subject.class);
    HttpSession session = mock(HttpSession.class);
    PrincipalHolder principalHolderMock = mock(PrincipalHolder.class);
    SimplePrincipalCollection principalCollection = new SimplePrincipalCollection();
    SecurityAssertion securityAssertion = mock(SecurityAssertion.class);
    OidcProfile profile = mock(OidcProfile.class);
    when(securityAssertion.getToken()).thenReturn(profile);
    when(securityAssertion.getTokenType()).thenReturn(SecurityAssertionJwt.JWT_TOKEN_TYPE);
    when(subject.getPrincipals()).thenReturn(principalCollection);
    when(principalHolderMock.getPrincipals()).thenReturn(principalCollection);
    principalCollection.add(securityAssertion, "oidc");
    when(session.getAttribute(SecurityConstants.SECURITY_TOKEN_KEY)).thenReturn(principalHolderMock);
    when(request.getSession(false)).thenReturn(session);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) OidcHandlerConfiguration(org.codice.ddf.security.handler.api.OidcHandlerConfiguration) SubjectUtils(ddf.security.service.impl.SubjectUtils) OidcLogoutActionBuilder(org.pac4j.oidc.logout.OidcLogoutActionBuilder) HttpSession(javax.servlet.http.HttpSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) OidcProfile(org.pac4j.oidc.profile.OidcProfile) SecurityAssertion(ddf.security.assertion.SecurityAssertion) PrincipalHolder(ddf.security.common.PrincipalHolder) Subject(ddf.security.Subject) Before(org.junit.Before)

Example 8 with SubjectUtils

use of ddf.security.service.impl.SubjectUtils in project ddf by codice.

the class FilterPluginTest method testPluginFilterNoStrategies.

@Test
public void testPluginFilterNoStrategies() {
    plugin = new FilterPlugin(new Security());
    plugin.setPermissions(new PermissionsImpl());
    plugin.setSubjectOperations(new SubjectUtils());
    plugin.setSecurityLogger(mock(SecurityLogger.class));
    try {
        QueryResponse response = plugin.processPostQuery(incomingResponse);
        verifyFilterResponse(response);
    } catch (StopProcessingException e) {
        LOGGER.error("Stopped processing the redaction plugin", e);
    }
}
Also used : SubjectUtils(ddf.security.service.impl.SubjectUtils) FilterPlugin(ddf.catalog.security.filter.plugin.FilterPlugin) PermissionsImpl(ddf.security.permission.impl.PermissionsImpl) QueryResponse(ddf.catalog.operation.QueryResponse) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Security(org.codice.ddf.security.impl.Security) SecurityLogger(ddf.security.audit.SecurityLogger) Test(org.junit.Test)

Example 9 with SubjectUtils

use of ddf.security.service.impl.SubjectUtils in project ddf by codice.

the class AdminAlertImplTest method setup.

@Before
public void setup() throws Exception {
    adminAlert = new AdminAlertImpl(persistentStore, eventAdmin);
    adminAlert.setSubjectOperations(new SubjectUtils());
    solrMap = new HashMap<>();
    solrMap.put(SystemNotice.SYSTEM_NOTICE_ID_KEY + "_txt", "myId");
}
Also used : SubjectUtils(ddf.security.service.impl.SubjectUtils) Before(org.junit.Before)

Example 10 with SubjectUtils

use of ddf.security.service.impl.SubjectUtils in project ddf by codice.

the class ReliableResourceDownloadManagerTest method setup.

@Before
public void setup() {
    resourceCache = mock(ResourceCacheImpl.class);
    when(resourceCache.getProductCacheDirectory()).thenReturn(productCacheDirectory);
    eventPublisher = mock(DownloadsStatusEventPublisher.class);
    eventListener = mock(DownloadsStatusEventListener.class);
    downloadStatusInfo = new DownloadStatusInfoImpl();
    downloadStatusInfo.setSubjectOperations(new SubjectUtils());
    downloadMgr = new ReliableResourceDownloadManager(getDownloaderConfig(), downloadStatusInfo, Executors.newSingleThreadExecutor());
}
Also used : SubjectUtils(ddf.security.service.impl.SubjectUtils) ResourceCacheImpl(ddf.catalog.cache.impl.ResourceCacheImpl) DownloadStatusInfoImpl(ddf.catalog.event.retrievestatus.DownloadStatusInfoImpl) DownloadsStatusEventListener(ddf.catalog.event.retrievestatus.DownloadsStatusEventListener) DownloadsStatusEventPublisher(ddf.catalog.event.retrievestatus.DownloadsStatusEventPublisher) Before(org.junit.Before)

Aggregations

SubjectUtils (ddf.security.service.impl.SubjectUtils)20 Test (org.junit.Test)10 Metacard (ddf.catalog.data.Metacard)5 DownloadStatusInfoImpl (ddf.catalog.event.retrievestatus.DownloadStatusInfoImpl)5 Before (org.junit.Before)5 Action (ddf.action.Action)4 ResourceCacheImpl (ddf.catalog.cache.impl.ResourceCacheImpl)4 ResourceResponse (ddf.catalog.operation.ResourceResponse)4 HashMap (java.util.HashMap)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 ActionProvider (ddf.action.ActionProvider)3 Claim (ddf.security.claims.Claim)3 ClaimsCollection (ddf.security.claims.ClaimsCollection)3 ClaimsParameters (ddf.security.claims.ClaimsParameters)3 ClaimsParametersImpl (ddf.security.claims.impl.ClaimsParametersImpl)3 HashSet (java.util.HashSet)3 UserPrincipal (org.apache.karaf.jaas.boot.principal.UserPrincipal)3 MockInputStream (ddf.catalog.cache.MockInputStream)2 SecurityLoggerImpl (ddf.security.audit.impl.SecurityLoggerImpl)2 IOException (java.io.IOException)2