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

Custom instances of GenericPrincipal in WaffleAuthenticatorBase #571

Merged
merged 5 commits into from Dec 3, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
Expand Up @@ -26,6 +26,7 @@
import org.apache.catalina.LifecycleException;
import org.apache.catalina.connector.Request;
import org.apache.catalina.deploy.LoginConfig;
import org.apache.catalina.realm.GenericPrincipal;
import org.slf4j.LoggerFactory;

import waffle.util.AuthorizationHeader;
Expand Down Expand Up @@ -254,17 +255,15 @@ private boolean post(final Request request, final HttpServletResponse response)
try {
this.log.debug("successfully logged in {} ({})", username, windowsIdentity.getSidString());

final GenericWindowsPrincipal windowsPrincipal = new GenericWindowsPrincipal(windowsIdentity,
this.principalFormat, this.roleFormat);

this.log.debug("roles: {}", windowsPrincipal.getRolesString());
final GenericPrincipal genericPrincipal = createPrincipal(windowsIdentity);

this.log.debug("roles: {}", String.join(", ", genericPrincipal.getRoles()));
// create a session associated with this request if there's none
final HttpSession session = request.getSession(true);
this.log.debug("session id: {}", session == null ? "null" : session.getId());

this.register(request, response, windowsPrincipal, "FORM", windowsPrincipal.getName(), null);
this.log.info("successfully logged in user: {}", windowsPrincipal.getName());
this.register(request, response, genericPrincipal, "FORM", genericPrincipal.getName(), null);
this.log.info("successfully logged in user: {}", genericPrincipal.getName());
} finally {
windowsIdentity.dispose();
}
Expand Down
Expand Up @@ -23,6 +23,7 @@
import org.apache.catalina.LifecycleException;
import org.apache.catalina.connector.Request;
import org.apache.catalina.deploy.LoginConfig;
import org.apache.catalina.realm.GenericPrincipal;
import org.slf4j.LoggerFactory;

import waffle.util.AuthorizationHeader;
Expand Down Expand Up @@ -160,12 +161,11 @@ public boolean authenticate(final Request request, final HttpServletResponse res
try {
this.log.debug("logged in user: {} ({})", windowsIdentity.getFqn(), windowsIdentity.getSidString());

final GenericWindowsPrincipal windowsPrincipal = new GenericWindowsPrincipal(windowsIdentity,
this.principalFormat, this.roleFormat);
final GenericPrincipal genericPrincipal = createPrincipal(windowsIdentity);

this.log.debug("roles: {}", windowsPrincipal.getRolesString());
this.log.debug("roles: {}", String.join(", ", genericPrincipal.getRoles()));

principal = windowsPrincipal;
principal = genericPrincipal;

// create a session associated with this request if there's none
final HttpSession session = request.getSession(true);
Expand Down
Expand Up @@ -23,6 +23,7 @@

import org.apache.catalina.authenticator.AuthenticatorBase;
import org.apache.catalina.connector.Request;
import org.apache.catalina.realm.GenericPrincipal;
import org.slf4j.Logger;

import waffle.windows.auth.IWindowsAuthProvider;
Expand Down Expand Up @@ -243,13 +244,22 @@ protected Principal doLogin(final Request request, final String username, final
}
try {
this.log.debug("successfully logged in {} ({})", username, windowsIdentity.getSidString());
final GenericWindowsPrincipal windowsPrincipal = new GenericWindowsPrincipal(windowsIdentity,
this.principalFormat, this.roleFormat);
this.log.debug("roles: {}", windowsPrincipal.getRolesString());
return windowsPrincipal;
final GenericPrincipal genericPrincipal = createPrincipal(windowsIdentity);
this.log.debug("roles: {}", String.join(", ", genericPrincipal.getRoles()));
return genericPrincipal;
} finally {
windowsIdentity.dispose();
}
}

/**
* This method will create an instance of a IWindowsIdentity based GenericPrincipal.
* It is used for creating custom implementation within subclasses.
* @param windowsIdentity the windows identity to initialize the principal
* @return the Generic Principal
*/
protected GenericPrincipal createPrincipal(final IWindowsIdentity windowsIdentity) {
return new GenericWindowsPrincipal(windowsIdentity, this.principalFormat, this.roleFormat);
}

}
Expand Up @@ -25,6 +25,7 @@

import org.apache.catalina.LifecycleException;
import org.apache.catalina.connector.Request;
import org.apache.catalina.realm.GenericPrincipal;
import org.apache.tomcat.util.descriptor.web.LoginConfig;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -255,17 +256,15 @@ private boolean post(final Request request, final HttpServletResponse response)
try {
this.log.debug("successfully logged in {} ({})", username, windowsIdentity.getSidString());

final GenericWindowsPrincipal windowsPrincipal = new GenericWindowsPrincipal(windowsIdentity,
this.principalFormat, this.roleFormat);

this.log.debug("roles: {}", windowsPrincipal.getRolesString());
final GenericPrincipal genericPrincipal = createPrincipal(windowsIdentity);

this.log.debug("roles: {}", String.join(", ", genericPrincipal.getRoles()));
// create a session associated with this request if there's none
final HttpSession session = request.getSession(true);
this.log.debug("session id: {}", session == null ? "null" : session.getId());

this.register(request, response, windowsPrincipal, "FORM", windowsPrincipal.getName(), null);
this.log.info("successfully logged in user: {}", windowsPrincipal.getName());
this.register(request, response, genericPrincipal, "FORM", genericPrincipal.getName(), null);
this.log.info("successfully logged in user: {}", genericPrincipal.getName());
} finally {
windowsIdentity.dispose();
}
Expand Down
Expand Up @@ -22,6 +22,7 @@

import org.apache.catalina.LifecycleException;
import org.apache.catalina.connector.Request;
import org.apache.catalina.realm.GenericPrincipal;
import org.slf4j.LoggerFactory;

import waffle.util.AuthorizationHeader;
Expand Down Expand Up @@ -158,12 +159,11 @@ public boolean authenticate(final Request request, final HttpServletResponse res
try {
this.log.debug("logged in user: {} ({})", windowsIdentity.getFqn(), windowsIdentity.getSidString());

final GenericWindowsPrincipal windowsPrincipal = new GenericWindowsPrincipal(windowsIdentity,
this.principalFormat, this.roleFormat);
final GenericPrincipal genericPrincipal = createPrincipal(windowsIdentity);

this.log.debug("roles: {}", windowsPrincipal.getRolesString());
this.log.debug("roles: {}", String.join(", ", genericPrincipal.getRoles()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor: one space too many.

Copy link
Member

Choose a reason for hiding this comment

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

Run a quick build, that will flush out that space or any others.

Copy link
Member

Choose a reason for hiding this comment

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

@Snap252 There isn't really much difference between the various integrations. We probably could use an overall refactoring to make things better. For now though, as new builds become available, because we brand the version, we supply a new copy. So tomcat 9 is really just tomcat 8.5 with the minor variance you saw. Spring 3, 4, and 5 copies I believe are completely identical. Just haven't had time to really go in and look how to make it more streamlined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Run a quick build, that will flush out that space or any others.

  • hazendaz

I already tried a maven test / maven install - but this kills me all the formatting (in existing and untouched files) - Am I doing something wrong, or is there anything I needed to know to keep formatting?


principal = windowsPrincipal;
principal = genericPrincipal;

// create a session associated with this request if there's none
final HttpSession session = request.getSession(true);
Expand Down
Expand Up @@ -23,6 +23,7 @@

import org.apache.catalina.authenticator.AuthenticatorBase;
import org.apache.catalina.connector.Request;
import org.apache.catalina.realm.GenericPrincipal;
import org.slf4j.Logger;

import waffle.windows.auth.IWindowsAuthProvider;
Expand Down Expand Up @@ -242,13 +243,22 @@ protected Principal doLogin(final Request request, final String username, final
}
try {
this.log.debug("successfully logged in {} ({})", username, windowsIdentity.getSidString());
final GenericWindowsPrincipal windowsPrincipal = new GenericWindowsPrincipal(windowsIdentity,
this.principalFormat, this.roleFormat);
this.log.debug("roles: {}", windowsPrincipal.getRolesString());
return windowsPrincipal;
final GenericPrincipal genericPrincipal = createPrincipal(windowsIdentity);
this.log.debug("roles: {}", String.join(", ", genericPrincipal.getRoles()));
return genericPrincipal;
} finally {
windowsIdentity.dispose();
}
}

/**
* This method will create an instance of a IWindowsIdentity based GenericPrincipal.
* It is used for creating custom implementation within subclasses.
* @param windowsIdentity the windows identity to initialize the principal
* @return the Generic Principal
*/
protected GenericPrincipal createPrincipal(final IWindowsIdentity windowsIdentity) {
return new GenericWindowsPrincipal(windowsIdentity, this.principalFormat, this.roleFormat);
}

}
Expand Up @@ -25,6 +25,7 @@

import org.apache.catalina.LifecycleException;
import org.apache.catalina.connector.Request;
import org.apache.catalina.realm.GenericPrincipal;
import org.apache.tomcat.util.descriptor.web.LoginConfig;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -202,17 +203,16 @@ private boolean negotiate(final Request request, final HttpServletResponse respo

this.log.debug("logged in user: {} ({})", windowsIdentity.getFqn(), windowsIdentity.getSidString());

final GenericWindowsPrincipal windowsPrincipal = new GenericWindowsPrincipal(windowsIdentity,
this.principalFormat, this.roleFormat);
final GenericPrincipal genericPrincipal = createPrincipal(windowsIdentity);

this.log.debug("roles: {}", windowsPrincipal.getRolesString());
this.log.debug("roles: {}", String.join(", ", genericPrincipal.getRoles()));

// create a session associated with this request if there's none
final HttpSession session = request.getSession(true);
this.log.debug("session id: {}", session == null ? "null" : session.getId());

this.register(request, response, windowsPrincipal, securityPackage, windowsPrincipal.getName(), null);
this.log.info("successfully logged in user: {}", windowsPrincipal.getName());
this.register(request, response, genericPrincipal, securityPackage, genericPrincipal.getName(), null);
this.log.info("successfully logged in user: {}", genericPrincipal.getName());

} finally {
windowsIdentity.dispose();
Expand Down Expand Up @@ -255,17 +255,15 @@ private boolean post(final Request request, final HttpServletResponse response)
try {
this.log.debug("successfully logged in {} ({})", username, windowsIdentity.getSidString());

final GenericWindowsPrincipal windowsPrincipal = new GenericWindowsPrincipal(windowsIdentity,
this.principalFormat, this.roleFormat);

this.log.debug("roles: {}", windowsPrincipal.getRolesString());
final GenericPrincipal genericPrincipal = createPrincipal(windowsIdentity);

this.log.debug("roles: {}", String.join(", ", genericPrincipal.getRoles()));
// create a session associated with this request if there's none
final HttpSession session = request.getSession(true);
this.log.debug("session id: {}", session == null ? "null" : session.getId());

this.register(request, response, windowsPrincipal, "FORM", windowsPrincipal.getName(), null);
this.log.info("successfully logged in user: {}", windowsPrincipal.getName());
this.register(request, response, genericPrincipal, "FORM", genericPrincipal.getName(), null);
this.log.info("successfully logged in user: {}", genericPrincipal.getName());
} finally {
windowsIdentity.dispose();
}
Expand Down
Expand Up @@ -11,8 +11,6 @@
*/
package waffle.apache;

import com.sun.jna.platform.win32.Win32Exception;

import java.io.IOException;
import java.security.Principal;
import java.util.Base64;
Expand All @@ -22,8 +20,11 @@

import org.apache.catalina.LifecycleException;
import org.apache.catalina.connector.Request;
import org.apache.catalina.realm.GenericPrincipal;
import org.slf4j.LoggerFactory;

import com.sun.jna.platform.win32.Win32Exception;

import waffle.util.AuthorizationHeader;
import waffle.util.NtlmServletRequest;
import waffle.windows.auth.IWindowsIdentity;
Expand Down Expand Up @@ -158,12 +159,11 @@ public boolean authenticate(final Request request, final HttpServletResponse res
try {
this.log.debug("logged in user: {} ({})", windowsIdentity.getFqn(), windowsIdentity.getSidString());

final GenericWindowsPrincipal windowsPrincipal = new GenericWindowsPrincipal(windowsIdentity,
this.principalFormat, this.roleFormat);
final GenericPrincipal genericPrincipal = createPrincipal(windowsIdentity);

this.log.debug("roles: {}", windowsPrincipal.getRolesString());
this.log.debug("roles: {}", String.join(", ", genericPrincipal.getRoles()));
Copy link
Member

Choose a reason for hiding this comment

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

Please revert the change above. getRolesString() already does the string joiner.

Copy link
Member

Choose a reason for hiding this comment

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

nevermind I see why now.

Copy link
Contributor Author

@Snap252 Snap252 Nov 18, 2017

Choose a reason for hiding this comment

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

Using the toString-Method in log output would give the possibility to use more generic interfaces
this.log.debug("roles: {}", String.join(", ", genericPrincipal.getRoles()));
->
this.log.debug("principal: {}", principal.toString());


principal = windowsPrincipal;
principal = genericPrincipal;

// create a session associated with this request if there's none
final HttpSession session = request.getSession(true);
Expand Down
Expand Up @@ -23,6 +23,7 @@

import org.apache.catalina.authenticator.AuthenticatorBase;
import org.apache.catalina.connector.Request;
import org.apache.catalina.realm.GenericPrincipal;
import org.slf4j.Logger;

import waffle.windows.auth.IWindowsAuthProvider;
Expand Down Expand Up @@ -242,13 +243,22 @@ protected Principal doLogin(final Request request, final String username, final
}
try {
this.log.debug("successfully logged in {} ({})", username, windowsIdentity.getSidString());
final GenericWindowsPrincipal windowsPrincipal = new GenericWindowsPrincipal(windowsIdentity,
this.principalFormat, this.roleFormat);
this.log.debug("roles: {}", windowsPrincipal.getRolesString());
return windowsPrincipal;
final GenericPrincipal genericPrincipal = createPrincipal(windowsIdentity);
this.log.debug("roles: {}", String.join(", ", genericPrincipal.getRoles()));
return genericPrincipal;
} finally {
windowsIdentity.dispose();
}
}

/**
* This method will create an instance of a IWindowsIdentity based GenericPrincipal.
* It is used for creating custom implementation within subclasses.
* @param windowsIdentity the windows identity to initialize the principal
* @return the Generic Principal
*/
protected GenericPrincipal createPrincipal(final IWindowsIdentity windowsIdentity) {
return new GenericWindowsPrincipal(windowsIdentity, this.principalFormat, this.roleFormat);
}

}
Expand Up @@ -25,6 +25,7 @@

import org.apache.catalina.LifecycleException;
import org.apache.catalina.connector.Request;
import org.apache.catalina.realm.GenericPrincipal;
import org.apache.tomcat.util.descriptor.web.LoginConfig;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -202,17 +203,16 @@ private boolean negotiate(final Request request, final HttpServletResponse respo

this.log.debug("logged in user: {} ({})", windowsIdentity.getFqn(), windowsIdentity.getSidString());

final GenericWindowsPrincipal windowsPrincipal = new GenericWindowsPrincipal(windowsIdentity,
this.principalFormat, this.roleFormat);
final GenericPrincipal genericPrincipal = createPrincipal(windowsIdentity);

this.log.debug("roles: {}", windowsPrincipal.getRolesString());
this.log.debug("roles: {}", String.join(", ", genericPrincipal.getRoles()));

// create a session associated with this request if there's none
final HttpSession session = request.getSession(true);
this.log.debug("session id: {}", session == null ? "null" : session.getId());

this.register(request, response, windowsPrincipal, securityPackage, windowsPrincipal.getName(), null);
this.log.info("successfully logged in user: {}", windowsPrincipal.getName());
this.register(request, response, genericPrincipal, securityPackage, genericPrincipal.getName(), null);
this.log.info("successfully logged in user: {}", genericPrincipal.getName());

} finally {
windowsIdentity.dispose();
Expand Down Expand Up @@ -255,17 +255,15 @@ private boolean post(final Request request, final HttpServletResponse response)
try {
this.log.debug("successfully logged in {} ({})", username, windowsIdentity.getSidString());

final GenericWindowsPrincipal windowsPrincipal = new GenericWindowsPrincipal(windowsIdentity,
this.principalFormat, this.roleFormat);

this.log.debug("roles: {}", windowsPrincipal.getRolesString());
final GenericPrincipal genericPrincipal = createPrincipal(windowsIdentity);

this.log.debug("roles: {}", String.join(", ", genericPrincipal.getRoles()));
// create a session associated with this request if there's none
final HttpSession session = request.getSession(true);
this.log.debug("session id: {}", session == null ? "null" : session.getId());

this.register(request, response, windowsPrincipal, "FORM", windowsPrincipal.getName(), null);
this.log.info("successfully logged in user: {}", windowsPrincipal.getName());
this.register(request, response, genericPrincipal, "FORM", genericPrincipal.getName(), null);
this.log.info("successfully logged in user: {}", genericPrincipal.getName());
} finally {
windowsIdentity.dispose();
}
Expand Down
Expand Up @@ -22,6 +22,7 @@

import org.apache.catalina.LifecycleException;
import org.apache.catalina.connector.Request;
import org.apache.catalina.realm.GenericPrincipal;
import org.slf4j.LoggerFactory;

import waffle.util.AuthorizationHeader;
Expand Down Expand Up @@ -159,12 +160,11 @@ public boolean authenticate(final Request request, final HttpServletResponse res
try {
this.log.debug("logged in user: {} ({})", windowsIdentity.getFqn(), windowsIdentity.getSidString());

final GenericWindowsPrincipal windowsPrincipal = new GenericWindowsPrincipal(windowsIdentity,
this.principalFormat, this.roleFormat);
final GenericPrincipal genericPrincipal = createPrincipal(windowsIdentity);

this.log.debug("roles: {}", windowsPrincipal.getRolesString());
this.log.debug("roles: {}", String.join(", ", genericPrincipal.getRoles()));

principal = windowsPrincipal;
principal = genericPrincipal;

// create a session associated with this request if there's none
final HttpSession session = request.getSession(true);
Expand Down