public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { { String theNamespace; theNamespace = this.getNamespace(); strategy.appendField(locator, this, "namespace", buffer, theNamespace, (this.namespace!= null)); } { List<NamespacePermissionEnum> theNamespacePermissions; theNamespacePermissions = ((this.namespacePermissions!= null)?this.getNamespacePermissions():null); strategy.appendField(locator, this, "namespacePermissions", buffer, theNamespacePermissions, (this.namespacePermissions!= null)); } return buffer; }
@Test public void testBuildNamespaceAuthorizationsAssertWildcardQueryExecuted() { ApplicationUser applicationUser = new ApplicationUser(getClass()); String userId = "userId"; applicationUser.setUserId(userId); when(configurationHelper.getBooleanProperty(any())).thenReturn(true); List<UserNamespaceAuthorizationEntity> wildcardEntities = new ArrayList<>(); UserNamespaceAuthorizationEntity wildcardEntity = new UserNamespaceAuthorizationEntity(); wildcardEntity.setUserId("wildcardEntityUserId"); NamespaceEntity namespaceEntity = new NamespaceEntity(); namespaceEntity.setCode("namespace"); wildcardEntity.setNamespace(namespaceEntity); wildcardEntities.add(wildcardEntity); when(userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByUserIdStartsWith(any())).thenReturn(wildcardEntities); when(wildcardHelper.matches(any(), any())).thenReturn(true); userNamespaceAuthorizationHelper.buildNamespaceAuthorizations(applicationUser); assertEquals(1, applicationUser.getNamespaceAuthorizations().size()); NamespaceAuthorization namespaceAuthorization = IterableUtils.get(applicationUser.getNamespaceAuthorizations(), 0); assertEquals(namespaceEntity.getCode(), namespaceAuthorization.getNamespace()); verify(userNamespaceAuthorizationDao).getUserNamespaceAuthorizationsByUserId(eq(userId)); verify(userNamespaceAuthorizationDao).getUserNamespaceAuthorizationsByUserIdStartsWith(eq(WildcardHelper.WILDCARD_TOKEN)); verify(wildcardHelper).matches(eq(userId.toUpperCase()), eq(wildcardEntity.getUserId().toUpperCase())); verifyNoMoreInteractions(userNamespaceAuthorizationDao, wildcardHelper); }
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { { String theNamespace; theNamespace = this.getNamespace(); strategy.appendField(locator, this, "namespace", buffer, theNamespace, (this.namespace!= null)); } { List<NamespacePermissionEnum> theNamespacePermissions; theNamespacePermissions = ((this.namespacePermissions!= null)?this.getNamespacePermissions():null); strategy.appendField(locator, this, "namespacePermissions", buffer, theNamespacePermissions, (this.namespacePermissions!= null)); } return buffer; }
@Test public void testBuildNamespaceAuthorizationsAssertAuthLookupByUserId() { ApplicationUser applicationUser = new ApplicationUser(getClass()); String userId = "userId"; applicationUser.setUserId(userId); when(configurationHelper.getBooleanProperty(any())).thenReturn(true); List<UserNamespaceAuthorizationEntity> userNamespaceAuthorizationEntities = new ArrayList<>(); UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity = new UserNamespaceAuthorizationEntity(); userNamespaceAuthorizationEntity.setUserId("userNamespaceAuthorizationEntityUserId"); NamespaceEntity namespaceEntity = new NamespaceEntity(); namespaceEntity.setCode("namespace"); userNamespaceAuthorizationEntity.setNamespace(namespaceEntity); userNamespaceAuthorizationEntities.add(userNamespaceAuthorizationEntity); when(userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByUserId(any())).thenReturn(userNamespaceAuthorizationEntities); userNamespaceAuthorizationHelper.buildNamespaceAuthorizations(applicationUser); assertEquals(1, applicationUser.getNamespaceAuthorizations().size()); NamespaceAuthorization namespaceAuthorization = IterableUtils.get(applicationUser.getNamespaceAuthorizations(), 0); assertEquals(namespaceEntity.getCode(), namespaceAuthorization.getNamespace()); verify(userNamespaceAuthorizationDao).getUserNamespaceAuthorizationsByUserId(eq(userId)); verify(userNamespaceAuthorizationDao).getUserNamespaceAuthorizationsByUserIdStartsWith(eq(WildcardHelper.WILDCARD_TOKEN)); verifyNoMoreInteractions(userNamespaceAuthorizationDao, wildcardHelper); }
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { { String theNamespace; theNamespace = this.getNamespace(); strategy.appendField(locator, this, "namespace", buffer, theNamespace, (this.namespace!= null)); } { List<NamespacePermissionEnum> theNamespacePermissions; theNamespacePermissions = ((this.namespacePermissions!= null)?this.getNamespacePermissions():null); strategy.appendField(locator, this, "namespacePermissions", buffer, theNamespacePermissions, (this.namespacePermissions!= null)); } return buffer; }
/** * Gets a set of namespace codes which the current user is authorized for the given permissions. * * @param permissions List of permissions to query * * @return Set of namespace codes */ public Set<String> getAuthorizedNamespaces(NamespacePermissionEnum... permissions) { Set<String> namespaces = new HashSet<>(); if (SecurityContextHolder.getContext().getAuthentication() != null) { ApplicationUser applicationUser = getApplicationUser(); if (applicationUser != null) { for (NamespaceAuthorization namespaceAuthorization : applicationUser.getNamespaceAuthorizations()) { if (namespaceAuthorization.getNamespacePermissions().containsAll(Arrays.asList(permissions))) { namespaces.add(namespaceAuthorization.getNamespace()); } } } } return namespaces; }
/** * Gets a set of namespace codes which the current user is authorized for the given permissions. * * @param permissions List of permissions to query * * @return Set of namespace codes */ public Set<String> getAuthorizedNamespaces(NamespacePermissionEnum... permissions) { Set<String> namespaces = new HashSet<>(); if (SecurityContextHolder.getContext().getAuthentication() != null) { ApplicationUser applicationUser = getApplicationUser(); if (applicationUser != null) { for (NamespaceAuthorization namespaceAuthorization : applicationUser.getNamespaceAuthorizations()) { if (namespaceAuthorization.getNamespacePermissions().containsAll(Arrays.asList(permissions))) { namespaces.add(namespaceAuthorization.getNamespace()); } } } } return namespaces; }
/** * Returns true if the application user is authorized to the given namespace and has the given permissions. * * @param applicationUser the application user * @param namespace the namespace * @param permissions the permissions * * @return true if authorized, false otherwise */ private boolean isAuthorized(ApplicationUser applicationUser, String namespace, NamespacePermissionEnum... permissions) { if (applicationUser != null && applicationUser.getNamespaceAuthorizations() != null) { for (NamespaceAuthorization currentUserAuthorization : applicationUser.getNamespaceAuthorizations()) { List<NamespacePermissionEnum> currentUserNamespacePermissions = currentUserAuthorization.getNamespacePermissions(); if (currentUserNamespacePermissions == null) { currentUserNamespacePermissions = Collections.emptyList(); } if (StringUtils.equalsIgnoreCase(currentUserAuthorization.getNamespace(), namespace) && currentUserNamespacePermissions.stream().anyMatch(Arrays.asList(permissions)::contains)) { return true; } } } return false; }
/** * Returns true if the application user is authorized to the given namespace and has the given permissions. * * @param applicationUser the application user * @param namespace the namespace * @param permissions the permissions * * @return true if authorized, false otherwise */ private boolean isAuthorized(ApplicationUser applicationUser, String namespace, NamespacePermissionEnum... permissions) { if (applicationUser != null && applicationUser.getNamespaceAuthorizations() != null) { for (NamespaceAuthorization currentUserAuthorization : applicationUser.getNamespaceAuthorizations()) { List<NamespacePermissionEnum> currentUserNamespacePermissions = currentUserAuthorization.getNamespacePermissions(); if (currentUserNamespacePermissions == null) { currentUserNamespacePermissions = Collections.emptyList(); } if (StringUtils.equalsIgnoreCase(currentUserAuthorization.getNamespace(), namespace) && currentUserNamespacePermissions.stream().anyMatch(Arrays.asList(permissions)::contains)) { return true; } } } return false; }
public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) { int currentHashCode = 1; { String theNamespace; theNamespace = this.getNamespace(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "namespace", theNamespace), currentHashCode, theNamespace, (this.namespace!= null)); } { List<NamespacePermissionEnum> theNamespacePermissions; theNamespacePermissions = ((this.namespacePermissions!= null)?this.getNamespacePermissions():null); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "namespacePermissions", theNamespacePermissions), currentHashCode, theNamespacePermissions, (this.namespacePermissions!= null)); } return currentHashCode; }
public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) { int currentHashCode = 1; { String theNamespace; theNamespace = this.getNamespace(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "namespace", theNamespace), currentHashCode, theNamespace, (this.namespace!= null)); } { List<NamespacePermissionEnum> theNamespacePermissions; theNamespacePermissions = ((this.namespacePermissions!= null)?this.getNamespacePermissions():null); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "namespacePermissions", theNamespacePermissions), currentHashCode, theNamespacePermissions, (this.namespacePermissions!= null)); } return currentHashCode; }
public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Object object, EqualsStrategy2 strategy) { if ((object == null)||(this.getClass()!= object.getClass())) { return false; } if (this == object) { return true; } final NamespaceAuthorization that = ((NamespaceAuthorization) object); { String lhsNamespace; lhsNamespace = this.getNamespace(); String rhsNamespace; rhsNamespace = that.getNamespace(); if (!strategy.equals(LocatorUtils.property(thisLocator, "namespace", lhsNamespace), LocatorUtils.property(thatLocator, "namespace", rhsNamespace), lhsNamespace, rhsNamespace, (this.namespace!= null), (that.namespace!= null))) { return false; } } { List<NamespacePermissionEnum> lhsNamespacePermissions; lhsNamespacePermissions = ((this.namespacePermissions!= null)?this.getNamespacePermissions():null); List<NamespacePermissionEnum> rhsNamespacePermissions; rhsNamespacePermissions = ((that.namespacePermissions!= null)?that.getNamespacePermissions():null); if (!strategy.equals(LocatorUtils.property(thisLocator, "namespacePermissions", lhsNamespacePermissions), LocatorUtils.property(thatLocator, "namespacePermissions", rhsNamespacePermissions), lhsNamespacePermissions, rhsNamespacePermissions, (this.namespacePermissions!= null), (that.namespacePermissions!= null))) { return false; } } return true; }
public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Object object, EqualsStrategy2 strategy) { if ((object == null)||(this.getClass()!= object.getClass())) { return false; } if (this == object) { return true; } final NamespaceAuthorization that = ((NamespaceAuthorization) object); { String lhsNamespace; lhsNamespace = this.getNamespace(); String rhsNamespace; rhsNamespace = that.getNamespace(); if (!strategy.equals(LocatorUtils.property(thisLocator, "namespace", lhsNamespace), LocatorUtils.property(thatLocator, "namespace", rhsNamespace), lhsNamespace, rhsNamespace, (this.namespace!= null), (that.namespace!= null))) { return false; } } { List<NamespacePermissionEnum> lhsNamespacePermissions; lhsNamespacePermissions = ((this.namespacePermissions!= null)?this.getNamespacePermissions():null); List<NamespacePermissionEnum> rhsNamespacePermissions; rhsNamespacePermissions = ((that.namespacePermissions!= null)?that.getNamespacePermissions():null); if (!strategy.equals(LocatorUtils.property(thisLocator, "namespacePermissions", lhsNamespacePermissions), LocatorUtils.property(thatLocator, "namespacePermissions", rhsNamespacePermissions), lhsNamespacePermissions, rhsNamespacePermissions, (this.namespacePermissions!= null), (that.namespacePermissions!= null))) { return false; } } return true; }
public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) { int currentHashCode = 1; { String theNamespace; theNamespace = this.getNamespace(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "namespace", theNamespace), currentHashCode, theNamespace, (this.namespace!= null)); } { List<NamespacePermissionEnum> theNamespacePermissions; theNamespacePermissions = ((this.namespacePermissions!= null)?this.getNamespacePermissions():null); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "namespacePermissions", theNamespacePermissions), currentHashCode, theNamespacePermissions, (this.namespacePermissions!= null)); } return currentHashCode; }
public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Object object, EqualsStrategy2 strategy) { if ((object == null)||(this.getClass()!= object.getClass())) { return false; } if (this == object) { return true; } final NamespaceAuthorization that = ((NamespaceAuthorization) object); { String lhsNamespace; lhsNamespace = this.getNamespace(); String rhsNamespace; rhsNamespace = that.getNamespace(); if (!strategy.equals(LocatorUtils.property(thisLocator, "namespace", lhsNamespace), LocatorUtils.property(thatLocator, "namespace", rhsNamespace), lhsNamespace, rhsNamespace, (this.namespace!= null), (that.namespace!= null))) { return false; } } { List<NamespacePermissionEnum> lhsNamespacePermissions; lhsNamespacePermissions = ((this.namespacePermissions!= null)?this.getNamespacePermissions():null); List<NamespacePermissionEnum> rhsNamespacePermissions; rhsNamespacePermissions = ((that.namespacePermissions!= null)?that.getNamespacePermissions():null); if (!strategy.equals(LocatorUtils.property(thisLocator, "namespacePermissions", lhsNamespacePermissions), LocatorUtils.property(thatLocator, "namespacePermissions", rhsNamespacePermissions), lhsNamespacePermissions, rhsNamespacePermissions, (this.namespacePermissions!= null), (that.namespacePermissions!= null))) { return false; } } return true; }
if (namespaceShouldBeCopiedAndSet == Boolean.TRUE) { String sourceNamespace; sourceNamespace = this.getNamespace(); String copyNamespace = ((String) strategy.copy(LocatorUtils.property(locator, "namespace", sourceNamespace), sourceNamespace, (this.namespace!= null))); copy.setNamespace(copyNamespace);
if (namespaceShouldBeCopiedAndSet == Boolean.TRUE) { String sourceNamespace; sourceNamespace = this.getNamespace(); String copyNamespace = ((String) strategy.copy(LocatorUtils.property(locator, "namespace", sourceNamespace), sourceNamespace, (this.namespace!= null))); copy.setNamespace(copyNamespace);
if (namespaceShouldBeCopiedAndSet == Boolean.TRUE) { String sourceNamespace; sourceNamespace = this.getNamespace(); String copyNamespace = ((String) strategy.copy(LocatorUtils.property(locator, "namespace", sourceNamespace), sourceNamespace, (this.namespace!= null))); copy.setNamespace(copyNamespace);