Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug login problems #252

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/main/java/org/mamute/auth/LDAPApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ public boolean authenticate(String username, String password) {
ldap.verifyCredentials(cn, password);
createUserIfNeeded(ldap, cn);

logger.info("Successful LDAP login: " + username);
return true;
} catch (LdapAuthenticationException e) {
logger.debug("LDAP auth attempt failed");
logger.info("LDAP auth attempt failed");
return false;
} catch (LdapException | IOException e) {
logger.debug("LDAP connection error", e);
logger.warn("LDAP connection error", e);
throw new AuthenticationException(LDAP_AUTH, "LDAP connection error", e);
}
}
Expand Down Expand Up @@ -170,7 +171,7 @@ public String getEmail(String username) {
Entry ldapUser = ldap.getUser(userCn(username));
return ldap.getAttribute(ldapUser, emailAttr);
} catch (LdapException | IOException e) {
logger.debug("LDAP connection error", e);
logger.warn("LDAP connection error", e);
throw new AuthenticationException(LDAP_AUTH, "LDAP connection error", e);
}
}
Expand All @@ -183,7 +184,7 @@ private String userCn(String username) {
return user.getDn().getName();
}
} catch (LdapException | IOException e) {
logger.debug("LDAP connection error", e);
logger.warn("LDAP connection error", e);
throw new AuthenticationException(LDAP_AUTH, "LDAP connection error", e);
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/mamute/auth/LDAPAuthenticator.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LDAPAuthenticator implements Authenticator{
private static final Logger logger = LoggerFactory.getLogger(LDAPApi.class);

@Inject private UserDAO users;
@Inject private Access system;
@Inject private LDAPApi ldap;
Expand All @@ -22,6 +27,7 @@ public boolean authenticate(String username, String password) {
retrieved = users.findByMailAndLegacyPasswordAndUpdatePassword(email, password);
}
if (retrieved == null) {
logger.warn("unable to find user by email in the database: " + email);
return false;
}

Expand Down
18 changes: 15 additions & 3 deletions src/main/resources/log4j.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
</layout>
</appender>

<appender name="errorFile" class="org.apache.log4j.FileAppender">
<appender name="auth" class="org.apache.log4j.FileAppender">
<param name="File" value="logs/auth.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{HH:mm:ss} %5p [%-20c{1}] %m%n"/>
</layout>
</appender>

<appender name="errorFile" class="org.apache.log4j.FileAppender">
<param name="File" value="logs/errors.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{HH:mm:ss} %5p [%-20c{1}] %m%n"/>
Expand Down Expand Up @@ -77,7 +84,12 @@
<appender-ref ref="main"/>
</category>

<category name="br.com.caelum.vraptor.simplemail.aws">
<category name="org.mamute.auth">
<priority value="DEBUG"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be DEBUG by default?

Copy link
Contributor

@felipeweb felipeweb Apr 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpfeiffer change here to info and debug

<appender-ref ref="auth"/>
</category>

<category name="br.com.caelum.vraptor.simplemail.aws">
<priority value="INFO"/>
<appender-ref ref="main"/>
</category>
Expand Down Expand Up @@ -137,4 +149,4 @@
<priority value="WARN"/>
<appender-ref ref="main"/>
</category>
</log4j:configuration>
</log4j:configuration>