]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/jcr/JcrUserDetails.java
Fix Remote RCP not working
[lgpl/argeo-commons.git] / security / runtime / org.argeo.security.core / src / main / java / org / argeo / security / jcr / JcrUserDetails.java
index 05ae165e03fbcccd0d63be4679745b787742f567..2f7b97b7842565bc6512f584fd814d1310e68988 100644 (file)
@@ -1,14 +1,30 @@
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.argeo.security.jcr;
 
 import java.util.ArrayList;
 import java.util.List;
 
 import javax.jcr.Node;
+import javax.jcr.Property;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
 import org.argeo.jcr.ArgeoNames;
-import org.argeo.jcr.JcrUtils;
+import org.argeo.jcr.UserJcrUtils;
 import org.springframework.security.BadCredentialsException;
 import org.springframework.security.DisabledException;
 import org.springframework.security.GrantedAuthority;
@@ -22,6 +38,9 @@ public class JcrUserDetails extends User implements ArgeoNames {
        private final String homePath;
        private final String securityWorkspace;
 
+       /** Human readable user name */
+       private String displayName;
+
        protected JcrUserDetails(String securityWorkspace, String homePath,
                        String username, String password, boolean enabled,
                        boolean accountNonExpired, boolean credentialsNonExpired,
@@ -43,6 +62,15 @@ public class JcrUserDetails extends User implements ArgeoNames {
                                userProfile.getProperty(ARGEO_CREDENTIALS_NON_EXPIRED)
                                                .getBoolean(), userProfile.getProperty(
                                                ARGEO_ACCOUNT_NON_LOCKED).getBoolean(), authorities);
+               // human readable name
+               if (userProfile.hasProperty(Property.JCR_TITLE)) {
+                       displayName = userProfile.getProperty(Property.JCR_TITLE)
+                                       .getString();
+                       if (displayName.trim().equals(""))
+                               displayName = null;
+               }
+               if (displayName == null)
+                       displayName = userProfile.getProperty(ARGEO_USER_ID).getString();
                // home is defined as the parent of the profile
                homePath = userProfile.getParent().getPath();
                securityWorkspace = userProfile.getSession().getWorkspace().getName();
@@ -62,7 +90,7 @@ public class JcrUserDetails extends User implements ArgeoNames {
         */
        public JcrUserDetails(Session session, String username, String password,
                        GrantedAuthority[] authorities) throws RepositoryException {
-               this(JcrUtils.getUserProfile(session, username),
+               this(UserJcrUtils.getUserProfile(session, username),
                                password != null ? password : "", authorities);
        }
 
@@ -109,4 +137,15 @@ public class JcrUserDetails extends User implements ArgeoNames {
        public String getSecurityWorkspace() {
                return securityWorkspace;
        }
+
+       /** The human readable name of this user */
+       public String getDisplayName() {
+               return displayName;
+       }
+
+       @Override
+       public String toString() {
+               return getDisplayName();
+       }
+
 }