/** * Add a user field to the document with the given key. * * @param document * @param key * @param user */ protected void addUser(JsonObject document, String key, User user) { if (user != null) { // TODO make sure field names match response UserResponse field names.. JsonObject userFields = new JsonObject(); userFields.put("uuid", user.getUuid()); document.put(key, userFields); } }
public static User mockUser(String username, String firstname, String lastname, User creator) { User user = mock(User.class); when(user.getUsername()).thenReturn(username); when(user.getFirstname()).thenReturn(firstname); when(user.getLastname()).thenReturn(lastname); when(user.getEmailAddress()).thenReturn(username + "@nowhere.tld"); when(user.getUuid()).thenReturn(USER_EDITOR_UUID); when(user.getCreationTimestamp()).thenReturn(TIMESTAMP_OLD); when(user.getLastEditedTimestamp()).thenReturn(TIMESTAMP_NEW); if (creator != null) { when(user.getCreator()).thenReturn(creator); when(user.getEditor()).thenReturn(creator); } when(user.getRolesWithPerm(GraphPermission.READ_PERM)).thenReturn(createEmptyTraversal()); when(user.getElementVersion()).thenReturn(UUID_1); return user; }
/** * Generate a new JWT which can be used as an API key. * * @param user * @param tokenCode * Code which will be part of the JWT. This code is used to verify that the JWT is still valid * @param expireDuration * @return Generated API key */ public String generateAPIToken(com.gentics.mesh.core.data.User user, String tokenCode, Integer expireDuration) { AuthenticationOptions options = Mesh.mesh().getOptions().getAuthenticationOptions(); JsonObject tokenData = new JsonObject() .put(USERID_FIELD_NAME, user.getUuid()) .put(API_KEY_TOKEN_CODE_FIELD_NAME, tokenCode); JWTOptions jwtOptions = new JWTOptions().setAlgorithm(options.getAlgorithm()); if (expireDuration != null) { jwtOptions.setExpiresInMinutes(expireDuration); } return jwtProvider.generateToken(tokenData, jwtOptions); }
public SchemaResponseAssert matches(SchemaContainer schema) { // TODO make schemas extends generic nodes? // assertGenericNode(schema, restSchema); assertNotNull(schema); assertNotNull(actual); String creatorUuid = schema.getCreator().getUuid(); String editorUuid = schema.getEditor().getUuid(); assertEquals("The editor of the schema did not match up.", editorUuid, actual.getEditor().getUuid()); assertEquals("The creator of the schema did not match up.", creatorUuid, actual.getCreator().getUuid()); assertEquals("The creation date did not match up", schema.getCreationDate(), actual.getCreated()); assertEquals("The edited date did not match up", schema.getLastEditedDate(), actual.getEdited()); // assertEquals("Name does not match with the requested name.", schema.getName(), restSchema.getName()); // assertEquals("Description does not match with the requested description.", schema.getDescription(), restSchema.getDescription()); // assertEquals("Display names do not match.", schema.getDisplayName(), restSchema.getDisplayName()); // TODO verify other fields return this; }
public UserResponseAssert matches(User user) { assertNotNull("The user must not be null.", user); assertNotNull("The restuser must not be null", actual); // user = neo4jTemplate.fetch(user); assertEquals(user.getUsername(), actual.getUsername()); assertEquals(user.getEmailAddress(), actual.getEmailAddress()); assertEquals(user.getFirstname(), actual.getFirstname()); assertEquals(user.getLastname(), actual.getLastname()); assertEquals(user.getUuid(), actual.getUuid()); assertEquals(user.getGroups().count(), actual.getGroups().size()); // TODO groups return this; }
public void assertGenericNode(MeshCoreVertex<?, ?> node, AbstractGenericRestResponse model) { assertNotNull(node); assertNotNull(model); assertNotNull("UUID field was not set in the rest response.", model.getUuid()); assertEquals("The uuids should not be different", node.getUuid(), model.getUuid()); assertNotNull("Permissions field was not set in the rest response.", model.getPermissions()); assertNotNull("Creator field was not set in the rest response.", model.getCreator()); assertNotNull("Editor field was not set in the rest response.", model.getEditor()); if (node instanceof EditorTrackingVertex) { EditorTrackingVertex editedNode = (EditorTrackingVertex) node; assertNotNull("The editor of the graph node was not set.", editedNode.getEditor()); assertEquals(editedNode.getEditor().getFirstname(), model.getEditor().getFirstName()); assertEquals(editedNode.getEditor().getLastname(), model.getEditor().getLastName()); assertEquals(editedNode.getEditor().getUuid(), model.getEditor().getUuid()); } if (node instanceof CreatorTrackingVertex) { CreatorTrackingVertex createdNode = (CreatorTrackingVertex) node; assertEquals(createdNode.getCreator().getFirstname(), model.getCreator().getFirstName()); assertEquals(createdNode.getCreator().getLastname(), model.getCreator().getLastName()); assertEquals(createdNode.getCreator().getUuid(), model.getCreator().getUuid()); } } }
public void assertGenericNode(MeshCoreVertex<?, ?> node, AbstractGenericRestResponse model) { assertNotNull(node); assertNotNull(model); assertNotNull("UUID field was not set in the rest response.", model.getUuid()); assertEquals("The uuids should not be different", node.getUuid(), model.getUuid()); assertNotNull("Permissions field was not set in the rest response.", model.getPermissions()); if (node instanceof EditorTrackingVertex) { assertNotNull("Editor field was not set in the rest response.", model.getEditor()); EditorTrackingVertex editedNode = (EditorTrackingVertex) node; assertNotNull("The editor of the graph node was not set.", editedNode.getEditor()); assertEquals(editedNode.getEditor().getFirstname(), model.getEditor()); assertEquals(editedNode.getEditor().getLastname(), model.getEditor().getLastName()); assertEquals(editedNode.getEditor().getUuid(), model.getEditor().getUuid()); } if (node instanceof CreatorTrackingVertex && ((CreatorTrackingVertex) node).getCreator() != null) { assertNotNull("Creator field was not set in the rest response.", model.getCreator()); CreatorTrackingVertex createdNode = (CreatorTrackingVertex) node; assertEquals(createdNode.getCreator().getFirstname(), model.getCreator().getFirstName()); assertEquals(createdNode.getCreator().getLastname(), model.getCreator().getLastName()); assertEquals(createdNode.getCreator().getUuid(), model.getCreator().getUuid()); } } }