use of ddf.security.SubjectUtils.NAME_IDENTIFIER_CLAIM_URI in project ddf by codice.
the class LdapClaimsHandlerTest method setup.
@Before
public void setup() throws Exception {
claimsParameters = mock(ClaimsParameters.class);
when(claimsParameters.getPrincipal()).thenReturn(new UserPrincipal(USER_DN));
mockEntry = mock(SearchResultEntry.class);
LinkedAttribute attribute = new LinkedAttribute(ATTRIBUTE_NAME);
attribute.add(USER_DN);
mockEntryReader = mock(ConnectionEntryReader.class);
mockBindRequest = mock(BindRequest.class);
PowerMockito.mockStatic(BindMethodChooser.class);
when(BindMethodChooser.selectBindMethod(eq(BINDING_TYPE), eq(BIND_USER_DN), eq(BIND_USER_CREDENTIALS), eq(REALM), eq(KCD))).thenReturn(mockBindRequest);
Map<String, String> map = new HashMap<>();
map.put(NAME_IDENTIFIER_CLAIM_URI, ATTRIBUTE_NAME);
PowerMockito.mockStatic(AttributeMapLoader.class);
when(AttributeMapLoader.buildClaimsMapFile(anyString())).thenReturn(map);
when(AttributeMapLoader.getUser(any(Principal.class))).then(i -> i.getArgumentAt(0, Principal.class).getName());
when(AttributeMapLoader.getBaseDN(any(Principal.class), anyString(), eq(false))).then(i -> i.getArgumentAt(1, String.class));
claimsHandler = new LdapClaimsHandler();
mockBindResult = mock(BindResult.class);
mockConnection = mock(Connection.class);
mockConnectionFactory = PowerMockito.mock(LDAPConnectionFactory.class);
when(mockConnectionFactory.getConnection()).thenReturn(mockConnection);
when(mockConnection.bind(anyString(), any(char[].class))).thenReturn(mockBindResult);
when(mockConnection.bind(any(BindRequest.class))).thenReturn(mockBindResult);
when(mockConnection.search(anyObject(), anyObject(), anyObject(), anyObject())).thenReturn(mockEntryReader);
when(mockEntryReader.hasNext()).thenReturn(true, false);
when(mockEntryReader.readEntry()).thenReturn(mockEntry);
when(mockEntry.getAttribute(anyString())).thenReturn(attribute);
claimsHandler.setLdapConnectionFactory(mockConnectionFactory);
claimsHandler.setPropertyFileLocation("thisstringisnotempty");
claimsHandler.setBindMethod(BINDING_TYPE);
claimsHandler.setBindUserCredentials(BIND_USER_CREDENTIALS);
claimsHandler.setRealm(REALM);
claimsHandler.setKdcAddress(KCD);
claimsHandler.setUserBaseDN(USER_BASE_DN);
claims = new ClaimCollection();
Claim claim = new Claim();
claim.setClaimType(new URI(NAME_IDENTIFIER_CLAIM_URI));
claims.add(claim);
}
Aggregations