Search in sources :

Example 1 with NAME_IDENTIFIER_CLAIM_URI

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);
}
Also used : HashMap(java.util.HashMap) BindRequest(org.forgerock.opendj.ldap.requests.BindRequest) Connection(org.forgerock.opendj.ldap.Connection) Matchers.anyString(org.mockito.Matchers.anyString) URI(java.net.URI) NAME_IDENTIFIER_CLAIM_URI(ddf.security.SubjectUtils.NAME_IDENTIFIER_CLAIM_URI) UserPrincipal(org.apache.karaf.jaas.boot.principal.UserPrincipal) ClaimsParameters(org.apache.cxf.sts.claims.ClaimsParameters) LinkedAttribute(org.forgerock.opendj.ldap.LinkedAttribute) ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) BindResult(org.forgerock.opendj.ldap.responses.BindResult) LDAPConnectionFactory(org.forgerock.opendj.ldap.LDAPConnectionFactory) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) UserPrincipal(org.apache.karaf.jaas.boot.principal.UserPrincipal) Principal(java.security.Principal) Claim(org.apache.cxf.rt.security.claims.Claim) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry) Before(org.junit.Before)

Aggregations

NAME_IDENTIFIER_CLAIM_URI (ddf.security.SubjectUtils.NAME_IDENTIFIER_CLAIM_URI)1 URI (java.net.URI)1 Principal (java.security.Principal)1 HashMap (java.util.HashMap)1 Claim (org.apache.cxf.rt.security.claims.Claim)1 ClaimCollection (org.apache.cxf.rt.security.claims.ClaimCollection)1 ClaimsParameters (org.apache.cxf.sts.claims.ClaimsParameters)1 ProcessedClaimCollection (org.apache.cxf.sts.claims.ProcessedClaimCollection)1 UserPrincipal (org.apache.karaf.jaas.boot.principal.UserPrincipal)1 Connection (org.forgerock.opendj.ldap.Connection)1 LDAPConnectionFactory (org.forgerock.opendj.ldap.LDAPConnectionFactory)1 LinkedAttribute (org.forgerock.opendj.ldap.LinkedAttribute)1 BindRequest (org.forgerock.opendj.ldap.requests.BindRequest)1 BindResult (org.forgerock.opendj.ldap.responses.BindResult)1 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)1 ConnectionEntryReader (org.forgerock.opendj.ldif.ConnectionEntryReader)1 Before (org.junit.Before)1 Matchers.anyString (org.mockito.Matchers.anyString)1