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
76c58f63
Commit
76c58f63
authored
9 years ago
by
Brian Major
Browse files
Options
Downloads
Patches
Plain Diff
ac2 - no exception throw on augment subject if user not found
parent
2153cec0
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/UserClient.java
+29
-26
29 additions, 26 deletions
...dcAccessControl/src/ca/nrc/cadc/ac/client/UserClient.java
with
29 additions
and
26 deletions
projects/cadcAccessControl/src/ca/nrc/cadc/ac/client/UserClient.java
+
29
−
26
View file @
76c58f63
...
...
@@ -131,8 +131,8 @@ public class UserClient
}
/**
* This method takes a subject with at least one valid principal,
* uses the ac user web service to get all the other
* This method takes a subject with at least one valid principal,
* uses the ac user web service to get all the other
* associated principals which are then added to the subject.
*
* @param subject The Subject to pull Princials for.
...
...
@@ -143,17 +143,31 @@ public class UserClient
if
(
principal
!=
null
)
{
URL
url
=
this
.
getURL
(
principal
);
log
.
debug
(
"augmentSubject request to "
+
url
.
toString
());
log
.
debug
(
"augmentSubject request to "
+
url
.
toString
());
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
HttpDownload
download
=
new
HttpDownload
(
url
,
out
);
download
.
run
();
this
.
handleThrowable
(
download
);
int
responseCode
=
download
.
getResponseCode
();
if
(
responseCode
==
404
)
// not found
{
return
;
}
if
(
responseCode
!=
200
)
{
String
message
=
"Error calling /ac to augment subject"
;
if
(
download
.
getThrowable
()
!=
null
)
{
throw
new
IllegalStateException
(
message
,
download
.
getThrowable
());
}
throw
new
IllegalStateException
(
message
);
}
subject
.
getPrincipals
().
clear
();
subject
.
getPrincipals
().
addAll
(
this
.
getPrincipals
(
out
));
}
}
protected
Principal
getPrincipal
(
final
Subject
subject
)
{
Set
<
Principal
>
principals
=
subject
.
getPrincipals
();
...
...
@@ -167,7 +181,7 @@ public class UserClient
final
String
msg
=
"Subject has more than one principal."
;
throw
new
IllegalArgumentException
(
msg
);
}
return
principal
;
}
else
...
...
@@ -175,14 +189,14 @@ public class UserClient
return
null
;
}
}
protected
Set
<
Principal
>
getPrincipals
(
ByteArrayOutputStream
out
)
{
try
{
String
userXML
=
new
String
(
out
.
toByteArray
(),
"UTF-8"
);
log
.
debug
(
"userXML Input to getPrincipals(): "
+
userXML
);
User
<
Principal
>
user
=
new
UserReader
().
read
(
userXML
);
return
user
.
getIdentities
();
}
...
...
@@ -191,36 +205,25 @@ public class UserClient
throw
new
RuntimeException
(
e
);
}
}
protected
void
handleThrowable
(
HttpDownload
download
)
{
Throwable
throwable
=
download
.
getThrowable
();
if
(
throwable
!=
null
)
{
log
.
debug
(
"handleThrowable(): throwable ("
+
download
.
getResponseCode
()
+
")"
,
throwable
);
throw
new
IllegalStateException
(
throwable
.
getMessage
());
}
}
protected
URL
getURL
(
Principal
principal
)
{
try
try
{
String
userID
=
principal
.
getName
();
URL
url
=
new
URL
(
this
.
baseURL
+
"/users/"
+
userID
+
URL
url
=
new
URL
(
this
.
baseURL
+
"/users/"
+
userID
+
"?idType="
+
this
.
getIdType
(
principal
)
+
"&detail=identity"
);
log
.
debug
(
"getURL(): returned url ="
+
""
+
" "
+
url
.
toString
());
return
url
;
}
}
catch
(
MalformedURLException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
protected
String
getIdType
(
Principal
principal
)
{
String
idTypeStr
=
AuthenticationUtil
.
getPrincipalType
(
principal
);
...
...
@@ -230,7 +233,7 @@ public class UserClient
principal
.
getName
();
throw
new
IllegalArgumentException
(
msg
);
}
return
idTypeStr
;
}
}
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