Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLogSuccessfulAuthorizationQueries()
        public virtual void ShouldLogSuccessfulAuthorizationQueries()
        {
            // Given
            when(Config.get(SecuritySettings.ldap_use_starttls)).thenReturn(true);

            LdapRealm realm = new TestLdapRealm(this, Config, _securityLog, false);
            JndiLdapContextFactory jndiLdapContectFactory = mock(typeof(JndiLdapContextFactory));

            when(jndiLdapContectFactory.Url).thenReturn("ldap://myserver.org:12345");

            // When
            realm.DoGetAuthorizationInfo(new SimplePrincipalCollection("olivia", "LdapRealm"));

            // Then
            verify(_securityLog).debug(contains("{LdapRealm}: Queried for authorization info for user 'olivia'"));
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLogSuccessfulAuthenticationQueriesUsingStartTLS() throws javax.naming.NamingException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldLogSuccessfulAuthenticationQueriesUsingStartTLS()
        {
            // Given
            when(Config.get(SecuritySettings.ldap_use_starttls)).thenReturn(true);

            LdapRealm realm = new TestLdapRealm(this, Config, _securityLog, false);
            JndiLdapContextFactory jndiLdapContectFactory = mock(typeof(JndiLdapContextFactory));

            when(jndiLdapContectFactory.Url).thenReturn("ldap://myserver.org:12345");

            // When
            realm.QueryForAuthenticationInfo(new ShiroAuthToken(map("principal", "olivia", "credentials", "123")), jndiLdapContectFactory);

            // Then
            verify(_securityLog).debug(contains("{LdapRealm}: Authenticated user 'olivia' against 'ldap://myserver.org:12345' using StartTLS"));
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLogFailedAuthorizationQueries()
        public virtual void ShouldLogFailedAuthorizationQueries()
        {
            // Given
            when(Config.get(SecuritySettings.ldap_use_starttls)).thenReturn(true);

            LdapRealm realm = new TestLdapRealm(this, Config, _securityLog, true);
            JndiLdapContextFactory jndiLdapContectFactory = mock(typeof(JndiLdapContextFactory));

            when(jndiLdapContectFactory.Url).thenReturn("ldap://myserver.org:12345");

            // When
            AuthorizationInfo info = realm.DoGetAuthorizationInfo(new SimplePrincipalCollection("olivia", "LdapRealm"));

            // Then
            assertNull(info);
            verify(_securityLog).warn(contains("{LdapRealm}: Failed to get authorization info: " + "'LDAP naming error while attempting to retrieve authorization for user [olivia].'" + " caused by 'Simulated failure'"));
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLogFailedAuthenticationQueries()
        public virtual void ShouldLogFailedAuthenticationQueries()
        {
            // Given
            when(Config.get(SecuritySettings.ldap_use_starttls)).thenReturn(true);

            LdapRealm realm = new TestLdapRealm(this, Config, _securityLog, true);
            JndiLdapContextFactory jndiLdapContectFactory = mock(typeof(JndiLdapContextFactory));

            when(jndiLdapContectFactory.Url).thenReturn("ldap://myserver.org:12345");

            // When
            assertException(() => realm.QueryForAuthenticationInfo(new ShiroAuthToken(map("principal", "olivia", "credentials", "123")), jndiLdapContectFactory), typeof(NamingException));

            // Then
            // Authentication failures are logged from MultiRealmAuthManager
            //verify( securityLog ).error( contains(
            //        "{LdapRealm}: Failed to authenticate user 'olivia' against 'ldap://myserver.org:12345' using StartTLS: " +
            //                "Simulated failure" ) );
        }