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
30981f6b
Commit
30981f6b
authored
17 years ago
by
ribeaudc
Browse files
Options
Downloads
Patches
Plain Diff
Add logging to Crowd authentication.
SVN: 219
parent
90238b80
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
+93
-35
93 additions, 35 deletions
...cisd/authentication/crowd/CrowdAuthenticationService.java
with
93 additions
and
35 deletions
authentication/source/java/ch/systemsx/cisd/authentication/crowd/CrowdAuthenticationService.java
+
93
−
35
View file @
30981f6b
...
...
@@ -22,71 +22,111 @@ import org.apache.commons.httpclient.HttpClient;
import
org.apache.commons.httpclient.methods.PostMethod
;
import
org.apache.commons.httpclient.methods.StringRequestEntity
;
import
org.apache.commons.lang.StringEscapeUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.log4j.Logger
;
import
ch.systemsx.cisd.authentication.IAuthenticationService
;
import
ch.systemsx.cisd.common.exceptions.CheckedExceptionTunnel
;
import
ch.systemsx.cisd.common.logging.LogCategory
;
import
ch.systemsx.cisd.common.logging.LogFactory
;
/**
* This <code>IAuthenticationService</code> implementation first registers the application on the <i>Crowd</i>
* server, then authenticates the user.
*
*
* @author felmer
*/
public
class
CrowdAuthenticationService
implements
IAuthenticationService
{
private
static
final
Logger
operationLog
=
LogFactory
.
getLogger
(
LogCategory
.
OPERATION
,
CrowdAuthenticationService
.
class
);
private
static
final
MessageFormat
AUTHENTICATE_APPL
=
new
MessageFormat
(
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" "
+
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
+
" <soap:Body>\n"
+
" <authenticateApplication xmlns=\"urn:SecurityServer\">\n"
+
" <in0>\n"
+
" <credential xmlns=\"http://authentication.integration.crowd.atlassian.com\">\n"
+
" <credential>{1}</credential>\n"
+
" </credential>\n"
+
" <name xmlns=\"http://authentication.integration.crowd.atlassian.com\">{0}</name>\n"
+
" <validationFactors xmlns=\"http://authentication.integration.crowd.atlassian.com\" "
+
" xsi:nil=\"true\" />\n"
+
" </in0>\n"
+
" </authenticateApplication>\n"
+
" </soap:Body>\n"
+
"</soap:Envelope>\n"
);
new
MessageFormat
(
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" "
+
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
+
" <soap:Body>\n"
+
" <authenticateApplication xmlns=\"urn:SecurityServer\">\n"
+
" <in0>\n"
+
" <credential xmlns=\"http://authentication.integration.crowd.atlassian.com\">\n"
+
" <credential>{1}</credential>\n"
+
" </credential>\n"
+
" <name xmlns=\"http://authentication.integration.crowd.atlassian.com\">{0}</name>\n"
+
" <validationFactors xmlns=\"http://authentication.integration.crowd.atlassian.com\" "
+
" xsi:nil=\"true\" />\n"
+
" </in0>\n"
+
" </authenticateApplication>\n"
+
" </soap:Body>\n"
+
"</soap:Envelope>\n"
);
private
static
final
MessageFormat
AUTHENTICATE_USER
=
new
MessageFormat
(
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" "
+
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
+
" <soap:Body>\n"
+
" <authenticatePrincipal xmlns=\"urn:SecurityServer\">\n"
+
" <in0>\n"
+
" <name xmlns=\"http://authentication.integration.crowd.atlassian.com\">{0}</name>\n"
+
" <token xmlns=\"http://authentication.integration.crowd.atlassian.com\">{1}</token>\n"
+
" </in0>\n"
+
" <in1>\n"
+
" <application xmlns=\"http://authentication.integration.crowd.atlassian.com\">{0}</application>\n"
+
" <credential xmlns=\"http://authentication.integration.crowd.atlassian.com\">\n"
+
" <credential>{3}</credential>\n"
+
" </credential>\n"
+
" <name xmlns=\"http://authentication.integration.crowd.atlassian.com\">{2}</name>\n"
+
" <validationFactors xmlns=\"http://authentication.integration.crowd.atlassian.com\" />\n"
+
" </in1>\n"
+
" </authenticatePrincipal>\n"
+
" </soap:Body>\n"
+
"</soap:Envelope>\n"
);
new
MessageFormat
(
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" "
+
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
+
" <soap:Body>\n"
+
" <authenticatePrincipal xmlns=\"urn:SecurityServer\">\n"
+
" <in0>\n"
+
" <name xmlns=\"http://authentication.integration.crowd.atlassian.com\">{0}</name>\n"
+
" <token xmlns=\"http://authentication.integration.crowd.atlassian.com\">{1}</token>\n"
+
" </in0>\n"
+
" <in1>\n"
+
" <application xmlns=\"http://authentication.integration.crowd.atlassian.com\">{0}</application>\n"
+
" <credential xmlns=\"http://authentication.integration.crowd.atlassian.com\">\n"
+
" <credential>{3}</credential>\n"
+
" </credential>\n"
+
" <name xmlns=\"http://authentication.integration.crowd.atlassian.com\">{2}</name>\n"
+
" <validationFactors xmlns=\"http://authentication.integration.crowd.atlassian.com\" />\n"
+
" </in1>\n"
+
" </authenticatePrincipal>\n"
+
" </soap:Body>\n"
+
"</soap:Envelope>\n"
);
private
final
String
url
;
private
final
String
application
;
private
final
String
applicationPassword
;
private
final
String
applicationPassword
;
public
CrowdAuthenticationService
(
String
host
,
int
port
,
String
application
,
String
applicationPassword
)
{
this
(
"https://"
+
host
+
":"
+
port
+
"/crowd/services/SecurityServer"
,
application
,
applicationPassword
);
}
public
CrowdAuthenticationService
(
String
url
,
String
application
,
String
applicationPassword
)
{
this
.
url
=
url
;
this
.
application
=
application
;
this
.
applicationPassword
=
applicationPassword
;
if
(
operationLog
.
isDebugEnabled
())
{
String
msg
=
"A new CrowdAuthenticationService instance has been created with following values ["
;
msg
+=
"url="
+
url
+
",application="
+
application
+
"]"
;
operationLog
.
debug
(
msg
);
}
}
public
boolean
authenticate
(
String
user
,
String
password
)
{
String
applicationToken
=
StringEscapeUtils
.
unescapeXml
(
execute
(
"token"
,
AUTHENTICATE_APPL
,
application
,
applicationPassword
));
String
userToken
=
StringEscapeUtils
.
unescapeXml
(
execute
(
"out"
,
AUTHENTICATE_USER
,
application
,
applicationToken
,
user
,
password
));
String
applicationToken
=
StringEscapeUtils
.
unescapeXml
(
execute
(
"token"
,
AUTHENTICATE_APPL
,
application
,
applicationPassword
));
if
(
applicationToken
==
null
)
{
operationLog
.
warn
(
"Application '"
+
application
+
"' could not be authenticated."
);
return
false
;
}
else
{
if
(
operationLog
.
isInfoEnabled
())
{
operationLog
.
info
(
"Application '"
+
application
+
"' successfully authenticated."
);
}
}
String
userToken
=
StringEscapeUtils
.
unescapeXml
(
execute
(
"out"
,
AUTHENTICATE_USER
,
application
,
applicationToken
,
user
,
password
));
if
(
userToken
==
null
)
{
operationLog
.
warn
(
"User '"
+
user
+
"' could not be authenticated with application '"
+
application
+
"'."
);
}
else
{
if
(
operationLog
.
isInfoEnabled
())
{
operationLog
.
info
(
"User '"
+
user
+
"' successfully authenticated with application '"
+
application
+
"'."
);
}
}
return
userToken
!=
null
;
}
...
...
@@ -101,21 +141,39 @@ public class CrowdAuthenticationService implements IAuthenticationService
return
pickElementContent
(
response
,
responseElement
);
}
/**
* Tries to find given <code>element</code> in given <code>xmlString</code>.
* <p>
* Returns <code>null</code> if given element could not be found.
* </p>
*/
private
String
pickElementContent
(
String
xmlString
,
String
element
)
{
int
index
=
xmlString
.
indexOf
(
"<"
+
element
);
if
(
index
<
0
)
{
if
(
operationLog
.
isDebugEnabled
())
{
operationLog
.
debug
(
"Element '"
+
element
+
"' could not be found in '"
+
StringUtils
.
abbreviate
(
xmlString
,
50
)
+
"'."
);
}
return
null
;
}
index
=
xmlString
.
indexOf
(
">"
,
index
);
if
(
index
<
0
)
{
if
(
operationLog
.
isDebugEnabled
())
{
operationLog
.
debug
(
"Element '"
+
element
+
"' could not be found in '"
+
StringUtils
.
abbreviate
(
xmlString
,
50
)
+
"'."
);
}
return
null
;
}
int
endIndex
=
xmlString
.
indexOf
(
"</"
+
element
,
index
);
if
(
endIndex
<
0
)
{
if
(
operationLog
.
isDebugEnabled
())
{
operationLog
.
debug
(
"Element '"
+
element
+
"' could not be found in '"
+
StringUtils
.
abbreviate
(
xmlString
,
50
)
+
"'."
);
}
return
null
;
}
return
xmlString
.
substring
(
index
+
1
,
endIndex
);
...
...
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