UserCredentials extends BaseIdentifiableObject implements UserDetails { public Set<String> getAllAuthorities() { final Set<String> resultingAuthorities = cachedAllAuthorities; if ( resultingAuthorities != null ) { return resultingAuthorities; } Set<String> authorities = new HashSet<>(); for ( UserAuthorityGroup group : userAuthorityGroups ) { authorities.addAll( group.getAuthorities() ); } authorities = Collections.unmodifiableSet( authorities ); cachedAllAuthorities = authorities; return authorities; } UserCredentials(); @Override void setAutoFields(); String getUserAuthorityGroupsName(); Set<String> getAllAuthorities(); boolean hasAuthorities(); boolean hasAnyAuthority( Collection<String> auths ); boolean isAuthorized( String auth ); boolean isSuper(); boolean canIssueUserRole( UserAuthorityGroup group, boolean canGrantOwnUserAuthorityGroups ); boolean canIssueUserRoles( Collection<UserAuthorityGroup> groups, boolean canGrantOwnUserAuthorityGroups ); boolean canModifyUser( UserCredentials other ); @Override String getName(); void updateLastLogin(); String isRestorable(); Set<DimensionalObject> getDimensionConstraints(); boolean hasUserAuthorityGroups(); boolean hasDimensionConstraints(); boolean hasLdapId(); boolean hasPassword(); @Override int hashCode(); @Override boolean equals( Object o ); UUID getUuid(); void setUuid( UUID uuid ); @JsonProperty @JsonSerialize( as = BaseIdentifiableObject.class ) @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) User getUserInfo(); void setUserInfo( User userInfo ); @Override @JsonProperty( access = JsonProperty.Access.WRITE_ONLY ) @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) @Property( value = PropertyType.PASSWORD, access = Access.WRITE_ONLY ) @PropertyRange( min = 8, max = 60 ) String getPassword(); void setPassword( String password ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) boolean isTwoFA(); void setTwoFA( boolean twoFA ); @JsonIgnore String getSecret(); void setSecret( String secret ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) boolean isExternalAuth(); void setExternalAuth( boolean externalAuth ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) Date getPasswordLastUpdated(); void setPasswordLastUpdated( Date passwordLastUpdated ); @JsonProperty( "userRoles" ) @JsonSerialize( contentAs = BaseIdentifiableObject.class ) @JacksonXmlElementWrapper( localName = "userRoles", namespace = DxfNamespaces.DXF_2_0 ) @JacksonXmlProperty( localName = "userRole", namespace = DxfNamespaces.DXF_2_0 ) Set<UserAuthorityGroup> getUserAuthorityGroups(); void setUserAuthorityGroups( Set<UserAuthorityGroup> userAuthorityGroups ); @JsonProperty @JsonSerialize( contentAs = BaseIdentifiableObject.class ) @JacksonXmlElementWrapper( localName = "catDimensionConstraints", namespace = DxfNamespaces.DXF_2_0 ) @JacksonXmlProperty( localName = "catDimensionConstraint", namespace = DxfNamespaces.DXF_2_0 ) Set<Category> getCatDimensionConstraints(); void setCatDimensionConstraints( Set<Category> catDimensionConstraints ); @JsonProperty @JsonSerialize( contentAs = BaseIdentifiableObject.class ) @JacksonXmlElementWrapper( localName = "cogsDimensionConstraints", namespace = DxfNamespaces.DXF_2_0 ) @JacksonXmlProperty( localName = "cogsDimensionConstraint", namespace = DxfNamespaces.DXF_2_0 ) Set<CategoryOptionGroupSet> getCogsDimensionConstraints(); void setCogsDimensionConstraints( Set<CategoryOptionGroupSet> cogsDimensionConstraints ); List<String> getPreviousPasswords(); void setPreviousPasswords( List<String> previousPasswords ); @Override @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) String getUsername(); void setUsername( String username ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) String getOpenId(); void setOpenId( String openId ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) String getLdapId(); void setLdapId( String ldapId ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) Date getLastLogin(); void setLastLogin( Date lastLogin ); String getRestoreToken(); void setRestoreToken( String restoreToken ); Date getRestoreExpiry(); void setRestoreExpiry( Date restoreExpiry ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) boolean isSelfRegistered(); void setSelfRegistered( boolean selfRegistered ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) boolean isInvitation(); void setInvitation( boolean invitation ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) boolean isDisabled(); void setDisabled( boolean disabled ); @Override String toString(); @Override Collection<GrantedAuthority> getAuthorities(); @Override boolean isAccountNonExpired(); @Override boolean isAccountNonLocked(); @Override boolean isCredentialsNonExpired(); @Override boolean isEnabled(); static final int USERNAME_MAX_LENGTH; }
@Test public void getAllAuthorities() { final UserCredentials userCredentials = new UserCredentials(); userCredentials.setUserAuthorityGroups( new HashSet<>( Arrays.asList( userAuthorityGroup1, userAuthorityGroup1Super ) ) ); Set<String> authorities1 = userCredentials.getAllAuthorities(); Assert.assertThat( authorities1, Matchers.containsInAnyOrder( "x1", "x2", "z1", UserAuthorityGroup.AUTHORITY_ALL ) ); Set<String> authorities2 = userCredentials.getAllAuthorities(); Assert.assertSame( authorities1, authorities2 ); }