import java.util.HashSet;\r
import java.util.Set;\r
\r
+import javax.persistence.Column;\r
import javax.persistence.Entity;\r
import javax.persistence.FetchType;\r
import javax.persistence.ManyToMany;\r
import org.apache.log4j.Logger;\r
import org.hibernate.annotations.Cascade;\r
import org.hibernate.annotations.CascadeType;\r
-import org.hibernate.annotations.NaturalId;\r
import org.hibernate.envers.Audited;\r
import org.hibernate.envers.NotAudited;\r
import org.hibernate.search.annotations.Analyze;\r
private static final long serialVersionUID = 6582191171369439163L;\r
private static final Logger logger = Logger.getLogger(User.class);\r
\r
- protected User(){\r
- super();\r
- }\r
-\r
+ // **************************** FACTORY *****************************************/ \r
+ \r
public static User NewInstance(String username, String pwd){\r
User user = new User();\r
user.setUsername(username);\r
return user;\r
}\r
\r
+//***************************** Fields *********************** /\r
+ \r
@XmlElement(name = "Username")\r
- @NaturalId\r
+ @Column(unique = true)\r
@Field(analyze = Analyze.NO)\r
protected String username;\r
\r
@XmlIDREF\r
@XmlSchemaType(name = "IDREF")\r
@ManyToMany(fetch = FetchType.LAZY, targetEntity = GrantedAuthorityImpl.class)\r
- @Cascade(CascadeType.SAVE_UPDATE)\r
+ @Cascade({CascadeType.SAVE_UPDATE, CascadeType.REFRESH}) // see #2414 (Group updating doesn't work)\r
@NotAudited\r
protected Set<GrantedAuthority> grantedAuthorities = new HashSet<GrantedAuthority>(); //authorities of this user only\r
\r
@XmlIDREF\r
@XmlSchemaType(name = "IDREF")\r
@ManyToMany(fetch = FetchType.LAZY)\r
+ @Cascade(CascadeType.REFRESH) // see #2414 (Group updating doesn't work)\r
@IndexedEmbedded(depth = 1)\r
@NotAudited\r
protected Set<Group> groups = new HashSet<Group>();\r
@Transient\r
private Set<GrantedAuthority> authorities; //authorities of this user and of all groups the user belongs to\r
\r
- private void initAuthorities() {\r
+//***************************** Constructor *********************** /\r
+ \r
+ protected User(){\r
+ super();\r
+ }\r
+ \r
+// ***************************** METHODS ******************************/\r
+ \r
+ /**\r
+ * Initializes or refreshes the collection of authorities, See\r
+ * {@link #getAuthorities()}\r
+ */\r
+ //FIXME made public as preliminary solution to #4053 (Transient field User.authorities not refreshed on reloading entity)\r
+ public void initAuthorities() {\r
authorities = new HashSet<GrantedAuthority>();\r
authorities.addAll(grantedAuthorities);\r
for(Group group : groups) {\r
}\r
\r
/**\r
+ * Implementation of {@link UserDetails#getAuthorities()}\r
+ *\r
* {@inheritDoc}\r
*\r
- * @return returns a {@code Set<GrantedAuthority>} as Collection\r
+ * @return returns all {@code Set<GrantedAuthority>} instances contained in\r
+ * the sets {@link #getGrantedAuthorities()} and\r
+ * {@link #getGroups()}\r
*/\r
@Override\r
@Transient\r