Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
6b266c51
Commit
6b266c51
authored
17 years ago
by
felmer
Browse files
Options
Downloads
Patches
Plain Diff
CrowdAuthenticationService refactored to make it testable
SVN: 685
parent
329224af
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
authentication/source/java/ch/systemsx/cisd/authentication/crowd/CrowdAuthenticationService.java
+44
-32
44 additions, 32 deletions
...cisd/authentication/crowd/CrowdAuthenticationService.java
with
44 additions
and
32 deletions
authentication/source/java/ch/systemsx/cisd/authentication/crowd/CrowdAuthenticationService.java
+
44
−
32
View file @
6b266c51
...
@@ -105,23 +105,64 @@ public class CrowdAuthenticationService implements IAuthenticationService
...
@@ -105,23 +105,64 @@ public class CrowdAuthenticationService implements IAuthenticationService
+
" <in1>{2}</in1>\n"
+
" <in1>{2}</in1>\n"
+
" </findPrincipalByName>\n"
+
" </findPrincipalByName>\n"
+
" </soap:Body>\n"
+
"</soap:Envelope>\n"
);
+
" </soap:Body>\n"
+
"</soap:Envelope>\n"
);
private
static
IRequestExecutor
createExecutor
()
{
return
new
IRequestExecutor
()
{
/**
* Makes a POST request with "application/soap+xml" as content type.
*
* @return The server's response to the request.
*/
public
String
execute
(
String
serviceUrl
,
String
message
)
{
try
{
HttpClient
client
=
new
HttpClient
();
PostMethod
post
=
new
PostMethod
(
serviceUrl
);
StringRequestEntity
entity
=
new
StringRequestEntity
(
message
,
"application/soap+xml"
,
"utf-8"
);
post
.
setRequestEntity
(
entity
);
String
response
=
null
;
try
{
client
.
executeMethod
(
post
);
response
=
post
.
getResponseBodyAsString
();
}
finally
{
post
.
releaseConnection
();
}
return
response
;
}
catch
(
Exception
ex
)
{
throw
CheckedExceptionTunnel
.
wrapIfNecessary
(
ex
);
}
}
};
}
private
final
String
url
;
private
final
String
url
;
private
final
String
application
;
private
final
String
application
;
private
final
String
applicationPassword
;
private
final
String
applicationPassword
;
private
final
IRequestExecutor
requestExecutor
;
public
CrowdAuthenticationService
(
String
host
,
int
port
,
String
application
,
String
applicationPassword
)
public
CrowdAuthenticationService
(
String
host
,
int
port
,
String
application
,
String
applicationPassword
)
{
{
this
(
"https://"
+
host
+
":"
+
port
+
"/crowd/services/SecurityServer"
,
application
,
applicationPassword
);
this
(
"https://"
+
host
+
":"
+
port
+
"/crowd/services/SecurityServer"
,
application
,
applicationPassword
,
createExecutor
());
}
}
public
CrowdAuthenticationService
(
String
url
,
String
application
,
String
applicationPassword
)
public
CrowdAuthenticationService
(
String
url
,
String
application
,
String
applicationPassword
,
IRequestExecutor
requestExecutor
)
{
{
this
.
url
=
url
;
this
.
url
=
url
;
this
.
application
=
application
;
this
.
application
=
application
;
this
.
applicationPassword
=
applicationPassword
;
this
.
applicationPassword
=
applicationPassword
;
this
.
requestExecutor
=
requestExecutor
;
if
(
operationLog
.
isDebugEnabled
())
if
(
operationLog
.
isDebugEnabled
())
{
{
final
String
msg
=
final
String
msg
=
...
@@ -278,7 +319,7 @@ public class CrowdAuthenticationService implements IAuthenticationService
...
@@ -278,7 +319,7 @@ public class CrowdAuthenticationService implements IAuthenticationService
{
{
decodedArguments
[
i
]
=
StringEscapeUtils
.
escapeXml
(
args
[
i
]);
decodedArguments
[
i
]
=
StringEscapeUtils
.
escapeXml
(
args
[
i
]);
}
}
return
execute
(
template
.
format
(
decodedArguments
));
return
requestExecutor
.
execute
(
url
,
template
.
format
(
decodedArguments
));
}
}
/**
/**
...
@@ -325,33 +366,4 @@ public class CrowdAuthenticationService implements IAuthenticationService
...
@@ -325,33 +366,4 @@ public class CrowdAuthenticationService implements IAuthenticationService
return
xmlString
.
substring
(
index
+
1
,
endIndex
);
return
xmlString
.
substring
(
index
+
1
,
endIndex
);
}
}
/**
* Makes a POST request with "application/soap+xml" as content type.
*
* @return The server's response to the request.
*/
private
final
String
execute
(
String
xmlMessage
)
{
try
{
HttpClient
client
=
new
HttpClient
();
PostMethod
post
=
new
PostMethod
(
url
);
StringRequestEntity
entity
=
new
StringRequestEntity
(
xmlMessage
,
"application/soap+xml"
,
"utf-8"
);
post
.
setRequestEntity
(
entity
);
String
response
=
null
;
try
{
client
.
executeMethod
(
post
);
response
=
post
.
getResponseBodyAsString
();
}
finally
{
post
.
releaseConnection
();
}
return
response
;
}
catch
(
Exception
ex
)
{
throw
CheckedExceptionTunnel
.
wrapIfNecessary
(
ex
);
}
}
}
}
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