You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2023/01/09 07:51:02 UTC

[GitHub] [james-project] quantranhong1999 opened a new pull request, #1380: JAMES-3756 JMAP API endpoint should support delegation

quantranhong1999 opened a new pull request, #1380:
URL: https://github.com/apache/james-project/pull/1380

    - [x] Delegation for JMAP API (QUAN)
    - [ ] Delegate/set only be called by primaryAccount (QUAN)
    
   Others (could be in diff PRs): 
    - [ ] Delegation for upload (TUNG)
    - [ ] Delegation for downloads (TUNG)
    - [ ] Delegation for all kinds of push


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[GitHub] [james-project] quantranhong1999 commented on a diff in pull request #1380: JAMES-3756 JMAP API endpoint should support delegation

Posted by GitBox <gi...@apache.org>.
quantranhong1999 commented on code in PR #1380:
URL: https://github.com/apache/james-project/pull/1380#discussion_r1064372844


##########
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/SessionTranslator.scala:
##########
@@ -0,0 +1,51 @@
+/****************************************************************
+ * 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.james.jmap.core
+
+import javax.inject.Inject
+import org.apache.james.core.Username
+import org.apache.james.jmap.method.AccountNotFoundException
+import org.apache.james.mailbox.{MailboxSession, SessionProvider}
+import org.apache.james.user.api.DelegationStore
+import org.apache.james.util.ReactorUtils
+import reactor.core.scala.publisher.{SFlux, SMono}
+
+class SessionTranslator  @Inject()(delegationStore: DelegationStore, sessionProvider: SessionProvider) {
+  def delegateIfNeeded(session: MailboxSession, targetAccountId: AccountId): SMono[MailboxSession] =
+    if (needDelegation(session, targetAccountId)) {
+      delegate(session, targetAccountId)
+    } else {
+      SMono.just(session)
+    }
+
+  private def needDelegation(session: MailboxSession, targetAccountId: AccountId): Boolean =
+   !hasAccountId(targetAccountId)(session.getUser)
+
+  private def hasAccountId(targetAccountId: AccountId)(username: Username): Boolean =
+    AccountId.from(username).toOption.contains(targetAccountId)
+
+  private def delegate(session: MailboxSession, targetAccountId: AccountId): SMono[MailboxSession] =
+    SFlux(delegationStore.delegatedUsers(session.getUser))
+      .filter(hasAccountId(targetAccountId))
+      .flatMap(targetUser => SMono.fromCallable(() => sessionProvider.authenticate(session.getUser).as(targetUser))
+        .subscribeOn(ReactorUtils.BLOCKING_CALL_WRAPPER))

Review Comment:
   `canLoginAsOtherUser` is blocking (in the reactor HTTP thread) therefore the `BLOCKING_CALL_WRAPPER`. We could try to reactify `Authorizator` one day and remove 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.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[GitHub] [james-project] vttranlina commented on a diff in pull request #1380: JAMES-3756 JMAP API endpoint should support delegation

Posted by GitBox <gi...@apache.org>.
vttranlina commented on code in PR #1380:
URL: https://github.com/apache/james-project/pull/1380#discussion_r1064422457


##########
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/SessionTranslator.scala:
##########
@@ -0,0 +1,51 @@
+/****************************************************************
+ * 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.james.jmap.core
+
+import javax.inject.Inject
+import org.apache.james.core.Username
+import org.apache.james.jmap.method.AccountNotFoundException
+import org.apache.james.mailbox.{MailboxSession, SessionProvider}
+import org.apache.james.user.api.DelegationStore
+import org.apache.james.util.ReactorUtils
+import reactor.core.scala.publisher.{SFlux, SMono}
+
+class SessionTranslator  @Inject()(delegationStore: DelegationStore, sessionProvider: SessionProvider) {
+  def delegateIfNeeded(session: MailboxSession, targetAccountId: AccountId): SMono[MailboxSession] =
+    if (needDelegation(session, targetAccountId)) {
+      delegate(session, targetAccountId)
+    } else {
+      SMono.just(session)
+    }
+
+  private def needDelegation(session: MailboxSession, targetAccountId: AccountId): Boolean =
+   !hasAccountId(targetAccountId)(session.getUser)

Review Comment:
   Good catch
   In the POC commit, it misses `!` 
   



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[GitHub] [james-project] chibenwa commented on a diff in pull request #1380: JAMES-3756 JMAP API endpoint should support delegation

Posted by GitBox <gi...@apache.org>.
chibenwa commented on code in PR #1380:
URL: https://github.com/apache/james-project/pull/1380#discussion_r1064451688


##########
server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/DelegateSetContract.scala:
##########
@@ -516,4 +516,47 @@ trait DelegateSetContract {
       assertThat(server.getProbe(classOf[DelegationProbe]).getAuthorizedUsers(BOB).asJavaCollection)
         .containsExactly(ANDRE))
   }
+
+  @Test
+  def bobCanOnlyManageHisPrimaryAccountSetting(server: GuiceJamesServer): Unit = {
+    server.getProbe(classOf[DelegationProbe]).addAuthorizedUser(ANDRE, BOB)
+    val request =
+      s"""{
+         |	"using": ["urn:ietf:params:jmap:core", "urn:apache:james:params:jmap:delegation"],
+         |	"methodCalls": [
+         |		[
+         |			"Delegate/set", {
+         |				"accountId": "$ANDRE_ACCOUNT_ID",
+         |				"create": {
+         |					"4f29": {
+         |						"username": "cedric@domain.tld"
+         |					}
+         |				}
+         |			}, "0"
+         |		]
+         |	]
+         |}""".stripMargin
+
+    val response =  `given`
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(request)
+    .when
+      .post.prettyPeek()
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response)
+      .inPath("methodResponses[0][1].notCreated")
+      .isEqualTo(
+        s"""{
+           |	"4f29": {
+           |		"type": "forbidden",
+           |		"description": "${BOB.asString()} can not manage ${ANDRE.asString()}'s account settings"
+           |	}
+           |}""".stripMargin)
+  }
 }

Review Comment:
   Can we answer that when Bob have not delegated his accounts to ALice, and alice tries to delegate bob accounts she gets an account not found response, if it is not yet implemented?



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[GitHub] [james-project] chibenwa merged pull request #1380: JAMES-3756 JMAP API endpoint should support delegation

Posted by GitBox <gi...@apache.org>.
chibenwa merged PR #1380:
URL: https://github.com/apache/james-project/pull/1380


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[GitHub] [james-project] quantranhong1999 commented on pull request #1380: JAMES-3756 JMAP API endpoint should support delegation

Posted by GitBox <gi...@apache.org>.
quantranhong1999 commented on PR #1380:
URL: https://github.com/apache/james-project/pull/1380#issuecomment-1376693874

   Rebased to solve conflict.


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[GitHub] [james-project] chibenwa commented on a diff in pull request #1380: JAMES-3756 JMAP API endpoint should support delegation

Posted by GitBox <gi...@apache.org>.
chibenwa commented on code in PR #1380:
URL: https://github.com/apache/james-project/pull/1380#discussion_r1064381254


##########
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/SessionTranslator.scala:
##########
@@ -0,0 +1,51 @@
+/****************************************************************
+ * 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.james.jmap.core
+
+import javax.inject.Inject
+import org.apache.james.core.Username
+import org.apache.james.jmap.method.AccountNotFoundException
+import org.apache.james.mailbox.{MailboxSession, SessionProvider}
+import org.apache.james.user.api.DelegationStore
+import org.apache.james.util.ReactorUtils
+import reactor.core.scala.publisher.{SFlux, SMono}
+
+class SessionTranslator  @Inject()(delegationStore: DelegationStore, sessionProvider: SessionProvider) {
+  def delegateIfNeeded(session: MailboxSession, targetAccountId: AccountId): SMono[MailboxSession] =
+    if (needDelegation(session, targetAccountId)) {
+      delegate(session, targetAccountId)
+    } else {
+      SMono.just(session)
+    }
+
+  private def needDelegation(session: MailboxSession, targetAccountId: AccountId): Boolean =
+   !hasAccountId(targetAccountId)(session.getUser)
+
+  private def hasAccountId(targetAccountId: AccountId)(username: Username): Boolean =
+    AccountId.from(username).toOption.contains(targetAccountId)
+
+  private def delegate(session: MailboxSession, targetAccountId: AccountId): SMono[MailboxSession] =
+    SFlux(delegationStore.delegatedUsers(session.getUser))
+      .filter(hasAccountId(targetAccountId))
+      .flatMap(targetUser => SMono.fromCallable(() => sessionProvider.authenticate(session.getUser).as(targetUser))
+        .subscribeOn(ReactorUtils.BLOCKING_CALL_WRAPPER))

Review Comment:
   Good catch!



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[GitHub] [james-project] chibenwa commented on a diff in pull request #1380: JAMES-3756 JMAP API endpoint should support delegation

Posted by GitBox <gi...@apache.org>.
chibenwa commented on code in PR #1380:
URL: https://github.com/apache/james-project/pull/1380#discussion_r1064450688


##########
server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/DelegateSetContract.scala:
##########
@@ -516,4 +516,47 @@ trait DelegateSetContract {
       assertThat(server.getProbe(classOf[DelegationProbe]).getAuthorizedUsers(BOB).asJavaCollection)
         .containsExactly(ANDRE))
   }
+
+  @Test
+  def bobCanOnlyManageHisPrimaryAccountSetting(server: GuiceJamesServer): Unit = {
+    server.getProbe(classOf[DelegationProbe]).addAuthorizedUser(ANDRE, BOB)
+    val request =
+      s"""{
+         |	"using": ["urn:ietf:params:jmap:core", "urn:apache:james:params:jmap:delegation"],
+         |	"methodCalls": [
+         |		[
+         |			"Delegate/set", {
+         |				"accountId": "$ANDRE_ACCOUNT_ID",
+         |				"create": {
+         |					"4f29": {
+         |						"username": "cedric@domain.tld"
+         |					}
+         |				}
+         |			}, "0"
+         |		]
+         |	]
+         |}""".stripMargin
+
+    val response =  `given`
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(request)
+    .when
+      .post.prettyPeek()

Review Comment:
   Debug



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org