Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OLAT CI-CD Testing Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor 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
Lars Oliver Dam
OLAT CI-CD Testing Project
Commits
c9066036
Commit
c9066036
authored
12 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
OO-290: synchronize login in WebDAV as in standard OLAT Servlet
parent
da94c4ab
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
src/main/java/org/olat/commons/servlets/WebDAVManagerImpl.java
+73
-56
73 additions, 56 deletions
...ain/java/org/olat/commons/servlets/WebDAVManagerImpl.java
with
73 additions
and
56 deletions
src/main/java/org/olat/commons/servlets/WebDAVManagerImpl.java
+
73
−
56
View file @
c9066036
...
...
@@ -107,7 +107,9 @@ public class WebDAVManagerImpl extends WebDAVManager {
if
(
authHeader
!=
null
)
{
// fetch user session from a previous authentication
UserSession
usess
=
(
UserSession
)
timedSessionCache
.
get
(
authHeader
);
if
(
usess
!=
null
&&
usess
.
isAuthenticated
())
return
usess
;
if
(
usess
!=
null
&&
usess
.
isAuthenticated
())
{
return
usess
;
}
StringTokenizer
st
=
new
StringTokenizer
(
authHeader
);
if
(
st
.
hasMoreTokens
())
{
...
...
@@ -116,63 +118,14 @@ public class WebDAVManagerImpl extends WebDAVManager {
// We only handle HTTP Basic authentication
if
(
basic
.
equalsIgnoreCase
(
"Basic"
))
{
String
credentials
=
st
.
nextToken
();
// This example uses sun.misc.* classes.
// You will need to provide your own
// if you are not comfortable with that.
String
userPass
=
Base64Decoder
.
decode
(
credentials
);
// The decoded string is in the form
// "userID:password".
int
p
=
userPass
.
indexOf
(
":"
);
if
(
p
!=
-
1
)
{
String
userID
=
userPass
.
substring
(
0
,
p
);
String
password
=
userPass
.
substring
(
p
+
1
);
// Validate user ID and password
// and set valid true if valid.
// In this example, we simply check
// that neither field is blank
Identity
identity
=
WebDAVAuthManager
.
authenticate
(
userID
,
password
);
if
(
identity
!=
null
)
{
usess
=
UserSession
.
getUserSession
(
request
);
usess
.
signOffAndClear
();
usess
.
setIdentity
(
identity
);
UserDeletionManager
.
getInstance
().
setIdentityAsActiv
(
identity
);
// set the roles (admin, author, guest)
Roles
roles
=
BaseSecurityManager
.
getInstance
().
getRoles
(
identity
);
usess
.
setRoles
(
roles
);
// set authprovider
//usess.getIdentityEnvironment().setAuthProvider(OLATAuthenticationController.PROVIDER_OLAT);
// set session info
SessionInfo
sinfo
=
new
SessionInfo
(
identity
.
getName
(),
request
.
getSession
());
User
usr
=
identity
.
getUser
();
sinfo
.
setFirstname
(
usr
.
getProperty
(
UserConstants
.
FIRSTNAME
,
null
));
sinfo
.
setLastname
(
usr
.
getProperty
(
UserConstants
.
LASTNAME
,
null
));
sinfo
.
setFromIP
(
request
.
getRemoteAddr
());
sinfo
.
setFromFQN
(
request
.
getRemoteAddr
());
try
{
InetAddress
[]
iaddr
=
InetAddress
.
getAllByName
(
request
.
getRemoteAddr
());
if
(
iaddr
.
length
>
0
)
sinfo
.
setFromFQN
(
iaddr
[
0
].
getHostName
());
}
catch
(
UnknownHostException
e
)
{
// ok, already set IP as FQDN
}
sinfo
.
setAuthProvider
(
BaseSecurityModule
.
getDefaultAuthProviderIdentifier
());
sinfo
.
setUserAgent
(
request
.
getHeader
(
"User-Agent"
));
sinfo
.
setSecure
(
request
.
isSecure
());
sinfo
.
setWebDAV
(
true
);
sinfo
.
setWebModeFromUreq
(
null
);
// set session info for this session
usess
.
setSessionInfo
(
sinfo
);
//
usess
.
signOn
();
timedSessionCache
.
put
(
authHeader
,
usess
);
return
usess
;
}
}
usess
=
handleBasicAuthentication
(
credentials
,
request
);
}
}
if
(
usess
!=
null
)
{
timedSessionCache
.
put
(
authHeader
,
usess
);
}
}
// If the user was not validated or the browser does not know about the realm yet, fail with a
...
...
@@ -191,6 +144,70 @@ public class WebDAVManagerImpl extends WebDAVManager {
return
null
;
}
private
UserSession
handleBasicAuthentication
(
String
credentials
,
HttpServletRequest
request
)
{
// This example uses sun.misc.* classes.
// You will need to provide your own
// if you are not comfortable with that.
String
userPass
=
Base64Decoder
.
decode
(
credentials
);
// The decoded string is in the form
// "userID:password".
int
p
=
userPass
.
indexOf
(
":"
);
if
(
p
!=
-
1
)
{
String
userID
=
userPass
.
substring
(
0
,
p
);
String
password
=
userPass
.
substring
(
p
+
1
);
// Validate user ID and password
// and set valid true if valid.
// In this example, we simply check
// that neither field is blank
Identity
identity
=
WebDAVAuthManager
.
authenticate
(
userID
,
password
);
if
(
identity
!=
null
)
{
UserSession
usess
=
UserSession
.
getUserSession
(
request
);
synchronized
(
usess
)
{
//double check to prevent severals concurrent login
if
(
usess
.
isAuthenticated
())
{
return
usess
;
}
usess
.
signOffAndClear
();
usess
.
setIdentity
(
identity
);
UserDeletionManager
.
getInstance
().
setIdentityAsActiv
(
identity
);
// set the roles (admin, author, guest)
Roles
roles
=
BaseSecurityManager
.
getInstance
().
getRoles
(
identity
);
usess
.
setRoles
(
roles
);
// set authprovider
//usess.getIdentityEnvironment().setAuthProvider(OLATAuthenticationController.PROVIDER_OLAT);
// set session info
SessionInfo
sinfo
=
new
SessionInfo
(
identity
.
getName
(),
request
.
getSession
());
User
usr
=
identity
.
getUser
();
sinfo
.
setFirstname
(
usr
.
getProperty
(
UserConstants
.
FIRSTNAME
,
null
));
sinfo
.
setLastname
(
usr
.
getProperty
(
UserConstants
.
LASTNAME
,
null
));
sinfo
.
setFromIP
(
request
.
getRemoteAddr
());
sinfo
.
setFromFQN
(
request
.
getRemoteAddr
());
try
{
InetAddress
[]
iaddr
=
InetAddress
.
getAllByName
(
request
.
getRemoteAddr
());
if
(
iaddr
.
length
>
0
)
sinfo
.
setFromFQN
(
iaddr
[
0
].
getHostName
());
}
catch
(
UnknownHostException
e
)
{
// ok, already set IP as FQDN
}
sinfo
.
setAuthProvider
(
BaseSecurityModule
.
getDefaultAuthProviderIdentifier
());
sinfo
.
setUserAgent
(
request
.
getHeader
(
"User-Agent"
));
sinfo
.
setSecure
(
request
.
isSecure
());
sinfo
.
setWebDAV
(
true
);
sinfo
.
setWebModeFromUreq
(
null
);
// set session info for this session
usess
.
setSessionInfo
(
sinfo
);
//
usess
.
signOn
();
return
usess
;
}
}
}
return
null
;
}
/**
* @see org.olat.core.servlets.WebDAVManager#isEnabled()
...
...
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