You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@syncope.apache.org by GitBox <gi...@apache.org> on 2020/05/18 12:58:48 UTC

[GitHub] [syncope] mmoayyed opened a new pull request #189: SYNCOPE-1562: Manage tokens for WA GoogleAuth MFA

mmoayyed opened a new pull request #189:
URL: https://github.com/apache/syncope/pull/189


   - Presents APIs and components to manage tokens for Google Authenticator MFA.
   - Managing user registered devices will be done in a separate pull request to minimize changes.
   - TODO: Integrate and register components with WA; smoke tests. 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [syncope] mmoayyed commented on a change in pull request #189: SYNCOPE-1562: Manage tokens for WA GoogleAuth MFA

Posted by GitBox <gi...@apache.org>.
mmoayyed commented on a change in pull request #189:
URL: https://github.com/apache/syncope/pull/189#discussion_r430200152



##########
File path: core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/auth/AuthProfileDAO.java
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.syncope.core.persistence.api.dao.auth;
+
+import org.apache.syncope.core.persistence.api.dao.DAO;
+import org.apache.syncope.core.persistence.api.entity.auth.AuthProfile;
+
+import java.util.List;
+import java.util.Optional;
+
+public interface AuthProfileDAO extends DAO<AuthProfile> {
+
+    List<AuthProfile> findAll();

Review comment:
       Why would you delete an auth-profile? 

##########
File path: core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/auth/AuthProfile.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.syncope.core.persistence.api.entity.auth;
+
+import org.apache.syncope.common.lib.types.GoogleMfaAuthToken;
+import org.apache.syncope.core.persistence.api.entity.Entity;
+
+import java.util.List;
+
+public interface AuthProfile extends Entity {
+
+    String getOwner();
+
+    void setOwner(String owner);
+    
+    List<GoogleMfaAuthToken> getGoogleMfaAuthTokens();
+
+    void setGoogleMfaAuthTokens(List<GoogleMfaAuthToken> tokens);

Review comment:
       Sorry I dont follow. Do you mean this should be removed?

##########
File path: core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/auth/AuthProfileDAO.java
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.syncope.core.persistence.api.dao.auth;
+
+import org.apache.syncope.core.persistence.api.dao.DAO;
+import org.apache.syncope.core.persistence.api.entity.auth.AuthProfile;
+
+import java.util.List;
+import java.util.Optional;
+
+public interface AuthProfileDAO extends DAO<AuthProfile> {
+
+    List<AuthProfile> findAll();

Review comment:
       Gotcha, sure. I'll make it happen.

##########
File path: core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/auth/AuthProfile.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.syncope.core.persistence.api.entity.auth;
+
+import org.apache.syncope.common.lib.types.GoogleMfaAuthToken;
+import org.apache.syncope.core.persistence.api.entity.Entity;
+
+import java.util.List;
+
+public interface AuthProfile extends Entity {
+
+    String getOwner();
+
+    void setOwner(String owner);
+    
+    List<GoogleMfaAuthToken> getGoogleMfaAuthTokens();
+
+    void setGoogleMfaAuthTokens(List<GoogleMfaAuthToken> tokens);

Review comment:
       I have looked at a number of other entities that follow a similar approach: `JPABatch`, `JPAJSONGroup`, `JPAAnyAbout`, etc. All have a setter. How else would one assign tokens if there is no setter? Specially since the getter is always deserializing the JSON field and returning a new list? 

##########
File path: core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/auth/AuthProfileDAO.java
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.syncope.core.persistence.api.dao.auth;
+
+import org.apache.syncope.core.persistence.api.dao.DAO;
+import org.apache.syncope.core.persistence.api.entity.auth.AuthProfile;
+
+import java.util.List;
+import java.util.Optional;
+
+public interface AuthProfileDAO extends DAO<AuthProfile> {
+
+    List<AuthProfile> findAll();

Review comment:
       Quick question: this means that I do need to create an `AuthProfileTO` component, right? 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [syncope] ilgrosso commented on a change in pull request #189: SYNCOPE-1562: Manage tokens for WA GoogleAuth MFA

Posted by GitBox <gi...@apache.org>.
ilgrosso commented on a change in pull request #189:
URL: https://github.com/apache/syncope/pull/189#discussion_r431032109



##########
File path: common/am/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/AuthProfileService.java
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.syncope.common.rest.api.service;
+
+import io.swagger.v3.oas.annotations.headers.Header;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import io.swagger.v3.oas.annotations.security.SecurityRequirement;
+import io.swagger.v3.oas.annotations.security.SecurityRequirements;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.apache.syncope.common.lib.to.AuthProfileTO;
+import org.apache.syncope.common.rest.api.RESTHeaders;
+
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import java.util.List;
+
+/**
+ * REST operations for SAML 2.0 SP metadata.
+ */
+@Tag(name = "Auth Profiles")
+@SecurityRequirements({
+    @SecurityRequirement(name = "BasicAuthentication"),
+    @SecurityRequirement(name = "Bearer")})
+@Path("authProfiles")
+public interface AuthProfileService extends JAXRSService {
+
+    @GET
+    @Produces({MediaType.APPLICATION_JSON})
+    List<AuthProfileTO> list();
+
+    @GET
+    @Path("owners/{owner}")
+    @Consumes({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Produces({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    AuthProfileTO findByOwner(@NotNull @PathParam("owner") String owner);

Review comment:
       I agree, but if so then you should add the related unique constraint in the JPA entity, no?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [syncope] ilgrosso commented on a change in pull request #189: SYNCOPE-1562: Manage tokens for WA GoogleAuth MFA

Posted by GitBox <gi...@apache.org>.
ilgrosso commented on a change in pull request #189:
URL: https://github.com/apache/syncope/pull/189#discussion_r430993966



##########
File path: common/am/lib/src/main/java/org/apache/syncope/common/lib/to/AuthProfileTO.java
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.syncope.common.lib.to;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.syncope.common.lib.BaseBean;
+import org.apache.syncope.common.lib.types.GoogleMfaAuthToken;
+
+import javax.ws.rs.PathParam;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+@XmlRootElement(name = "authProfile")
+@XmlType
+public class AuthProfileTO extends BaseBean implements EntityTO {
+
+    private static final long serialVersionUID = -6543425997956703057L;
+
+    private final List<GoogleMfaAuthToken> googleMfaAuthTokens = new ArrayList<>();
+
+    private String key;
+
+    private String owner;
+
+    @Override
+    public String getKey() {
+        return key;
+    }
+
+    @PathParam("key")
+    @Override
+    public void setKey(final String key) {
+        this.key = key;
+    }
+
+    public String getOwner() {
+        return owner;
+    }
+
+    public void setOwner(final String owner) {
+        this.owner = owner;
+    }
+
+    @XmlElementWrapper(name = "googleMfaAuthTokens")
+    @XmlElement(name = "googleMfaAuthTokens")
+    @JsonProperty("googleMfaAuthTokens")
+    public List<GoogleMfaAuthToken> getGoogleMfaAuthTokens() {
+        return googleMfaAuthTokens;
+    }
+
+    public boolean add(final GoogleMfaAuthToken item) {

Review comment:
       This method is not needed, please remove.

##########
File path: common/am/lib/src/main/java/org/apache/syncope/common/lib/to/AuthProfileTO.java
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.syncope.common.lib.to;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.syncope.common.lib.BaseBean;
+import org.apache.syncope.common.lib.types.GoogleMfaAuthToken;
+
+import javax.ws.rs.PathParam;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+@XmlRootElement(name = "authProfile")
+@XmlType
+public class AuthProfileTO extends BaseBean implements EntityTO {
+
+    private static final long serialVersionUID = -6543425997956703057L;
+
+    private final List<GoogleMfaAuthToken> googleMfaAuthTokens = new ArrayList<>();
+
+    private String key;
+
+    private String owner;
+
+    @Override
+    public String getKey() {
+        return key;
+    }
+
+    @PathParam("key")
+    @Override
+    public void setKey(final String key) {
+        this.key = key;
+    }
+
+    public String getOwner() {
+        return owner;
+    }
+
+    public void setOwner(final String owner) {
+        this.owner = owner;
+    }
+
+    @XmlElementWrapper(name = "googleMfaAuthTokens")
+    @XmlElement(name = "googleMfaAuthTokens")
+    @JsonProperty("googleMfaAuthTokens")
+    public List<GoogleMfaAuthToken> getGoogleMfaAuthTokens() {
+        return googleMfaAuthTokens;
+    }
+
+    public boolean add(final GoogleMfaAuthToken item) {
+        return Optional.ofNullable(item).
+            filter(itemTO -> googleMfaAuthTokens.contains(itemTO) || googleMfaAuthTokens.add(itemTO)).
+            isPresent();
+    }
+
+    public boolean remove(final GoogleMfaAuthToken item) {

Review comment:
       This method is not needed, please remove.

##########
File path: common/am/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/AuthProfileService.java
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.syncope.common.rest.api.service;
+
+import io.swagger.v3.oas.annotations.headers.Header;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import io.swagger.v3.oas.annotations.security.SecurityRequirement;
+import io.swagger.v3.oas.annotations.security.SecurityRequirements;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.apache.syncope.common.lib.to.AuthProfileTO;
+import org.apache.syncope.common.rest.api.RESTHeaders;
+
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import java.util.List;
+
+/**
+ * REST operations for SAML 2.0 SP metadata.
+ */
+@Tag(name = "Auth Profiles")
+@SecurityRequirements({
+    @SecurityRequirement(name = "BasicAuthentication"),
+    @SecurityRequirement(name = "Bearer")})
+@Path("authProfiles")
+public interface AuthProfileService extends JAXRSService {
+
+    @GET
+    @Produces({MediaType.APPLICATION_JSON})
+    List<AuthProfileTO> list();
+
+    @GET
+    @Path("owners/{owner}")
+    @Consumes({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Produces({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    AuthProfileTO findByOwner(@NotNull @PathParam("owner") String owner);

Review comment:
       As far as I can see from `JPAAuthProfile` there could be different profiles for a given `owner`: so, this method should return `List<AuthProfileTO>`

##########
File path: core/am/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/wa/GoogleMfaAuthTokenServiceImpl.java
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.syncope.core.rest.cxf.service.wa;
+
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.types.ClientExceptionType;
+import org.apache.syncope.common.lib.types.GoogleMfaAuthToken;
+import org.apache.syncope.common.rest.api.RESTHeaders;
+import org.apache.syncope.common.rest.api.service.wa.GoogleMfaAuthTokenService;
+import org.apache.syncope.core.logic.GoogleMfaAuthTokenLogic;
+import org.apache.syncope.core.persistence.api.dao.NotFoundException;
+import org.apache.syncope.core.rest.cxf.service.AbstractServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.ws.rs.core.Response;
+
+import java.net.URI;
+import java.util.Date;
+import java.util.List;
+
+@Service
+public class GoogleMfaAuthTokenServiceImpl extends AbstractServiceImpl implements GoogleMfaAuthTokenService {
+    @Autowired
+    private GoogleMfaAuthTokenLogic logic;
+
+    @Override
+    public Response deleteTokensByDate(final Date expirationDate) {
+        logic.delete(expirationDate);
+        return Response.noContent().build();
+    }
+
+    @Override
+    public Response deleteToken(final String owner, final Integer otp) {
+        logic.delete(owner, otp);
+        return Response.noContent().build();
+    }
+
+    @Override
+    public Response deleteTokensFor(final String owner) {
+        logic.delete(owner);
+        return Response.noContent().build();
+    }
+
+    @Override
+    public Response deleteToken(final Integer otp) {
+        logic.delete(otp);
+        return Response.noContent().build();
+    }
+
+    @Override
+    public Response deleteTokens() {
+        logic.deleteAll();
+        return Response.noContent().build();
+    }
+
+    @Override
+    public Response save(final GoogleMfaAuthToken tokenTO) {
+        final GoogleMfaAuthToken token = logic.save(tokenTO);
+        URI location = uriInfo.getAbsolutePathBuilder().path(token.getKey()).build();
+        return Response.created(location).
+            header(RESTHeaders.RESOURCE_KEY, token.getKey()).
+            build();
+    }
+
+    @Override
+    public GoogleMfaAuthToken findTokenFor(final String owner, final Integer otp) {
+        try {
+            return logic.read(owner, otp);

Review comment:
       Normally, `NotFoundException` is managed at logic level - see many examples including https://github.com/apache/syncope/blob/master/core/idm/logic/src/main/java/org/apache/syncope/core/logic/ResourceLogic.java#L148-L150

##########
File path: common/am/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/AuthProfileService.java
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.syncope.common.rest.api.service;
+
+import io.swagger.v3.oas.annotations.headers.Header;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import io.swagger.v3.oas.annotations.security.SecurityRequirement;
+import io.swagger.v3.oas.annotations.security.SecurityRequirements;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.apache.syncope.common.lib.to.AuthProfileTO;
+import org.apache.syncope.common.rest.api.RESTHeaders;
+
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import java.util.List;
+
+/**
+ * REST operations for SAML 2.0 SP metadata.
+ */
+@Tag(name = "Auth Profiles")
+@SecurityRequirements({
+    @SecurityRequirement(name = "BasicAuthentication"),
+    @SecurityRequirement(name = "Bearer")})
+@Path("authProfiles")
+public interface AuthProfileService extends JAXRSService {
+
+    @GET
+    @Produces({MediaType.APPLICATION_JSON})
+    List<AuthProfileTO> list();
+
+    @GET
+    @Path("owners/{owner}")
+    @Consumes({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Produces({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    AuthProfileTO findByOwner(@NotNull @PathParam("owner") String owner);
+
+    @GET
+    @Path("{key}")
+    @Consumes({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Produces({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    AuthProfileTO findByKey(@NotNull @PathParam("key") String key);
+
+    @DELETE
+    @Path("{key}")
+    @Consumes({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Produces({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    Response deleteByKey(@NotNull @PathParam("key") String key);
+
+    @DELETE
+    @Path("owners/{owner}")
+    @Consumes({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Produces({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    Response deleteByOwner(@NotNull @PathParam("owner") String owner);
+
+    @ApiResponses({
+        @ApiResponse(responseCode = "201",
+            description = "AuthProfile successfully created", headers = {
+            @Header(name = RESTHeaders.RESOURCE_KEY, schema =
+            @Schema(type = "string"),
+                description = "UUID generated for the entity created"),
+            @Header(name = HttpHeaders.LOCATION, schema =
+            @Schema(type = "string"),
+                description = "URL of the entity created") }),
+        @ApiResponse(responseCode = "409",
+            description = "AuthProfile already existing") })
+    @POST
+    @Consumes({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML })
+    @Produces({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML })
+    Response create(@NotNull AuthProfileTO authProfileTO);

Review comment:
       I don't think we should expose a mean to administratively create an `AuthProfile`; this method should be removed, then.

##########
File path: core/am/logic/src/main/java/org/apache/syncope/core/logic/AuthProfileLogic.java
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.syncope.core.logic;
+
+import org.apache.syncope.common.lib.to.AuthProfileTO;
+import org.apache.syncope.common.lib.types.AMEntitlement;
+import org.apache.syncope.core.persistence.api.dao.NotFoundException;
+import org.apache.syncope.core.persistence.api.dao.auth.AuthProfileDAO;
+import org.apache.syncope.core.persistence.api.entity.auth.AuthProfile;
+import org.apache.syncope.core.provisioning.api.data.AuthProfileDataBinder;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Component
+@Transactional(rollbackFor = {Throwable.class})
+public class AuthProfileLogic {

Review comment:
       Please have this class extend `AbstractTransactionalLogic<AuthProfileTO>` and remove `@Transactional` annotation.

##########
File path: core/am/logic/src/main/java/org/apache/syncope/core/logic/GoogleMfaAuthTokenLogic.java
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.syncope.core.logic;
+
+import org.apache.syncope.common.lib.types.AMEntitlement;
+import org.apache.syncope.common.lib.types.GoogleMfaAuthToken;
+import org.apache.syncope.common.lib.types.IdRepoEntitlement;
+import org.apache.syncope.core.persistence.api.dao.auth.AuthProfileDAO;
+import org.apache.syncope.core.persistence.api.entity.EntityFactory;
+import org.apache.syncope.core.persistence.api.entity.auth.AuthProfile;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Predicate;
+
+@Component
+@Transactional(rollbackFor = { Throwable.class })
+public class GoogleMfaAuthTokenLogic {

Review comment:
       Please have this class extend `AbstractTransactionalLogic<AuthProfileTO>` and remove `@Transactional` annotation.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [syncope] ilgrosso commented on a change in pull request #189: SYNCOPE-1562: Manage tokens for WA GoogleAuth MFA

Posted by GitBox <gi...@apache.org>.
ilgrosso commented on a change in pull request #189:
URL: https://github.com/apache/syncope/pull/189#discussion_r427355325



##########
File path: core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/auth/GoogleMfaAuthTokenDAO.java
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.syncope.core.persistence.api.dao.auth;
+
+import org.apache.syncope.core.persistence.api.dao.DAO;
+import org.apache.syncope.core.persistence.api.entity.auth.GoogleMfaAuthToken;
+
+import java.util.Date;
+import java.util.List;
+
+public interface GoogleMfaAuthTokenDAO extends DAO<GoogleMfaAuthToken> {
+    GoogleMfaAuthToken find(String user, Integer otp);
+
+    GoogleMfaAuthToken find(String key);
+
+    GoogleMfaAuthToken save(GoogleMfaAuthToken token);
+
+    long count(String user);
+
+    long count();
+
+    void deleteAll();
+
+    boolean delete(Integer otp);
+
+    boolean delete(String user);
+
+    boolean delete(String user, Integer otp);
+
+    boolean delete(Date expirationDate);
+
+    List<GoogleMfaAuthToken> findTokensForUser(String user);

Review comment:
       I think this should be renamed as `findForOwner()`

##########
File path: wa/starter/src/test/java/org/apache/syncope/wa/starter/gauth/token/SyncopeWAGoogleMfaAuthTokenRepositoryTest.java
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.syncope.wa.starter.gauth.token;
+
+import org.apereo.cas.gauth.token.GoogleAuthenticatorToken;
+import org.apereo.cas.otp.repository.token.OneTimeTokenRepository;
+
+import org.apache.syncope.wa.starter.AbstractTest;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class SyncopeWAGoogleMfaAuthTokenRepositoryTest extends AbstractTest {
+    @Autowired
+    private OneTimeTokenRepository tokenRepository;
+
+    @Test
+    public void verifyOps() {
+        tokenRepository.removeAll();
+        GoogleAuthenticatorToken token = new GoogleAuthenticatorToken(123456, "SyncopeWA");
+        tokenRepository.store(token);
+        assertEquals(1, tokenRepository.count(token.getUserId()));
+        assertEquals(1, tokenRepository.count());
+    }
+

Review comment:
       I know I am picky but... any reason for these two blank lines? :-)

##########
File path: core/am/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/wa/GoogleMfaAuthTokenServiceImpl.java
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.syncope.core.rest.cxf.service.wa;
+
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.to.GoogleMfaAuthTokenTO;
+import org.apache.syncope.common.lib.types.ClientExceptionType;
+import org.apache.syncope.common.rest.api.RESTHeaders;
+import org.apache.syncope.common.rest.api.service.wa.GoogleMfaAuthTokenService;
+import org.apache.syncope.core.logic.GoogleMfaAuthTokenLogic;
+import org.apache.syncope.core.persistence.api.dao.NotFoundException;
+import org.apache.syncope.core.rest.cxf.service.AbstractServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.ws.rs.core.Response;
+
+import java.net.URI;
+import java.util.Date;
+import java.util.List;
+
+@Service
+public class GoogleMfaAuthTokenServiceImpl extends AbstractServiceImpl implements GoogleMfaAuthTokenService {
+    @Autowired
+    private GoogleMfaAuthTokenLogic logic;
+
+    @Override
+    public Response deleteTokensByDate(final Date expirationDate) {
+        boolean result = logic.delete(expirationDate);

Review comment:
       Normally, `delete()` methods should be returning `void` - see https://github.com/apache/syncope/blob/master/common/idm/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/ResourceService.java#L216 for example.

##########
File path: common/am/lib/src/main/java/org/apache/syncope/common/lib/to/GoogleMfaAuthTokenTO.java
##########
@@ -0,0 +1,142 @@
+/*
+ * 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.syncope.common.lib.to;
+
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.syncope.common.lib.BaseBean;
+
+import javax.ws.rs.PathParam;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import java.util.Date;
+
+@XmlRootElement(name = "gauthToken")
+@XmlType
+public class GoogleMfaAuthTokenTO extends BaseBean implements EntityTO {
+
+    private static final long serialVersionUID = 1285073386484048953L;
+
+    private String key;
+
+    private Integer token;
+
+    private String user;
+
+    private Date issuedDate;
+
+    @Override
+    public String getKey() {
+        return key;
+    }
+
+    @PathParam("key")
+    @Override
+    public void setKey(final String key) {
+        this.key = key;
+    }
+
+    public Integer getToken() {
+        return token;
+    }
+
+    public void setToken(final Integer token) {
+        this.token = token;
+    }
+
+    public String getUser() {
+        return user;
+    }
+
+    public void setUser(final String user) {
+        this.user = user;
+    }
+
+    public Date getIssuedDate() {
+        return issuedDate;

Review comment:
       We normally use defensive copy for `Date` values - see https://github.com/apache/syncope/blob/master/common/idrepo/lib/src/main/java/org/apache/syncope/common/lib/to/AbstractStartEndBean.java#L49-L56

##########
File path: common/am/lib/src/main/java/org/apache/syncope/common/lib/to/GoogleMfaAuthTokenTO.java
##########
@@ -0,0 +1,142 @@
+/*
+ * 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.syncope.common.lib.to;
+
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.syncope.common.lib.BaseBean;
+
+import javax.ws.rs.PathParam;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import java.util.Date;
+
+@XmlRootElement(name = "gauthToken")
+@XmlType
+public class GoogleMfaAuthTokenTO extends BaseBean implements EntityTO {
+
+    private static final long serialVersionUID = 1285073386484048953L;
+
+    private String key;
+
+    private Integer token;
+
+    private String user;

Review comment:
       Would it be possible to rename this field (and all related, including JPA) as `owner` instead? The wording `user` might sound like a Syncope user, which is not.

##########
File path: core/am/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/wa/GoogleMfaAuthTokenServiceImpl.java
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.syncope.core.rest.cxf.service.wa;
+
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.to.GoogleMfaAuthTokenTO;
+import org.apache.syncope.common.lib.types.ClientExceptionType;
+import org.apache.syncope.common.rest.api.RESTHeaders;
+import org.apache.syncope.common.rest.api.service.wa.GoogleMfaAuthTokenService;
+import org.apache.syncope.core.logic.GoogleMfaAuthTokenLogic;
+import org.apache.syncope.core.persistence.api.dao.NotFoundException;
+import org.apache.syncope.core.rest.cxf.service.AbstractServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.ws.rs.core.Response;
+
+import java.net.URI;
+import java.util.Date;
+import java.util.List;
+
+@Service
+public class GoogleMfaAuthTokenServiceImpl extends AbstractServiceImpl implements GoogleMfaAuthTokenService {
+    @Autowired
+    private GoogleMfaAuthTokenLogic logic;
+
+    @Override
+    public Response deleteTokensByDate(final Date expirationDate) {
+        boolean result = logic.delete(expirationDate);
+        return result ? Response.ok().build() : Response.status(Response.Status.BAD_REQUEST).build();
+    }
+
+    @Override
+    public Response deleteToken(final String user, final Integer otp) {
+        boolean result = logic.delete(user, otp);
+        return result ? Response.ok().build() : Response.status(Response.Status.BAD_REQUEST).build();
+    }
+
+    @Override
+    public Response deleteTokensFor(final String user) {
+        boolean result = logic.delete(user);
+        return result ? Response.ok().build() : Response.status(Response.Status.BAD_REQUEST).build();
+    }
+
+    @Override
+    public Response deleteToken(final Integer otp) {
+        boolean result = logic.delete(otp);
+        return result ? Response.ok().build() : Response.status(Response.Status.BAD_REQUEST).build();
+    }
+
+    @Override
+    public Response deleteTokens() {
+        logic.deleteAll();
+        return Response.ok().build();

Review comment:
       this should be
   ```java
   return Response.noContent().build();
   ```
   
   no?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [syncope] mmoayyed commented on pull request #189: SYNCOPE-1562: Manage tokens for WA GoogleAuth MFA

Posted by GitBox <gi...@apache.org>.
mmoayyed commented on pull request #189:
URL: https://github.com/apache/syncope/pull/189#issuecomment-635168690


   Applied changes after review.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [syncope] ilgrosso commented on a change in pull request #189: SYNCOPE-1562: Manage tokens for WA GoogleAuth MFA

Posted by GitBox <gi...@apache.org>.
ilgrosso commented on a change in pull request #189:
URL: https://github.com/apache/syncope/pull/189#discussion_r430993373



##########
File path: core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/data/AuthProfileDataBinder.java
##########
@@ -0,0 +1,27 @@
+/*

Review comment:
       @mmoayyed what about this?

##########
File path: core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AuthProfileDataBinderImpl.java
##########
@@ -0,0 +1,39 @@
+/*

Review comment:
       @mmoayyed what about this?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [syncope] mmoayyed commented on pull request #189: SYNCOPE-1562: Manage tokens for WA GoogleAuth MFA

Posted by GitBox <gi...@apache.org>.
mmoayyed commented on pull request #189:
URL: https://github.com/apache/syncope/pull/189#issuecomment-634550779


   This should be ready for another review. Test failures seem random.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [syncope] ilgrosso commented on a change in pull request #189: SYNCOPE-1562: Manage tokens for WA GoogleAuth MFA

Posted by GitBox <gi...@apache.org>.
ilgrosso commented on a change in pull request #189:
URL: https://github.com/apache/syncope/pull/189#discussion_r430993076



##########
File path: wa/starter/src/test/java/org/apache/syncope/wa/starter/SyncopeCoreTestingServer.java
##########
@@ -68,7 +80,81 @@ public void onApplicationEvent(final ContextRefreshedEvent event) {
         }
     }
 
-    public class StubWAClientAppService implements WAClientAppService {
+    public static class StubGoogleMfaAuthTokenService implements GoogleMfaAuthTokenService {
+        private final List<GoogleMfaAuthTokenTO> tokens = new ArrayList<>();
+
+        @Override
+        public Response deleteTokensByDate(@NotNull final Date expirationDate) {
+            tokens.removeIf(token -> token.getIssuedDate().compareTo(expirationDate) >= 0);
+            return Response.noContent().build();
+        }
+
+        @Override
+        public Response deleteToken(@NotNull final String user, @NotNull final Integer token) {

Review comment:
       @mmoayyed this is still to be addressed, no?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [syncope] mmoayyed commented on a change in pull request #189: SYNCOPE-1562: Manage tokens for WA GoogleAuth MFA

Posted by GitBox <gi...@apache.org>.
mmoayyed commented on a change in pull request #189:
URL: https://github.com/apache/syncope/pull/189#discussion_r431031510



##########
File path: common/am/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/AuthProfileService.java
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.syncope.common.rest.api.service;
+
+import io.swagger.v3.oas.annotations.headers.Header;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import io.swagger.v3.oas.annotations.security.SecurityRequirement;
+import io.swagger.v3.oas.annotations.security.SecurityRequirements;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.apache.syncope.common.lib.to.AuthProfileTO;
+import org.apache.syncope.common.rest.api.RESTHeaders;
+
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import java.util.List;
+
+/**
+ * REST operations for SAML 2.0 SP metadata.
+ */
+@Tag(name = "Auth Profiles")
+@SecurityRequirements({
+    @SecurityRequirement(name = "BasicAuthentication"),
+    @SecurityRequirement(name = "Bearer")})
+@Path("authProfiles")
+public interface AuthProfileService extends JAXRSService {
+
+    @GET
+    @Produces({MediaType.APPLICATION_JSON})
+    List<AuthProfileTO> list();
+
+    @GET
+    @Path("owners/{owner}")
+    @Consumes({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Produces({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    AuthProfileTO findByOwner(@NotNull @PathParam("owner") String owner);

Review comment:
       Could you elaborate on this? Each other should have a single auth-profile, and the profile carries the related info for the owner/user such as tokens, devices, etc.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [syncope] ilgrosso commented on a change in pull request #189: SYNCOPE-1562: Manage tokens for WA GoogleAuth MFA

Posted by GitBox <gi...@apache.org>.
ilgrosso commented on a change in pull request #189:
URL: https://github.com/apache/syncope/pull/189#discussion_r427782240



##########
File path: common/am/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/wa/GoogleMfaAuthTokenService.java
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.syncope.common.rest.api.service.wa;
+
+import io.swagger.v3.oas.annotations.headers.Header;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import io.swagger.v3.oas.annotations.security.SecurityRequirement;
+import io.swagger.v3.oas.annotations.security.SecurityRequirements;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.apache.syncope.common.lib.to.GoogleMfaAuthTokenTO;
+import org.apache.syncope.common.rest.api.RESTHeaders;
+import org.apache.syncope.common.rest.api.service.JAXRSService;
+
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+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.MediaType;
+import javax.ws.rs.core.Response;
+
+import java.util.Date;
+import java.util.List;
+
+@Tag(name = "Google MFA Tokens")
+@SecurityRequirements({
+    @SecurityRequirement(name = "BasicAuthentication"),
+    @SecurityRequirement(name = "Bearer")})
+@Path("wa/gauth")
+public interface GoogleMfaAuthTokenService extends JAXRSService {
+
+    @DELETE
+    @Consumes({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Produces({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Path("tokens")
+    Response deleteTokensByDate(@NotNull @QueryParam("expirationDate") Date expirationDate);
+
+    @DELETE
+    @Consumes({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Produces({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Path("tokens/${owner}/${token}")
+    Response deleteToken(@NotNull @PathParam("owner") String owner, @NotNull @PathParam("token") Integer token);
+
+    @DELETE
+    @Consumes({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Produces({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Path("tokens/owners/${owner}")
+    Response deleteTokensFor(@NotNull @PathParam("owner") String owner);
+
+    @DELETE
+    @Consumes({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Produces({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Path("tokens/${token}")
+    Response deleteToken(@NotNull @PathParam("token") Integer token);
+
+    @DELETE
+    @Consumes({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Produces({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Path("tokens")
+    Response deleteTokens();
+
+    @ApiResponses({
+        @ApiResponse(responseCode = "201",
+            description = "GoogleMfaAuthTokenTO successfully created", headers = {
+            @Header(name = RESTHeaders.RESOURCE_KEY, schema =
+            @Schema(type = "string"),
+                description = "UUID generated for the entity created")})})
+    @POST
+    @Consumes({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Produces({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Path("tokens")
+    Response save(@NotNull GoogleMfaAuthTokenTO tokenTO);
+
+    @GET
+    @Consumes({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Produces({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Path("tokens/${owner}/${token}")
+    GoogleMfaAuthTokenTO findTokenFor(@NotNull @PathParam("owner") String owner,
+                                      @NotNull @PathParam("token") Integer token);
+
+    @GET
+    @Consumes({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Produces({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Path("tokens/owners/${owner}")
+    List<GoogleMfaAuthTokenTO> findTokensFor(@NotNull @PathParam("owner") String owner);
+
+    @GET
+    @Path("tokens/{key}")
+    @Consumes({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Produces({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    GoogleMfaAuthTokenTO findTokenFor(@NotNull @PathParam("key") String key);
+
+    @GET
+    @Consumes({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Produces({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Path("tokens/${owner}/count")
+    long countTokensForUser(@NotNull @PathParam("owner") String owner);

Review comment:
       Shouldn't this be `countTokensForOwner()` or just `countTokens(String owner)`

##########
File path: core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/auth/JPAGoogleMfaAuthToken.java
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.syncope.core.persistence.jpa.entity.auth;
+
+import org.apache.syncope.core.persistence.api.entity.auth.GoogleMfaAuthToken;
+import org.apache.syncope.core.persistence.jpa.entity.AbstractGeneratedKeyEntity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+import java.util.Date;
+import java.util.Optional;
+
+@Entity
+@Table(name = JPAGoogleMfaAuthToken.TABLE)
+public class JPAGoogleMfaAuthToken extends AbstractGeneratedKeyEntity implements GoogleMfaAuthToken {
+
+    public static final String TABLE = "GoogleMfaAuthToken";
+
+    private static final long serialVersionUID = 57352617217394093L;
+
+    @Column(nullable = false)
+    private Integer token;
+
+    @Column(nullable = false)
+    private String owner;
+
+    @Column(nullable = false)
+    private Date issuedDate;
+
+    @Override
+    public String getOwner() {
+        return owner;
+    }
+
+    @Override
+    public void setOwner(final String user) {

Review comment:
       `user` -> `owner`

##########
File path: core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/auth/GoogleMfaAuthToken.java
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.syncope.core.persistence.api.entity.auth;
+
+import org.apache.syncope.core.persistence.api.entity.Entity;
+
+import java.util.Date;
+
+public interface GoogleMfaAuthToken extends Entity {
+    String getOwner();
+
+    void setOwner(String user);

Review comment:
       `user` -> `owner`

##########
File path: core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/auth/GoogleMfaAuthToken.java
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.syncope.core.persistence.api.entity.auth;
+
+import org.apache.syncope.core.persistence.api.entity.Entity;
+
+import java.util.Date;
+
+public interface GoogleMfaAuthToken extends Entity {
+    String getOwner();
+
+    void setOwner(String user);
+
+    Date getIssuedDate();
+
+    void setIssuedDate(Date user);

Review comment:
       `user` -> `issueDate`

##########
File path: wa/starter/src/test/java/org/apache/syncope/wa/starter/SyncopeCoreTestingServer.java
##########
@@ -68,7 +80,81 @@ public void onApplicationEvent(final ContextRefreshedEvent event) {
         }
     }
 
-    public class StubWAClientAppService implements WAClientAppService {
+    public static class StubGoogleMfaAuthTokenService implements GoogleMfaAuthTokenService {
+        private final List<GoogleMfaAuthTokenTO> tokens = new ArrayList<>();
+
+        @Override
+        public Response deleteTokensByDate(@NotNull final Date expirationDate) {
+            tokens.removeIf(token -> token.getIssuedDate().compareTo(expirationDate) >= 0);
+            return Response.noContent().build();
+        }
+
+        @Override
+        public Response deleteToken(@NotNull final String user, @NotNull final Integer token) {

Review comment:
       `user` -> `owner`

##########
File path: core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/GoogleMfaAuthTokenTest.java
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.syncope.core.persistence.jpa.inner;
+
+import org.apache.syncope.core.persistence.api.dao.auth.GoogleMfaAuthTokenDAO;
+import org.apache.syncope.core.persistence.api.entity.auth.GoogleMfaAuthToken;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.Date;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+@Transactional("Master")
+public class GoogleMfaAuthTokenTest extends AbstractTest {
+
+    @Autowired
+    private GoogleMfaAuthTokenDAO googleMfaAuthTokenDAO;
+
+    @BeforeEach
+    public void setup() {
+        googleMfaAuthTokenDAO.deleteAll();
+    }
+
+    @Test
+    public void save() {
+        create("SyncopeCreate", 123456);
+    }
+
+    @Test
+    public void count() {
+        create("SyncopeCount", 123456);
+        assertEquals(1, googleMfaAuthTokenDAO.count());
+        assertEquals(1, googleMfaAuthTokenDAO.count("SyncopeCount"));
+    }
+
+    @Test
+    public void deleteByToken() {
+        GoogleMfaAuthToken token = create("SyncopeDelete", 123456);
+        googleMfaAuthTokenDAO.delete(token.getToken());
+        assertNull(googleMfaAuthTokenDAO.find(token.getOwner(), token.getToken()));
+    }
+
+    @Test
+    public void deleteByUser() {

Review comment:
       `deleteByOwner()`

##########
File path: wa/starter/src/test/java/org/apache/syncope/wa/starter/SyncopeCoreTestingServer.java
##########
@@ -68,7 +80,81 @@ public void onApplicationEvent(final ContextRefreshedEvent event) {
         }
     }
 
-    public class StubWAClientAppService implements WAClientAppService {
+    public static class StubGoogleMfaAuthTokenService implements GoogleMfaAuthTokenService {
+        private final List<GoogleMfaAuthTokenTO> tokens = new ArrayList<>();
+
+        @Override
+        public Response deleteTokensByDate(@NotNull final Date expirationDate) {
+            tokens.removeIf(token -> token.getIssuedDate().compareTo(expirationDate) >= 0);
+            return Response.noContent().build();
+        }
+
+        @Override
+        public Response deleteToken(@NotNull final String user, @NotNull final Integer token) {
+            tokens.removeIf(to -> to.getToken().equals(token) && to.getOwner().equalsIgnoreCase(user));
+            return Response.noContent().build();
+        }
+
+        @Override
+        public Response deleteTokensFor(@NotNull final String owner) {
+            tokens.removeIf(to -> to.getOwner().equalsIgnoreCase(owner));
+            return Response.noContent().build();
+        }
+
+        @Override
+        public Response deleteToken(@NotNull final Integer token) {
+            tokens.removeIf(to -> to.getToken().equals(token));
+            return Response.noContent().build();
+        }
+
+        @Override
+        public Response deleteTokens() {
+            tokens.clear();
+            return Response.noContent().build();
+        }
+
+        @Override
+        public Response save(@NotNull final GoogleMfaAuthTokenTO tokenTO) {
+            tokenTO.setKey(UUID.randomUUID().toString());
+            tokens.add(tokenTO);
+            return Response.ok().build();
+        }
+
+        @Override
+        public GoogleMfaAuthTokenTO findTokenFor(@NotNull final String user, @NotNull final Integer token) {
+            return tokens.stream()
+                .filter(to -> to.getToken().equals(token) && to.getOwner().equalsIgnoreCase(user))
+                .findFirst().get();
+        }
+
+        @Override
+        public List<GoogleMfaAuthTokenTO> findTokensFor(@NotNull final String user) {
+            return tokens.stream()
+                .filter(to -> to.getOwner().equalsIgnoreCase(user))
+                .collect(Collectors.toList());
+        }
+
+        @Override
+        public GoogleMfaAuthTokenTO findTokenFor(@NotNull final String key) {
+            return tokens.stream()
+                .filter(to -> to.getKey().equalsIgnoreCase(key))
+                .findFirst().get();
+        }
+
+        @Override
+        public long countTokensForUser(@NotNull final String user) {

Review comment:
       `user` -> `owner`

##########
File path: core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/auth/JPAGoogleMfaAuthTokenDAO.java
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.syncope.core.persistence.jpa.dao.auth;
+
+import org.apache.syncope.core.persistence.api.dao.auth.GoogleMfaAuthTokenDAO;
+import org.apache.syncope.core.persistence.api.entity.auth.GoogleMfaAuthToken;
+import org.apache.syncope.core.persistence.jpa.dao.AbstractDAO;
+import org.apache.syncope.core.persistence.jpa.entity.auth.JPAGoogleMfaAuthToken;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.persistence.NoResultException;
+import javax.persistence.TypedQuery;
+
+import java.util.Date;
+import java.util.List;
+
+@Repository
+public class JPAGoogleMfaAuthTokenDAO extends AbstractDAO<GoogleMfaAuthToken> implements GoogleMfaAuthTokenDAO {
+    @Override
+    @Transactional(readOnly = true)
+    public GoogleMfaAuthToken find(final String key) {
+        return entityManager().find(JPAGoogleMfaAuthToken.class, key);
+    }
+
+    @Override
+    @Transactional(readOnly = true)
+    public GoogleMfaAuthToken find(final String owner, final Integer otp) {
+        TypedQuery<GoogleMfaAuthToken> query = entityManager().createQuery(
+            "SELECT e FROM " + JPAGoogleMfaAuthToken.class.getSimpleName()
+                + " e WHERE e.owner=:owner AND e.token=:token",
+            GoogleMfaAuthToken.class);
+        query.setParameter("owner", owner);
+        query.setParameter("token", otp);
+        GoogleMfaAuthToken result = null;
+        try {
+            result = query.getSingleResult();
+        } catch (final NoResultException e) {
+            LOG.debug("No Google Mfa Token found for owner = {} and otp = {}", owner, otp);
+        }
+        return result;
+    }
+
+    @Override
+    public GoogleMfaAuthToken save(final GoogleMfaAuthToken token) {
+        return entityManager().merge(token);
+    }
+
+    @Override
+    @Transactional(readOnly = true)
+    public long count(final String owner) {
+        TypedQuery<Long> query = entityManager().createQuery(
+            "SELECT COUNT(e.user) FROM " + JPAGoogleMfaAuthToken.class.getSimpleName() + " e WHERE e.owner=:owner",

Review comment:
       `e.owner`

##########
File path: core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/auth/JPAGoogleMfaAuthTokenDAO.java
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.syncope.core.persistence.jpa.dao.auth;
+
+import org.apache.syncope.core.persistence.api.dao.auth.GoogleMfaAuthTokenDAO;
+import org.apache.syncope.core.persistence.api.entity.auth.GoogleMfaAuthToken;
+import org.apache.syncope.core.persistence.jpa.dao.AbstractDAO;
+import org.apache.syncope.core.persistence.jpa.entity.auth.JPAGoogleMfaAuthToken;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.persistence.NoResultException;
+import javax.persistence.TypedQuery;
+
+import java.util.Date;
+import java.util.List;
+
+@Repository
+public class JPAGoogleMfaAuthTokenDAO extends AbstractDAO<GoogleMfaAuthToken> implements GoogleMfaAuthTokenDAO {
+    @Override
+    @Transactional(readOnly = true)
+    public GoogleMfaAuthToken find(final String key) {
+        return entityManager().find(JPAGoogleMfaAuthToken.class, key);
+    }
+
+    @Override
+    @Transactional(readOnly = true)
+    public GoogleMfaAuthToken find(final String owner, final Integer otp) {
+        TypedQuery<GoogleMfaAuthToken> query = entityManager().createQuery(
+            "SELECT e FROM " + JPAGoogleMfaAuthToken.class.getSimpleName()
+                + " e WHERE e.owner=:owner AND e.token=:token",
+            GoogleMfaAuthToken.class);
+        query.setParameter("owner", owner);
+        query.setParameter("token", otp);
+        GoogleMfaAuthToken result = null;
+        try {
+            result = query.getSingleResult();
+        } catch (final NoResultException e) {
+            LOG.debug("No Google Mfa Token found for owner = {} and otp = {}", owner, otp);
+        }
+        return result;
+    }
+
+    @Override
+    public GoogleMfaAuthToken save(final GoogleMfaAuthToken token) {
+        return entityManager().merge(token);
+    }
+
+    @Override
+    @Transactional(readOnly = true)
+    public long count(final String owner) {
+        TypedQuery<Long> query = entityManager().createQuery(
+            "SELECT COUNT(e.user) FROM " + JPAGoogleMfaAuthToken.class.getSimpleName() + " e WHERE e.owner=:owner",
+            Long.class);
+        query.setParameter("owner", owner);
+        return query.getSingleResult();
+    }
+
+    @Override
+    @Transactional(readOnly = true)
+    public long count() {
+        TypedQuery<Long> query = entityManager().createQuery(
+            "SELECT COUNT(e.owner) FROM " + JPAGoogleMfaAuthToken.class.getSimpleName() + " e",
+            Long.class);
+        return query.getSingleResult();
+    }
+
+    @Override
+    public void deleteAll() {
+        entityManager()
+            .createQuery("DELETE FROM " + JPAGoogleMfaAuthToken.class.getSimpleName() + " e")
+            .executeUpdate();
+    }
+
+    @Override
+    public void delete(final Integer otp) {
+        entityManager()
+            .createQuery("DELETE FROM " + JPAGoogleMfaAuthToken.class.getSimpleName() + " e WHERE e.token=:token")
+            .setParameter("token", otp)
+            .executeUpdate();
+    }
+
+    @Override
+    public void delete(final String owner) {
+        entityManager()
+            .createQuery("DELETE FROM " + JPAGoogleMfaAuthToken.class.getSimpleName() + " e WHERE e.owner=:owner")
+            .setParameter("owner", owner)
+            .executeUpdate();
+    }
+
+    @Override
+    public void delete(final String owner, final Integer otp) {
+        entityManager()
+            .createQuery("DELETE FROM " + JPAGoogleMfaAuthToken.class.getSimpleName()
+                + " e WHERE e.owner=:user AND e.token=:token")
+            .setParameter("owner", owner)
+            .setParameter("token", otp)
+            .executeUpdate();
+    }
+
+    @Override
+    public void delete(final Date expirationDate) {
+        entityManager()
+            .createQuery("DELETE FROM " + JPAGoogleMfaAuthToken.class.getSimpleName()
+                + " e WHERE e.issuedDateTime>=:expired")
+            .setParameter("expired", expirationDate)
+            .executeUpdate();
+    }
+
+    @Override
+    public List<GoogleMfaAuthToken> findForOwner(final String owner) {
+        TypedQuery<GoogleMfaAuthToken> query = entityManager().createQuery(
+            "SELECT e FROM " + JPAGoogleMfaAuthToken.class.getSimpleName() + " e WHERE e.owner=:owner",
+            GoogleMfaAuthToken.class);
+        query.setParameter("owner", owner);
+        try {
+            return query.getResultList();
+        } catch (final NoResultException e) {
+            LOG.debug("No Google Mfa Token found for user = {}", owner);

Review comment:
       `"No Google Mfa Token found for owner = {}"`

##########
File path: core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/auth/JPAGoogleMfaAuthTokenDAO.java
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.syncope.core.persistence.jpa.dao.auth;
+
+import org.apache.syncope.core.persistence.api.dao.auth.GoogleMfaAuthTokenDAO;
+import org.apache.syncope.core.persistence.api.entity.auth.GoogleMfaAuthToken;
+import org.apache.syncope.core.persistence.jpa.dao.AbstractDAO;
+import org.apache.syncope.core.persistence.jpa.entity.auth.JPAGoogleMfaAuthToken;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.persistence.NoResultException;
+import javax.persistence.TypedQuery;
+
+import java.util.Date;
+import java.util.List;
+
+@Repository
+public class JPAGoogleMfaAuthTokenDAO extends AbstractDAO<GoogleMfaAuthToken> implements GoogleMfaAuthTokenDAO {
+    @Override
+    @Transactional(readOnly = true)
+    public GoogleMfaAuthToken find(final String key) {
+        return entityManager().find(JPAGoogleMfaAuthToken.class, key);
+    }
+
+    @Override
+    @Transactional(readOnly = true)
+    public GoogleMfaAuthToken find(final String owner, final Integer otp) {
+        TypedQuery<GoogleMfaAuthToken> query = entityManager().createQuery(
+            "SELECT e FROM " + JPAGoogleMfaAuthToken.class.getSimpleName()
+                + " e WHERE e.owner=:owner AND e.token=:token",
+            GoogleMfaAuthToken.class);
+        query.setParameter("owner", owner);
+        query.setParameter("token", otp);
+        GoogleMfaAuthToken result = null;
+        try {
+            result = query.getSingleResult();
+        } catch (final NoResultException e) {
+            LOG.debug("No Google Mfa Token found for owner = {} and otp = {}", owner, otp);
+        }
+        return result;
+    }
+
+    @Override
+    public GoogleMfaAuthToken save(final GoogleMfaAuthToken token) {
+        return entityManager().merge(token);
+    }
+
+    @Override
+    @Transactional(readOnly = true)
+    public long count(final String owner) {
+        TypedQuery<Long> query = entityManager().createQuery(
+            "SELECT COUNT(e.user) FROM " + JPAGoogleMfaAuthToken.class.getSimpleName() + " e WHERE e.owner=:owner",
+            Long.class);
+        query.setParameter("owner", owner);
+        return query.getSingleResult();
+    }
+
+    @Override
+    @Transactional(readOnly = true)
+    public long count() {
+        TypedQuery<Long> query = entityManager().createQuery(
+            "SELECT COUNT(e.owner) FROM " + JPAGoogleMfaAuthToken.class.getSimpleName() + " e",
+            Long.class);
+        return query.getSingleResult();
+    }
+
+    @Override
+    public void deleteAll() {
+        entityManager()
+            .createQuery("DELETE FROM " + JPAGoogleMfaAuthToken.class.getSimpleName() + " e")
+            .executeUpdate();
+    }
+
+    @Override
+    public void delete(final Integer otp) {
+        entityManager()
+            .createQuery("DELETE FROM " + JPAGoogleMfaAuthToken.class.getSimpleName() + " e WHERE e.token=:token")
+            .setParameter("token", otp)
+            .executeUpdate();
+    }
+
+    @Override
+    public void delete(final String owner) {
+        entityManager()
+            .createQuery("DELETE FROM " + JPAGoogleMfaAuthToken.class.getSimpleName() + " e WHERE e.owner=:owner")
+            .setParameter("owner", owner)
+            .executeUpdate();
+    }
+
+    @Override
+    public void delete(final String owner, final Integer otp) {
+        entityManager()
+            .createQuery("DELETE FROM " + JPAGoogleMfaAuthToken.class.getSimpleName()
+                + " e WHERE e.owner=:user AND e.token=:token")

Review comment:
       `:owner`

##########
File path: wa/starter/src/test/java/org/apache/syncope/wa/starter/SyncopeCoreTestingServer.java
##########
@@ -68,7 +80,81 @@ public void onApplicationEvent(final ContextRefreshedEvent event) {
         }
     }
 
-    public class StubWAClientAppService implements WAClientAppService {
+    public static class StubGoogleMfaAuthTokenService implements GoogleMfaAuthTokenService {
+        private final List<GoogleMfaAuthTokenTO> tokens = new ArrayList<>();
+
+        @Override
+        public Response deleteTokensByDate(@NotNull final Date expirationDate) {
+            tokens.removeIf(token -> token.getIssuedDate().compareTo(expirationDate) >= 0);
+            return Response.noContent().build();
+        }
+
+        @Override
+        public Response deleteToken(@NotNull final String user, @NotNull final Integer token) {
+            tokens.removeIf(to -> to.getToken().equals(token) && to.getOwner().equalsIgnoreCase(user));
+            return Response.noContent().build();
+        }
+
+        @Override
+        public Response deleteTokensFor(@NotNull final String owner) {
+            tokens.removeIf(to -> to.getOwner().equalsIgnoreCase(owner));
+            return Response.noContent().build();
+        }
+
+        @Override
+        public Response deleteToken(@NotNull final Integer token) {
+            tokens.removeIf(to -> to.getToken().equals(token));
+            return Response.noContent().build();
+        }
+
+        @Override
+        public Response deleteTokens() {
+            tokens.clear();
+            return Response.noContent().build();
+        }
+
+        @Override
+        public Response save(@NotNull final GoogleMfaAuthTokenTO tokenTO) {
+            tokenTO.setKey(UUID.randomUUID().toString());
+            tokens.add(tokenTO);
+            return Response.ok().build();
+        }
+
+        @Override
+        public GoogleMfaAuthTokenTO findTokenFor(@NotNull final String user, @NotNull final Integer token) {

Review comment:
       `user` -> `owner`

##########
File path: core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/GoogleMfaAuthTokenTest.java
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.syncope.core.persistence.jpa.inner;
+
+import org.apache.syncope.core.persistence.api.dao.auth.GoogleMfaAuthTokenDAO;
+import org.apache.syncope.core.persistence.api.entity.auth.GoogleMfaAuthToken;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.Date;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+@Transactional("Master")
+public class GoogleMfaAuthTokenTest extends AbstractTest {
+
+    @Autowired
+    private GoogleMfaAuthTokenDAO googleMfaAuthTokenDAO;
+
+    @BeforeEach
+    public void setup() {
+        googleMfaAuthTokenDAO.deleteAll();
+    }
+
+    @Test
+    public void save() {
+        create("SyncopeCreate", 123456);
+    }
+
+    @Test
+    public void count() {
+        create("SyncopeCount", 123456);
+        assertEquals(1, googleMfaAuthTokenDAO.count());
+        assertEquals(1, googleMfaAuthTokenDAO.count("SyncopeCount"));
+    }
+
+    @Test
+    public void deleteByToken() {
+        GoogleMfaAuthToken token = create("SyncopeDelete", 123456);
+        googleMfaAuthTokenDAO.delete(token.getToken());
+        assertNull(googleMfaAuthTokenDAO.find(token.getOwner(), token.getToken()));
+    }
+
+    @Test
+    public void deleteByUser() {
+        GoogleMfaAuthToken token = create("SyncopeDelete", 123456);
+        googleMfaAuthTokenDAO.delete(token.getOwner());
+        assertNull(googleMfaAuthTokenDAO.find(token.getOwner(), token.getToken()));
+    }
+
+    @Test
+    public void deleteByUserAndToken() {

Review comment:
       `deleteByOwnerAndToken()`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [syncope] mmoayyed commented on a change in pull request #189: SYNCOPE-1562: Manage tokens for WA GoogleAuth MFA

Posted by GitBox <gi...@apache.org>.
mmoayyed commented on a change in pull request #189:
URL: https://github.com/apache/syncope/pull/189#discussion_r431036380



##########
File path: core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/data/AuthProfileDataBinder.java
##########
@@ -0,0 +1,27 @@
+/*

Review comment:
       Given we have an AuthProfileTO entity, should this still be removed? 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [syncope] ilgrosso commented on a change in pull request #189: SYNCOPE-1562: Manage tokens for WA GoogleAuth MFA

Posted by GitBox <gi...@apache.org>.
ilgrosso commented on a change in pull request #189:
URL: https://github.com/apache/syncope/pull/189#discussion_r429891279



##########
File path: core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/auth/AuthProfile.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.syncope.core.persistence.api.entity.auth;
+
+import org.apache.syncope.common.lib.types.GoogleMfaAuthToken;
+import org.apache.syncope.core.persistence.api.entity.Entity;
+
+import java.util.List;
+
+public interface AuthProfile extends Entity {
+
+    String getOwner();
+
+    void setOwner(String owner);
+    
+    List<GoogleMfaAuthToken> getGoogleMfaAuthTokens();
+
+    void setGoogleMfaAuthTokens(List<GoogleMfaAuthToken> tokens);

Review comment:
       This setter method is generally not required by other entities.

##########
File path: core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/data/AuthProfileDataBinder.java
##########
@@ -0,0 +1,27 @@
+/*

Review comment:
       This class should not be needed, the purpose of databinding is to transform entities in TOs and viceversa. Just use `entityFactory` in the calling place.

##########
File path: core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/auth/AuthProfileDAO.java
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.syncope.core.persistence.api.dao.auth;
+
+import org.apache.syncope.core.persistence.api.dao.DAO;
+import org.apache.syncope.core.persistence.api.entity.auth.AuthProfile;
+
+import java.util.List;
+import java.util.Optional;
+
+public interface AuthProfileDAO extends DAO<AuthProfile> {
+
+    List<AuthProfile> findAll();

Review comment:
       How to delete an `AuthProfile` instance?

##########
File path: core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/GoogleMfaAuthTokenDataBinderImpl.java
##########
@@ -0,0 +1,50 @@
+/*

Review comment:
       As said above.

##########
File path: core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/auth/AuthProfile.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.syncope.core.persistence.api.entity.auth;
+
+import org.apache.syncope.common.lib.types.GoogleMfaAuthToken;
+import org.apache.syncope.core.persistence.api.entity.Entity;
+
+import java.util.List;
+
+public interface AuthProfile extends Entity {
+
+    String getOwner();
+
+    void setOwner(String owner);
+    
+    List<GoogleMfaAuthToken> getGoogleMfaAuthTokens();
+
+    void setGoogleMfaAuthTokens(List<GoogleMfaAuthToken> tokens);
+
+    void addGoogleMfaAuthToken(GoogleMfaAuthToken token);

Review comment:
       `add()` should be enough (see other entities)

##########
File path: core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/auth/AuthProfile.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.syncope.core.persistence.api.entity.auth;
+
+import org.apache.syncope.common.lib.types.GoogleMfaAuthToken;
+import org.apache.syncope.core.persistence.api.entity.Entity;
+
+import java.util.List;
+
+public interface AuthProfile extends Entity {
+
+    String getOwner();
+
+    void setOwner(String owner);
+    
+    List<GoogleMfaAuthToken> getGoogleMfaAuthTokens();
+
+    void setGoogleMfaAuthTokens(List<GoogleMfaAuthToken> tokens);
+
+    void addGoogleMfaAuthToken(GoogleMfaAuthToken token);
+
+    void clearGoogleMfaAuthTokens();

Review comment:
       This method is generally not required by other entities.

##########
File path: core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AuthProfileDataBinderImpl.java
##########
@@ -0,0 +1,39 @@
+/*

Review comment:
       As said above.

##########
File path: common/am/lib/src/main/java/org/apache/syncope/common/lib/to/GoogleMfaAuthTokenTO.java
##########
@@ -0,0 +1,143 @@
+/*

Review comment:
       This class is not needed, just use `GoogleMfaAuthToken` everywhere.

##########
File path: core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/data/GoogleMfaAuthTokenDataBinder.java
##########
@@ -0,0 +1,30 @@
+/*

Review comment:
       This class should not be needed.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [syncope] mmoayyed merged pull request #189: SYNCOPE-1562: Manage tokens for WA GoogleAuth MFA

Posted by GitBox <gi...@apache.org>.
mmoayyed merged pull request #189:
URL: https://github.com/apache/syncope/pull/189


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [syncope] mmoayyed commented on a change in pull request #189: SYNCOPE-1562: Manage tokens for WA GoogleAuth MFA

Posted by GitBox <gi...@apache.org>.
mmoayyed commented on a change in pull request #189:
URL: https://github.com/apache/syncope/pull/189#discussion_r431036748



##########
File path: common/am/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/AuthProfileService.java
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.syncope.common.rest.api.service;
+
+import io.swagger.v3.oas.annotations.headers.Header;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import io.swagger.v3.oas.annotations.security.SecurityRequirement;
+import io.swagger.v3.oas.annotations.security.SecurityRequirements;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.apache.syncope.common.lib.to.AuthProfileTO;
+import org.apache.syncope.common.rest.api.RESTHeaders;
+
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import java.util.List;
+
+/**
+ * REST operations for SAML 2.0 SP metadata.
+ */
+@Tag(name = "Auth Profiles")
+@SecurityRequirements({
+    @SecurityRequirement(name = "BasicAuthentication"),
+    @SecurityRequirement(name = "Bearer")})
+@Path("authProfiles")
+public interface AuthProfileService extends JAXRSService {
+
+    @GET
+    @Produces({MediaType.APPLICATION_JSON})
+    List<AuthProfileTO> list();
+
+    @GET
+    @Path("owners/{owner}")
+    @Consumes({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    @Produces({MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML})
+    AuthProfileTO findByOwner(@NotNull @PathParam("owner") String owner);

Review comment:
       Sure. Will do.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [syncope] ilgrosso commented on a change in pull request #189: SYNCOPE-1562: Manage tokens for WA GoogleAuth MFA

Posted by GitBox <gi...@apache.org>.
ilgrosso commented on a change in pull request #189:
URL: https://github.com/apache/syncope/pull/189#discussion_r430202043



##########
File path: core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/auth/AuthProfile.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.syncope.core.persistence.api.entity.auth;
+
+import org.apache.syncope.common.lib.types.GoogleMfaAuthToken;
+import org.apache.syncope.core.persistence.api.entity.Entity;
+
+import java.util.List;
+
+public interface AuthProfile extends Entity {
+
+    String getOwner();
+
+    void setOwner(String owner);
+    
+    List<GoogleMfaAuthToken> getGoogleMfaAuthTokens();
+
+    void setGoogleMfaAuthTokens(List<GoogleMfaAuthToken> tokens);

Review comment:
       exactly, it is not needed, following the general approach we use everywhere else

##########
File path: core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/auth/AuthProfileDAO.java
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.syncope.core.persistence.api.dao.auth;
+
+import org.apache.syncope.core.persistence.api.dao.DAO;
+import org.apache.syncope.core.persistence.api.entity.auth.AuthProfile;
+
+import java.util.List;
+import java.util.Optional;
+
+public interface AuthProfileDAO extends DAO<AuthProfile> {
+
+    List<AuthProfile> findAll();

Review comment:
       for administration purpose, I mean; I think we should also have an `AuthProfileService` allowing to browse and delete the available profiles.

##########
File path: core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/auth/AuthProfile.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.syncope.core.persistence.api.entity.auth;
+
+import org.apache.syncope.common.lib.types.GoogleMfaAuthToken;
+import org.apache.syncope.core.persistence.api.entity.Entity;
+
+import java.util.List;
+
+public interface AuthProfile extends Entity {
+
+    String getOwner();
+
+    void setOwner(String owner);
+    
+    List<GoogleMfaAuthToken> getGoogleMfaAuthTokens();
+
+    void setGoogleMfaAuthTokens(List<GoogleMfaAuthToken> tokens);

Review comment:
       I was referring to the fact of having setter for collection, which we don't generally do; however, it seems that [JPAConnInstance](https://github.com/apache/syncope/blob/master/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAConnInstance.java#L195) is exactly in the same situation, as the collection is being serialized to JSON.
   
   Sorry for the noise!

##########
File path: core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/auth/AuthProfileDAO.java
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.syncope.core.persistence.api.dao.auth;
+
+import org.apache.syncope.core.persistence.api.dao.DAO;
+import org.apache.syncope.core.persistence.api.entity.auth.AuthProfile;
+
+import java.util.List;
+import java.util.Optional;
+
+public interface AuthProfileDAO extends DAO<AuthProfile> {
+
+    List<AuthProfile> findAll();

Review comment:
       Correct




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [syncope] ilgrosso commented on a change in pull request #189: SYNCOPE-1562: Manage tokens for WA GoogleAuth MFA

Posted by GitBox <gi...@apache.org>.
ilgrosso commented on a change in pull request #189:
URL: https://github.com/apache/syncope/pull/189#discussion_r431039713



##########
File path: core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/data/AuthProfileDataBinder.java
##########
@@ -0,0 +1,27 @@
+/*

Review comment:
       Ah, I see you are right, please ignore this.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org