Skip to content

Commit

Permalink
Merge pull request #169 from hazendaz/master
Browse files Browse the repository at this point in the history
Win32Exception Regression and others
  • Loading branch information
dblock committed Nov 25, 2014
2 parents b14fee8 + dc3f706 commit 3d32939
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 32 deletions.
13 changes: 9 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
1.8 (in-progress)
=================
* Added try/catch to authorization header base64 decode in cases of invalid or unsupported authentication header.
1.7.1 (11/24/2014 - waffle-jna only)
====================================
* [#164](https://github.com/dblock/waffle/issues/164): Added try/catch to authorization header base64 decode in cases of invalid or unsupported authentication header.
** Throws runtimeException "Invalid authorization header."

* [#168](https://github.com/dblock/waffle/pull/168): Exception stack trace on invalid credentials.
** Change in waffle 1.7 per sonar to trap only thrown errors resulted in a regression where user enters invalid
creditionals and expected behaviour is to ask again but instead a stack trace was thrown. Special thanks to
@gstanchev for finding and helping resolve this issue.
* Drop legacy base64 usage previously deprecated. We use guava for this now.
* Small number of array object creations cleanup.

1.7 (9/25/2014)
===============
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ public class StartEmbeddedJettyValidateNTLMGroup {

private static Logger LOGGER = LoggerFactory.getLogger(StartEmbeddedJettyValidateNTLMGroup.class);

public static void main(String args[]) {
public static void main(final String args[]) {
System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE");

Server server = new Server(8080);
final Server server = new Server(8080);

ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");

ServletHandler handler = new ServletHandler();
ServletHolder sh = new ServletHolder(new InfoServlet());
final ServletHandler handler = new ServletHandler();
final ServletHolder sh = new ServletHolder(new InfoServlet());
context.addServlet(sh, "/*");

FilterHolder fh = handler.addFilterWithMapping(NegotiateSecurityFilter.class, "/*",
final FilterHolder fh = handler.addFilterWithMapping(NegotiateSecurityFilter.class, "/*",
EnumSet.of(DispatcherType.REQUEST));
setFilterParams(fh);
context.addFilter(fh, "/*", EnumSet.of(DispatcherType.REQUEST));
Expand All @@ -77,7 +77,7 @@ public static void main(String args[]) {
}
}

private static void setFilterParams(FilterHolder fh) {
private static void setFilterParams(final FilterHolder fh) {
fh.setInitParameter("principalFormat", "fqn");
fh.setInitParameter("roleFormat", "both");

Expand All @@ -98,48 +98,48 @@ public static class InfoServlet extends HttpServlet {
private static List<String> authorisedGroups = Arrays.asList("NTGroup1", "NTGroup2");

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
public void doGet(final HttpServletRequest request, final HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
response.setStatus(HttpServletResponse.SC_OK);

boolean isUserAuthorised = isUserAuthorised(request, authorisedGroups);
final boolean isUserAuthorised = isUserAuthorised(request, authorisedGroups);
if (isUserAuthorised) {
response.getWriter().println("User is authorised");
} else {
response.getWriter().println("User is not authorised");
}
}

private boolean isUserAuthorised(HttpServletRequest request, List<String> authorizedGroups) {
List<String> usersGroups = getUsersGroups(request);
private boolean isUserAuthorised(final HttpServletRequest request, final List<String> authorizedGroups) {
final List<String> usersGroups = getUsersGroups(request);

boolean noOverlappingGroups = Collections.disjoint(authorizedGroups, usersGroups);
final boolean noOverlappingGroups = Collections.disjoint(authorizedGroups, usersGroups);
if (!noOverlappingGroups) {
return true;
}
return false;
}

private List<String> getUsersGroups(HttpServletRequest request) {
List<String> result = new ArrayList<String>();
Principal principal = request.getUserPrincipal();
private List<String> getUsersGroups(final HttpServletRequest request) {
final List<String> result = new ArrayList<String>();
final Principal principal = request.getUserPrincipal();
if (principal instanceof WindowsPrincipal) {
WindowsPrincipal windowsPrincipal = (WindowsPrincipal) principal;
for (WindowsAccount account : windowsPrincipal.getGroups().values()) {
String groupName = getGroupName(account.getDomain(), account.getFqn());
String groupName;
final WindowsPrincipal windowsPrincipal = (WindowsPrincipal) principal;
for (final WindowsAccount account : windowsPrincipal.getGroups().values()) {
groupName = getGroupName(account.getDomain(), account.getFqn());
result.add(groupName);
}
}
return result;
}

private String getGroupName(String domain, String groupString) {
private String getGroupName(final String domain, final String groupString) {
if (domain == null || groupString == null) {
return "";
}
String group = groupString.split(domain)[1];
return group.substring(1);
return groupString.split(domain)[1].substring(1);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Source/JNA/waffle-jna/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<parent>
<groupId>com.github.dblock.waffle</groupId>
<artifactId>waffle-parent</artifactId>
<version>1.8-SNAPSHOT</version>
<version>1.7</version>
<relativePath>../waffle-parent</relativePath>
</parent>
<artifactId>waffle-jna</artifactId>
<version>1.8-SNAPSHOT</version>
<version>1.7.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>waffle-jna</name>
<description>WAFFLE JNA implementation</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

import waffle.util.AuthorizationHeader;
import waffle.windows.auth.IWindowsAuthProvider;
import waffle.windows.auth.IWindowsIdentity;
Expand Down Expand Up @@ -127,7 +129,11 @@ public IWindowsIdentity doFilter(final HttpServletRequest request, final HttpSer
if (provider == null) {
throw new RuntimeException("Unsupported security package: " + authorizationHeader.getSecurityPackage());
}
return provider.doFilter(request, response);
try {
return provider.doFilter(request, response);
} catch (Win32Exception e) {
throw new IOException(e);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static boolean isNegTokenArg(final byte[] message) {
int lenBytes;
int len;

// Get lenght of message for additional check.
// Get length of message for additional check.
if ((message[1] & 0x80) == 0) {
len = message[1];
} else {
Expand Down
4 changes: 2 additions & 2 deletions Source/JNA/waffle-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.2</version>
<version>3.3</version>
</plugin>
<!-- Tools -->
<plugin>
Expand All @@ -283,7 +283,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
<configuration>
<descriptor>${project.basedir}/src/assembly/assembly.xml</descriptor>
</configuration>
Expand Down

0 comments on commit 3d32939

Please sign in to comment.