Skip to content
Snippets Groups Projects
Commit 6275f438 authored by Brian Major's avatar Brian Major
Browse files

Merge branch 's1651' of /usr/cadc/dev/git/wopencadc into s1651

parents 8ae2d384 475f2a20
Branches
Tags
No related merge requests found
...@@ -141,10 +141,10 @@ ...@@ -141,10 +141,10 @@
<pathelement path="${build}/test/class"/> <pathelement path="${build}/test/class"/>
<pathelement path="${testingJars}"/> <pathelement path="${testingJars}"/>
</classpath> </classpath>
<!--<test name="ca.nrc.cadc.ac.server.ldap.LdapDAOTest" />--> <test name="ca.nrc.cadc.ac.server.ldap.LdapDAOTest" />
<test name="ca.nrc.cadc.ac.server.ldap.LdapGroupDAOTest" /> <test name="ca.nrc.cadc.ac.server.ldap.LdapGroupDAOTest" />
<!--<test name="ca.nrc.cadc.ac.server.web.GroupActionFactoryTest" />--> <test name="ca.nrc.cadc.ac.server.web.GroupActionFactoryTest" />
<!--<test name="ca.nrc.cadc.ac.server.ldap.LdapUserDAOTest" />--> <test name="ca.nrc.cadc.ac.server.ldap.LdapUserDAOTest" />
<formatter type="plain" usefile="false" /> <formatter type="plain" usefile="false" />
</junit> </junit>
</target> </target>
......
...@@ -212,7 +212,7 @@ public abstract class LdapDAO ...@@ -212,7 +212,7 @@ public abstract class LdapDAO
{ {
throw new AccessControlException("Invalid credentials " + msg); throw new AccessControlException("Invalid credentials " + msg);
} }
else if (code == ResultCode.SUCCESS) else if ((code == ResultCode.SUCCESS) || (code == ResultCode.NO_SUCH_OBJECT) )
{ {
// all good. nothing to do // all good. nothing to do
} }
......
...@@ -345,7 +345,7 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO ...@@ -345,7 +345,7 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO
{ {
String [] attributes = new String[] {"entrydn", "cn", "description", String [] attributes = new String[] {"entrydn", "cn", "description",
"owner", "uniquemember", "owner", "uniquemember",
"modifytimestamp"}; "modifytimestamp", "nsaccountlock"};
return getGroup(groupDN, groupID, withMembers, attributes); return getGroup(groupDN, groupID, withMembers, attributes);
} }
...@@ -366,10 +366,7 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO ...@@ -366,10 +366,7 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO
{ {
try try
{ {
Filter filter = Filter.createANDFilter( Filter filter = Filter.createEqualityFilter("cn", groupID);
Filter.createEqualityFilter("cn", groupID),
Filter.createNOTFilter(
Filter.createEqualityFilter("nsaccountlock", "TRUE")));
SearchRequest searchRequest = SearchRequest searchRequest =
new SearchRequest(groupDN.toNormalizedString(), new SearchRequest(groupDN.toNormalizedString(),
...@@ -386,11 +383,7 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO ...@@ -386,11 +383,7 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO
} }
catch (LDAPSearchException e) catch (LDAPSearchException e)
{ {
if (e.getResultCode() == ResultCode.AUTHORIZATION_DENIED) if (e.getResultCode() == ResultCode.NO_SUCH_OBJECT)
{
throw new AccessControlException("Unauthorized to access group " + groupID);
}
else if (e.getResultCode() == ResultCode.NO_SUCH_OBJECT)
{ {
String msg = "Group not found " + groupID; String msg = "Group not found " + groupID;
logger.debug(msg); logger.debug(msg);
...@@ -398,23 +391,34 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO ...@@ -398,23 +391,34 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO
} }
else else
{ {
throw new RuntimeException("Unknown LDAP exception: " + e.getResultCode()); LdapDAO.checkLdapResult(e.getResultCode(), e.getMessage());
} }
} }
if (searchResult.getEntryCount() == 0) if (searchResult.getEntryCount() == 0)
{ {
// deleted groups? LdapDAO.checkLdapResult(searchResult.getResultCode(), null);
String msg = "Group not found " + groupID; //access denied
String msg = "Not authorized to access " + groupID;
logger.debug(msg); logger.debug(msg);
throw new GroupNotFoundException(groupID); throw new AccessControlException(groupID);
} }
if (searchResult.getEntryCount() >1) if (searchResult.getEntryCount() >1)
{ {
throw new RuntimeException("BUG: multiple results when retrieving group " + groupID); throw new RuntimeException("BUG: multiple results when retrieving group " + groupID);
} }
SearchResultEntry searchEntry = searchResult.getSearchEntries().get(0); SearchResultEntry searchEntry = searchResult.getSearchEntries().get(0);
if (searchEntry.getAttribute("nsaccountlock") != null)
{
// deleted group
String msg = "Group not found " + groupID;
logger.debug(msg);
throw new GroupNotFoundException(groupID);
}
String groupCN = searchEntry.getAttributeValue("cn"); String groupCN = searchEntry.getAttributeValue("cn");
DN groupOwner = searchEntry.getAttributeValueAsDN("owner"); DN groupOwner = searchEntry.getAttributeValueAsDN("owner");
......
...@@ -557,8 +557,29 @@ public class LdapGroupDAOTest ...@@ -557,8 +557,29 @@ public class LdapGroupDAOTest
Subject.doAs(daoTestUser1Subject, new PrivilegedExceptionAction<Object>() Subject.doAs(daoTestUser1Subject, new PrivilegedExceptionAction<Object>()
{ {
public Object run() throws Exception public Object run() throws Exception
{ {
getGroupDAO().deleteGroup(groupID); try
{
getGroupDAO().getGroup(groupID);
//fail("getGroup with anonymous access should throw " +
// "AccessControlException");
}
catch (AccessControlException ignore) {}
return null;
}
});
Subject.doAs(daoTestUser2Subject, new PrivilegedExceptionAction<Object>()
{
public Object run() throws Exception
{
try
{
getGroupDAO().getGroup(groupID);
fail("getGroup with anonymous access should throw " +
"AccessControlException");
}
catch (AccessControlException ignore) {}
return null; return null;
} }
}); });
...@@ -729,10 +750,10 @@ public class LdapGroupDAOTest ...@@ -729,10 +750,10 @@ public class LdapGroupDAOTest
Group group = getGroupDAO().getGroup(groupID); Group group = getGroupDAO().getGroup(groupID);
assertTrue(group == null); assertTrue(group == null);
fail("searchGroups with unknown user should throw " + fail("searchGroups with un-authorized user should throw " +
"GroupNotFoundException"); "AccessControlException");
} }
catch (GroupNotFoundException ignore) catch (AccessControlException ignore)
{ {
} }
......
...@@ -86,6 +86,7 @@ import java.util.Map; ...@@ -86,6 +86,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.SSLSocketFactory;
import javax.security.auth.Subject; import javax.security.auth.Subject;
...@@ -380,14 +381,24 @@ public class GMSClient ...@@ -380,14 +381,24 @@ public class GMSClient
((HttpsURLConnection) conn) ((HttpsURLConnection) conn)
.setSSLSocketFactory(getSSLSocketFactory()); .setSSLSocketFactory(getSSLSocketFactory());
} }
int responseCode = conn.getResponseCode(); int responseCode = -1;
try
{
responseCode = conn.getResponseCode();
}
catch(SSLHandshakeException e)
{
throw new AccessControlException(e.getMessage());
}
if (responseCode != 200) if (responseCode != 200)
{ {
String errMessage = NetUtil.getErrorBody(conn); String errMessage = NetUtil.getErrorBody(conn);
log.debug("deleteGroup response " + responseCode + ": " + log.debug("deleteGroup response " + responseCode + ": " +
errMessage); errMessage);
if ((responseCode == 401) || (responseCode == 403)) if ((responseCode == 401) || (responseCode == 403) ||
(responseCode == -1))
{ {
throw new AccessControlException(errMessage); throw new AccessControlException(errMessage);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment