Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ac
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OATS-CADC
ac
Commits
d3614f51
Commit
d3614f51
authored
10 years ago
by
Brian Major
Browse files
Options
Downloads
Patches
Plain Diff
s1651 - GMSClient search API implementation
parent
9f3ff933
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
projects/cadcAccessControl/src/ca/nrc/cadc/ac/client/GMSClient.java
+124
-3
124 additions, 3 deletions
...adcAccessControl/src/ca/nrc/cadc/ac/client/GMSClient.java
with
124 additions
and
3 deletions
projects/cadcAccessControl/src/ca/nrc/cadc/ac/client/GMSClient.java
+
124
−
3
View file @
d3614f51
...
@@ -96,6 +96,7 @@ import ca.nrc.cadc.ac.GroupAlreadyExistsException;
...
@@ -96,6 +96,7 @@ import ca.nrc.cadc.ac.GroupAlreadyExistsException;
import
ca.nrc.cadc.ac.GroupNotFoundException
;
import
ca.nrc.cadc.ac.GroupNotFoundException
;
import
ca.nrc.cadc.ac.GroupReader
;
import
ca.nrc.cadc.ac.GroupReader
;
import
ca.nrc.cadc.ac.GroupWriter
;
import
ca.nrc.cadc.ac.GroupWriter
;
import
ca.nrc.cadc.ac.GroupsReader
;
import
ca.nrc.cadc.ac.Role
;
import
ca.nrc.cadc.ac.Role
;
import
ca.nrc.cadc.ac.UserNotFoundException
;
import
ca.nrc.cadc.ac.UserNotFoundException
;
import
ca.nrc.cadc.auth.AuthenticationUtil
;
import
ca.nrc.cadc.auth.AuthenticationUtil
;
...
@@ -653,27 +654,147 @@ public class GMSClient
...
@@ -653,27 +654,147 @@ public class GMSClient
}
}
}
}
public
Collection
<
Group
>
getMemberships
(
Principal
userID
,
Role
role
)
public
List
<
Group
>
getMemberships
(
Principal
userID
,
Role
role
)
throws
IOException
{
{
throw
new
UnsupportedOperationException
();
if
(
userID
==
null
||
role
==
null
)
{
throw
new
IllegalArgumentException
(
"userID and role are required."
);
}
String
idType
=
AuthenticationUtil
.
getPrincipalType
(
userID
);
String
id
=
userID
.
getName
();
String
roleString
=
role
.
getValue
();
StringBuilder
searchGroupURL
=
new
StringBuilder
(
this
.
baseURL
);
searchGroupURL
.
append
(
"/search?"
);
searchGroupURL
.
append
(
"ID="
+
URLEncoder
.
encode
(
id
,
"UTF-8"
));
searchGroupURL
.
append
(
"&TYPE="
+
URLEncoder
.
encode
(
idType
,
"UTF-8"
));
searchGroupURL
.
append
(
"&ROLE="
+
URLEncoder
.
encode
(
roleString
,
"UTF-8"
));
log
.
debug
(
"getMemberships request to "
+
searchGroupURL
.
toString
());
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
URL
url
=
new
URL
(
searchGroupURL
.
toString
());
HttpDownload
transfer
=
new
HttpDownload
(
url
,
out
);
transfer
.
setSSLSocketFactory
(
getSSLSocketFactory
());
transfer
.
run
();
Throwable
error
=
transfer
.
getThrowable
();
if
(
error
!=
null
)
{
log
.
debug
(
"getMemberships throwable"
,
error
);
// transfer returns a -1 code for anonymous access.
if
((
transfer
.
getResponseCode
()
==
-
1
)
||
(
transfer
.
getResponseCode
()
==
401
)
||
(
transfer
.
getResponseCode
()
==
403
))
{
throw
new
AccessControlException
(
error
.
getMessage
());
}
if
(
transfer
.
getResponseCode
()
==
400
)
{
throw
new
IllegalArgumentException
(
error
.
getMessage
());
}
throw
new
IOException
(
error
);
}
try
{
String
groupsXML
=
new
String
(
out
.
toByteArray
(),
"UTF-8"
);
log
.
debug
(
"getMemberships returned: "
+
groupsXML
);
return
GroupsReader
.
read
(
groupsXML
);
}
catch
(
Exception
bug
)
{
log
.
error
(
"Unexpected exception"
,
bug
);
throw
new
RuntimeException
(
bug
);
}
}
}
public
Group
getMembership
(
Principal
userID
,
String
groupName
)
public
Group
getMembership
(
Principal
userID
,
String
groupName
)
throws
IOException
{
{
return
getMembership
(
userID
,
groupName
,
Role
.
MEMBER
);
return
getMembership
(
userID
,
groupName
,
Role
.
MEMBER
);
}
}
public
Group
getMembership
(
Principal
userID
,
String
groupName
,
Role
role
)
public
Group
getMembership
(
Principal
userID
,
String
groupName
,
Role
role
)
throws
IOException
{
{
throw
new
UnsupportedOperationException
();
if
(
userID
==
null
||
groupName
==
null
||
role
==
null
)
{
throw
new
IllegalArgumentException
(
"userID and role are required."
);
}
String
idType
=
AuthenticationUtil
.
getPrincipalType
(
userID
);
String
id
=
userID
.
getName
();
String
roleString
=
role
.
getValue
();
StringBuilder
searchGroupURL
=
new
StringBuilder
(
this
.
baseURL
);
searchGroupURL
.
append
(
"/search?"
);
searchGroupURL
.
append
(
"ID="
+
URLEncoder
.
encode
(
id
,
"UTF-8"
));
searchGroupURL
.
append
(
"&TYPE="
+
URLEncoder
.
encode
(
idType
,
"UTF-8"
));
searchGroupURL
.
append
(
"&ROLE="
+
URLEncoder
.
encode
(
roleString
,
"UTF-8"
));
searchGroupURL
.
append
(
"&GURI="
+
URLEncoder
.
encode
(
groupName
,
"UTF-8"
));
log
.
debug
(
"getMembership request to "
+
searchGroupURL
.
toString
());
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
URL
url
=
new
URL
(
searchGroupURL
.
toString
());
HttpDownload
transfer
=
new
HttpDownload
(
url
,
out
);
transfer
.
setSSLSocketFactory
(
getSSLSocketFactory
());
transfer
.
run
();
Throwable
error
=
transfer
.
getThrowable
();
if
(
error
!=
null
)
{
log
.
debug
(
"getMembership throwable"
,
error
);
// transfer returns a -1 code for anonymous access.
if
((
transfer
.
getResponseCode
()
==
-
1
)
||
(
transfer
.
getResponseCode
()
==
401
)
||
(
transfer
.
getResponseCode
()
==
403
))
{
throw
new
AccessControlException
(
error
.
getMessage
());
}
if
(
transfer
.
getResponseCode
()
==
400
)
{
throw
new
IllegalArgumentException
(
error
.
getMessage
());
}
throw
new
IOException
(
error
);
}
try
{
String
groupsXML
=
new
String
(
out
.
toByteArray
(),
"UTF-8"
);
log
.
debug
(
"getMembership returned: "
+
groupsXML
);
List
<
Group
>
groups
=
GroupsReader
.
read
(
groupsXML
);
if
(
groups
.
size
()
==
0
)
{
return
null
;
}
if
(
groups
.
size
()
==
1
)
{
return
groups
.
get
(
0
);
}
throw
new
IllegalStateException
(
"Duplicate membership for "
+
id
+
" in group "
+
groupName
);
}
catch
(
Exception
bug
)
{
log
.
error
(
"Unexpected exception"
,
bug
);
throw
new
RuntimeException
(
bug
);
}
}
}
public
boolean
isMember
(
Principal
userID
,
String
groupName
)
public
boolean
isMember
(
Principal
userID
,
String
groupName
)
throws
IOException
{
{
return
isMember
(
userID
,
groupName
,
Role
.
MEMBER
);
return
isMember
(
userID
,
groupName
,
Role
.
MEMBER
);
}
}
public
boolean
isMember
(
Principal
userID
,
String
groupName
,
Role
role
)
public
boolean
isMember
(
Principal
userID
,
String
groupName
,
Role
role
)
throws
IOException
{
{
Group
group
=
getMembership
(
userID
,
groupName
,
role
);
Group
group
=
getMembership
(
userID
,
groupName
,
role
);
return
group
!=
null
;
return
group
!=
null
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment