]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.security.core/src/org/argeo/security/jcr/SecureThreadBoundSession.java
Move security model to CMS
[lgpl/argeo-commons.git] / org.argeo.security.core / src / org / argeo / security / jcr / SecureThreadBoundSession.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.security.jcr;
17
18 import javax.jcr.Session;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.argeo.jcr.spring.ThreadBoundSession;
23 import org.springframework.security.core.Authentication;
24 import org.springframework.security.core.context.SecurityContextHolder;
25
26 /**
27 * Thread bounded JCR session factory which checks authentication and is
28 * autoconfigured in Spring.
29 */
30 @Deprecated
31 public class SecureThreadBoundSession extends ThreadBoundSession {
32 private final static Log log = LogFactory
33 .getLog(SecureThreadBoundSession.class);
34
35 @Override
36 protected Session preCall(Session session) {
37 Authentication authentication = SecurityContextHolder.getContext()
38 .getAuthentication();
39 if (authentication != null) {
40 String userID = session.getUserID();
41 String currentUserName = authentication.getName();
42 if (currentUserName != null) {
43 if (!userID.equals(currentUserName)) {
44 log.warn("Current session has user ID " + userID
45 + " while logged is user is " + currentUserName
46 + "(authentication=" + authentication + ")"
47 + ". Re-login.");
48 // TODO throw an exception
49 return login();
50 }
51 }
52 }
53 return super.preCall(session);
54 }
55
56 }