[GitHub] nifi pull request #526: NIFI-1952 Create REST endpoints for user/group/polic...

2016-06-22 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/nifi/pull/526


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] nifi pull request #526: NIFI-1952 Create REST endpoints for user/group/polic...

2016-06-17 Thread mcgilman
Github user mcgilman commented on a diff in the pull request:

https://github.com/apache/nifi/pull/526#discussion_r67553151
  
--- Diff: nifi-api/src/main/java/org/apache/nifi/authorization/Group.java 
---
@@ -24,7 +24,7 @@
 /**
  * A group that users can belong to.
  */
-public class Group {
+public class Group { // TODO rename to UserGroup
--- End diff --

Sounds good.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] nifi pull request #526: NIFI-1952 Create REST endpoints for user/group/polic...

2016-06-14 Thread mcgilman
Github user mcgilman commented on a diff in the pull request:

https://github.com/apache/nifi/pull/526#discussion_r66968920
  
--- Diff: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/resources/nifi-web-api-context.xml
 ---
@@ -114,7 +123,23 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 
+
--- End diff --

I have no issue with using constructor arguments. However, why are we only 
using it on that one property?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] nifi pull request #526: NIFI-1952 Create REST endpoints for user/group/polic...

2016-06-14 Thread jtstorck
Github user jtstorck commented on a diff in the pull request:

https://github.com/apache/nifi/pull/526#discussion_r66968481
  
--- Diff: nifi-api/src/main/java/org/apache/nifi/authorization/Group.java 
---
@@ -24,7 +24,7 @@
 /**
  * A group that users can belong to.
  */
-public class Group {
+public class Group { // TODO rename to UserGroup
--- End diff --

I didn't want to cause too much of a ripple effect of changes outside the 
scope of the JIRA, but I can make those changes in this PR.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] nifi pull request #526: NIFI-1952 Create REST endpoints for user/group/polic...

2016-06-14 Thread jtstorck
Github user jtstorck commented on a diff in the pull request:

https://github.com/apache/nifi/pull/526#discussion_r66968299
  
--- Diff: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/resources/nifi-web-api-context.xml
 ---
@@ -114,7 +123,23 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 
+
--- End diff --

I prefer constructor injection over setter injection.  I think it's best 
that once an object is constructed, it should be usable, and that's not 
possible with setter injection.  With setters needing to be used to configure 
the object, there's no way to indicate required versus optional properties, 
outside of documentation.  By using constructors, you can programmatically 
declare the required properties.  This has an added benefit (in my opinion) of 
working towards making these types of objects (resources, services) immutable, 
and I think, generally speaking, immutability moves towards easier testing.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] nifi pull request #526: NIFI-1952 Create REST endpoints for user/group/polic...

2016-06-14 Thread jtstorck
Github user jtstorck commented on a diff in the pull request:

https://github.com/apache/nifi/pull/526#discussion_r66966699
  
--- Diff: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/UserGroupsResource.java
 ---
@@ -0,0 +1,373 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.web.api;
+
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+import com.wordnik.swagger.annotations.Authorization;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.authorization.Authorizer;
+import org.apache.nifi.authorization.RequestAction;
+import org.apache.nifi.authorization.resource.Authorizable;
+import org.apache.nifi.web.NiFiServiceFacade;
+import org.apache.nifi.web.Revision;
+import org.apache.nifi.web.UpdateResult;
+import org.apache.nifi.web.api.dto.UserGroupDTO;
+import org.apache.nifi.web.api.entity.UserGroupEntity;
+import org.apache.nifi.web.api.request.ClientIdParameter;
+import org.apache.nifi.web.api.request.LongParameter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.net.URI;
+
+@Path("/usergroups")
+@Api(
+value = "/usergroups",
+description = "Endpoint for managing user groups."
+)
+public class UserGroupsResource extends ApplicationResource {
+
+final private NiFiServiceFacade serviceFacade;
+final private Authorizer authorizer;
+
+public UserGroupsResource(NiFiServiceFacade serviceFacade, Authorizer 
authorizer) {
+this.serviceFacade = serviceFacade;
+this.authorizer = authorizer;
+}
+
+/**
+ * Populates the uri for the specified user group.
+ *
+ * @param userGroupEntity userGroupEntity
+ * @return userGroupEntity
+ */
+public UserGroupEntity 
populateRemainingUserGroupEntityContent(UserGroupEntity userGroupEntity) {
+if (userGroupEntity.getComponent() != null) {
+
populateRemainingUserGroupContent(userGroupEntity.getComponent());
+}
+return userGroupEntity;
+}
+
+/**
+ * Populates the uri for the specified userGroup.
+ */
+public UserGroupDTO populateRemainingUserGroupContent(UserGroupDTO 
userGroup) {
+// populate the user group href
+userGroup.setUri(generateResourceUri("usergroups", 
userGroup.getId()));
+return userGroup;
+}
+
+/**
+ * Creates a new user group.
+ *
+ * @param httpServletRequest request
+ * @param userGroupEntity An userGroupEntity.
+ * @return An userGroupEntity.
+ */
+@POST
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+// TODO - @PreAuthorize("hasRole('ROLE_DFM')")
+@ApiOperation(
+value = "Creates a user group",
+response = UserGroupEntity.class,
+authorizations = {
+@Authorization(value = "Data Flow Manager", type = 
"ROLE_DFM")
+}
+)
+@ApiResponses(
+value = {
+@ApiResponse(code = 400, message = "NiFi was unable to 
complete the request because it was invalid. The request should not be retri

[GitHub] nifi pull request #526: NIFI-1952 Create REST endpoints for user/group/polic...

2016-06-14 Thread jtstorck
Github user jtstorck commented on a diff in the pull request:

https://github.com/apache/nifi/pull/526#discussion_r66966751
  
--- Diff: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/UsersResource.java
 ---
@@ -0,0 +1,373 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.web.api;
+
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+import com.wordnik.swagger.annotations.Authorization;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.authorization.Authorizer;
+import org.apache.nifi.authorization.RequestAction;
+import org.apache.nifi.authorization.resource.Authorizable;
+import org.apache.nifi.web.NiFiServiceFacade;
+import org.apache.nifi.web.Revision;
+import org.apache.nifi.web.UpdateResult;
+import org.apache.nifi.web.api.dto.UserDTO;
+import org.apache.nifi.web.api.entity.UserEntity;
+import org.apache.nifi.web.api.request.ClientIdParameter;
+import org.apache.nifi.web.api.request.LongParameter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.net.URI;
+
+@Path("/users")
+@Api(
+value = "/users",
+description = "Endpoint for managing users."
+)
+public class UsersResource extends ApplicationResource {
+
+final private NiFiServiceFacade serviceFacade;
+final private Authorizer authorizer;
+
+public UsersResource(NiFiServiceFacade serviceFacade, Authorizer 
authorizer) {
+this.serviceFacade = serviceFacade;
+this.authorizer = authorizer;
+}
+
+/**
+ * Populates the uri for the specified user.
+ *
+ * @param userEntity userEntity
+ * @return userEntity
+ */
+public UserEntity populateRemainingUserEntityContent(UserEntity 
userEntity) {
+if (userEntity.getComponent() != null) {
+populateRemainingUserContent(userEntity.getComponent());
+}
+return userEntity;
+}
+
+/**
+ * Populates the uri for the specified user.
+ */
+public UserDTO populateRemainingUserContent(UserDTO user) {
+// populate the user href
+user.setUri(generateResourceUri("users", user.getId()));
+return user;
+}
+
+/**
+ * Creates a new user.
+ *
+ * @param httpServletRequest request
+ * @param userEntity An userEntity.
+ * @return An userEntity.
+ */
+@POST
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+// TODO - @PreAuthorize("hasRole('ROLE_DFM')")
+@ApiOperation(
+value = "Creates a user",
+response = UserEntity.class,
+authorizations = {
+@Authorization(value = "Data Flow Manager", type = 
"ROLE_DFM")
+}
+)
+@ApiResponses(
+value = {
+@ApiResponse(code = 400, message = "NiFi was unable to 
complete the request because it was invalid. The request should not be retried 
without modification."),
+@ApiResponse(code = 401, message = "Client could not 
be authenticated."),
+@ApiResponse(code = 403, message =

[GitHub] nifi pull request #526: NIFI-1952 Create REST endpoints for user/group/polic...

2016-06-14 Thread jtstorck
Github user jtstorck commented on a diff in the pull request:

https://github.com/apache/nifi/pull/526#discussion_r66966643
  
--- Diff: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/AccessPolicyResource.java
 ---
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.web.api;
+
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+import com.wordnik.swagger.annotations.Authorization;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.authorization.Authorizer;
+import org.apache.nifi.authorization.RequestAction;
+import org.apache.nifi.authorization.resource.Authorizable;
+import org.apache.nifi.web.NiFiServiceFacade;
+import org.apache.nifi.web.Revision;
+import org.apache.nifi.web.UpdateResult;
+import org.apache.nifi.web.api.dto.AccessPolicyDTO;
+import org.apache.nifi.web.api.entity.AccessPolicyEntity;
+import org.apache.nifi.web.api.request.ClientIdParameter;
+import org.apache.nifi.web.api.request.LongParameter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.net.URI;
+
+/**
+ * RESTful endpoint for managing access policies.
+ */
+@Path("/policies")
+@Api(
+value = "/policies",
+description = "Endpoint for managing access policies."
+)
+public class AccessPolicyResource extends ApplicationResource {
+
+final private NiFiServiceFacade serviceFacade;
+final private Authorizer authorizer;
+
+public AccessPolicyResource(NiFiServiceFacade serviceFacade, 
Authorizer authorizer) {
+this.serviceFacade = serviceFacade;
+this.authorizer = authorizer;
+}
+
+/**
+ * Populates the uri for the specified access policy.
+ *
+ * @param accessPolicyEntity accessPolicyEntity
+ * @return accessPolicyEntity
+ */
+public AccessPolicyEntity 
populateRemainingAccessPolicyEntityContent(AccessPolicyEntity 
accessPolicyEntity) {
+if (accessPolicyEntity.getComponent() != null) {
+
populateRemainingAccessPolicyContent(accessPolicyEntity.getComponent());
+}
+return accessPolicyEntity;
+}
+
+/**
+ * Populates the uri for the specified accessPolicy.
+ */
+public AccessPolicyDTO 
populateRemainingAccessPolicyContent(AccessPolicyDTO accessPolicy) {
+// populate the access policy href
+accessPolicy.setUri(generateResourceUri("policies", 
accessPolicy.getId()));
+return accessPolicy;
+}
+
+/**
+ * Creates a new access policy.
+ *
+ * @param httpServletRequest request
+ * @param accessPolicyEntity An accessPolicyEntity.
+ * @return An accessPolicyEntity.
+ */
+@POST
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+// TODO - @PreAuthorize("hasRole('ROLE_DFM')")
+@ApiOperation(
+value = "Creates an access policy",
+response = AccessPolicyEntity.class,
+authorizations = {
+@Authorization(value = "Data Flow Manager", type = 
"ROLE_DFM")
+}
+)
+@ApiResponses(
+v

[GitHub] nifi pull request #526: NIFI-1952 Create REST endpoints for user/group/polic...

2016-06-14 Thread mcgilman
Github user mcgilman commented on a diff in the pull request:

https://github.com/apache/nifi/pull/526#discussion_r66962729
  
--- Diff: nifi-api/src/main/java/org/apache/nifi/authorization/Group.java 
---
@@ -24,7 +24,7 @@
 /**
  * A group that users can belong to.
  */
-public class Group {
+public class Group { // TODO rename to UserGroup
--- End diff --

Let's proceed with renaming prior to merging.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] nifi pull request #526: NIFI-1952 Create REST endpoints for user/group/polic...

2016-06-14 Thread mcgilman
Github user mcgilman commented on a diff in the pull request:

https://github.com/apache/nifi/pull/526#discussion_r66960292
  
--- Diff: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/resources/nifi-web-api-context.xml
 ---
@@ -114,7 +123,23 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 
+
--- End diff --

Is there a reason the authorizable lookup is a constructor arg instead of a 
settable property?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] nifi pull request #526: NIFI-1952 Create REST endpoints for user/group/polic...

2016-06-14 Thread mcgilman
Github user mcgilman commented on a diff in the pull request:

https://github.com/apache/nifi/pull/526#discussion_r66959842
  
--- Diff: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/UsersResource.java
 ---
@@ -0,0 +1,373 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.web.api;
+
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+import com.wordnik.swagger.annotations.Authorization;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.authorization.Authorizer;
+import org.apache.nifi.authorization.RequestAction;
+import org.apache.nifi.authorization.resource.Authorizable;
+import org.apache.nifi.web.NiFiServiceFacade;
+import org.apache.nifi.web.Revision;
+import org.apache.nifi.web.UpdateResult;
+import org.apache.nifi.web.api.dto.UserDTO;
+import org.apache.nifi.web.api.entity.UserEntity;
+import org.apache.nifi.web.api.request.ClientIdParameter;
+import org.apache.nifi.web.api.request.LongParameter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.net.URI;
+
+@Path("/users")
+@Api(
+value = "/users",
+description = "Endpoint for managing users."
+)
+public class UsersResource extends ApplicationResource {
+
+final private NiFiServiceFacade serviceFacade;
+final private Authorizer authorizer;
+
+public UsersResource(NiFiServiceFacade serviceFacade, Authorizer 
authorizer) {
+this.serviceFacade = serviceFacade;
+this.authorizer = authorizer;
+}
+
+/**
+ * Populates the uri for the specified user.
+ *
+ * @param userEntity userEntity
+ * @return userEntity
+ */
+public UserEntity populateRemainingUserEntityContent(UserEntity 
userEntity) {
+if (userEntity.getComponent() != null) {
+populateRemainingUserContent(userEntity.getComponent());
+}
+return userEntity;
+}
+
+/**
+ * Populates the uri for the specified user.
+ */
+public UserDTO populateRemainingUserContent(UserDTO user) {
+// populate the user href
+user.setUri(generateResourceUri("users", user.getId()));
+return user;
+}
+
+/**
+ * Creates a new user.
+ *
+ * @param httpServletRequest request
+ * @param userEntity An userEntity.
+ * @return An userEntity.
+ */
+@POST
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+// TODO - @PreAuthorize("hasRole('ROLE_DFM')")
+@ApiOperation(
+value = "Creates a user",
+response = UserEntity.class,
+authorizations = {
+@Authorization(value = "Data Flow Manager", type = 
"ROLE_DFM")
+}
+)
+@ApiResponses(
+value = {
+@ApiResponse(code = 400, message = "NiFi was unable to 
complete the request because it was invalid. The request should not be retried 
without modification."),
+@ApiResponse(code = 401, message = "Client could not 
be authenticated."),
+@ApiResponse(code = 403, message =

[GitHub] nifi pull request #526: NIFI-1952 Create REST endpoints for user/group/polic...

2016-06-14 Thread mcgilman
Github user mcgilman commented on a diff in the pull request:

https://github.com/apache/nifi/pull/526#discussion_r66959717
  
--- Diff: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/UserGroupsResource.java
 ---
@@ -0,0 +1,373 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.web.api;
+
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+import com.wordnik.swagger.annotations.Authorization;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.authorization.Authorizer;
+import org.apache.nifi.authorization.RequestAction;
+import org.apache.nifi.authorization.resource.Authorizable;
+import org.apache.nifi.web.NiFiServiceFacade;
+import org.apache.nifi.web.Revision;
+import org.apache.nifi.web.UpdateResult;
+import org.apache.nifi.web.api.dto.UserGroupDTO;
+import org.apache.nifi.web.api.entity.UserGroupEntity;
+import org.apache.nifi.web.api.request.ClientIdParameter;
+import org.apache.nifi.web.api.request.LongParameter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.net.URI;
+
+@Path("/usergroups")
+@Api(
+value = "/usergroups",
+description = "Endpoint for managing user groups."
+)
+public class UserGroupsResource extends ApplicationResource {
+
+final private NiFiServiceFacade serviceFacade;
+final private Authorizer authorizer;
+
+public UserGroupsResource(NiFiServiceFacade serviceFacade, Authorizer 
authorizer) {
+this.serviceFacade = serviceFacade;
+this.authorizer = authorizer;
+}
+
+/**
+ * Populates the uri for the specified user group.
+ *
+ * @param userGroupEntity userGroupEntity
+ * @return userGroupEntity
+ */
+public UserGroupEntity 
populateRemainingUserGroupEntityContent(UserGroupEntity userGroupEntity) {
+if (userGroupEntity.getComponent() != null) {
+
populateRemainingUserGroupContent(userGroupEntity.getComponent());
+}
+return userGroupEntity;
+}
+
+/**
+ * Populates the uri for the specified userGroup.
+ */
+public UserGroupDTO populateRemainingUserGroupContent(UserGroupDTO 
userGroup) {
+// populate the user group href
+userGroup.setUri(generateResourceUri("usergroups", 
userGroup.getId()));
+return userGroup;
+}
+
+/**
+ * Creates a new user group.
+ *
+ * @param httpServletRequest request
+ * @param userGroupEntity An userGroupEntity.
+ * @return An userGroupEntity.
+ */
+@POST
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+// TODO - @PreAuthorize("hasRole('ROLE_DFM')")
+@ApiOperation(
+value = "Creates a user group",
+response = UserGroupEntity.class,
+authorizations = {
+@Authorization(value = "Data Flow Manager", type = 
"ROLE_DFM")
+}
+)
+@ApiResponses(
+value = {
+@ApiResponse(code = 400, message = "NiFi was unable to 
complete the request because it was invalid. The request should not be retri

[GitHub] nifi pull request #526: NIFI-1952 Create REST endpoints for user/group/polic...

2016-06-14 Thread mcgilman
Github user mcgilman commented on a diff in the pull request:

https://github.com/apache/nifi/pull/526#discussion_r66959598
  
--- Diff: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/AccessPolicyResource.java
 ---
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.web.api;
+
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+import com.wordnik.swagger.annotations.Authorization;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.authorization.Authorizer;
+import org.apache.nifi.authorization.RequestAction;
+import org.apache.nifi.authorization.resource.Authorizable;
+import org.apache.nifi.web.NiFiServiceFacade;
+import org.apache.nifi.web.Revision;
+import org.apache.nifi.web.UpdateResult;
+import org.apache.nifi.web.api.dto.AccessPolicyDTO;
+import org.apache.nifi.web.api.entity.AccessPolicyEntity;
+import org.apache.nifi.web.api.request.ClientIdParameter;
+import org.apache.nifi.web.api.request.LongParameter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.net.URI;
+
+/**
+ * RESTful endpoint for managing access policies.
+ */
+@Path("/policies")
+@Api(
+value = "/policies",
+description = "Endpoint for managing access policies."
+)
+public class AccessPolicyResource extends ApplicationResource {
+
+final private NiFiServiceFacade serviceFacade;
+final private Authorizer authorizer;
+
+public AccessPolicyResource(NiFiServiceFacade serviceFacade, 
Authorizer authorizer) {
+this.serviceFacade = serviceFacade;
+this.authorizer = authorizer;
+}
+
+/**
+ * Populates the uri for the specified access policy.
+ *
+ * @param accessPolicyEntity accessPolicyEntity
+ * @return accessPolicyEntity
+ */
+public AccessPolicyEntity 
populateRemainingAccessPolicyEntityContent(AccessPolicyEntity 
accessPolicyEntity) {
+if (accessPolicyEntity.getComponent() != null) {
+
populateRemainingAccessPolicyContent(accessPolicyEntity.getComponent());
+}
+return accessPolicyEntity;
+}
+
+/**
+ * Populates the uri for the specified accessPolicy.
+ */
+public AccessPolicyDTO 
populateRemainingAccessPolicyContent(AccessPolicyDTO accessPolicy) {
+// populate the access policy href
+accessPolicy.setUri(generateResourceUri("policies", 
accessPolicy.getId()));
+return accessPolicy;
+}
+
+/**
+ * Creates a new access policy.
+ *
+ * @param httpServletRequest request
+ * @param accessPolicyEntity An accessPolicyEntity.
+ * @return An accessPolicyEntity.
+ */
+@POST
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+// TODO - @PreAuthorize("hasRole('ROLE_DFM')")
+@ApiOperation(
+value = "Creates an access policy",
+response = AccessPolicyEntity.class,
+authorizations = {
+@Authorization(value = "Data Flow Manager", type = 
"ROLE_DFM")
+}
+)
+@ApiResponses(
+v

[GitHub] nifi pull request #526: NIFI-1952 Create REST endpoints for user/group/polic...

2016-06-13 Thread jtstorck
GitHub user jtstorck opened a pull request:

https://github.com/apache/nifi/pull/526

NIFI-1952 Create REST endpoints for user/group/policy management

created REST Resources for users, groups, and access policies
added Authorizables for users, groups, and access policies
added methods to DtoFactory and EntityFactory to create objects for users, 
groups, and access policies
extracted anonymous AuthorizableLookup impl in 
StandardNiFiServiceFacade.java to a protected class to make the lookup call 
mockable in tests
added methods to manage users/groups/access policies to 
StandardNiFiServiceFacade
added StandardNiFiServiceFacadeSpec to unit-test management of 
users/groups/access policies
added implementations for UserDAO, GroupDAO, AccessPolicyDAO.
added spring config for user/group/policy resources and daos

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/jtstorck/nifi NIFI-1952

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/nifi/pull/526.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #526


commit 81971e80bae4b7b4a5084984090b52489c4451b7
Author: Jeff Storck 
Date:   2016-06-02T20:33:05Z

NIFI-1952 Create REST endpoints for user/group/policy management
created REST Resources for users, groups, and access policies
added Authorizables for users, groups, and access policies
added methods to DtoFactory and EntityFactory to create objects for users, 
groups, and access policies
extracted anonymous AuthorizableLookup impl in 
StandardNiFiServiceFacade.java to a protected class to make the lookup call 
mockable in tests
added methods to manage users/groups/access policies to 
StandardNiFiServiceFacade
added StandardNiFiServiceFacadeSpec to unit-test management of 
users/groups/access policies
added implementations for UserDAO, GroupDAO, AccessPolicyDAO.
added spring config for user/group/policy resources and daos




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---