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));
}
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);
}
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);
}
}
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");
}
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());
}
Aggregations