Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JAMES-1783 POSTing on download endpoint should return a token
- Loading branch information
Raphael Ouazana
committed
Jun 29, 2016
1 parent
9963086
commit a5bd1c7
Showing
18 changed files
with
644 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadPost.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Feature: Alternative authentication mechanism for getting attachment via a POST request returning a specific authentication token | ||
As a James user | ||
I want to retrieve my attachments without an alternative authentication mechanim | ||
|
||
Background: | ||
Given a domain named "domain.tld" | ||
And a connected user "username@domain.tld" | ||
And "username@domain.tld" has a mailbox "inbox" | ||
|
||
Scenario: Asking for an attachment access token with an unknown blobId | ||
When "username@domain.tld" asks for a token for attachment "123" | ||
Then the user should receive a not found response | ||
|
||
Scenario: Asking for an attachment access token with a previously stored blobId | ||
Given "username@domain.tld" mailbox "inbox" contains a message "1" with an attachment "2" | ||
When "username@domain.tld" asks for a token for attachment "2" | ||
Then the user should receive an attachment access token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
server/protocols/jmap/src/main/java/org/apache/james/jmap/api/SimpleTokenManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/**************************************************************** | ||
* 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.api; | ||
|
||
import org.apache.james.jmap.model.SignedExpiringToken; | ||
|
||
public interface SimpleTokenManager { | ||
enum TokenStatus { | ||
OK, | ||
INVALID, | ||
EXPIRED | ||
} | ||
|
||
TokenStatus getValidity(SignedExpiringToken token); | ||
|
||
boolean isValid(SignedExpiringToken token); | ||
} |
73 changes: 73 additions & 0 deletions
73
server/protocols/jmap/src/main/java/org/apache/james/jmap/crypto/SignedTokenFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/**************************************************************** | ||
* 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.crypto; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.apache.james.jmap.api.SimpleTokenFactory; | ||
import org.apache.james.jmap.model.AttachmentAccessToken; | ||
import org.apache.james.jmap.model.ContinuationToken; | ||
import org.apache.james.util.date.ZonedDateTimeProvider; | ||
|
||
import com.google.common.base.Joiner; | ||
import com.google.common.base.Preconditions; | ||
import com.google.common.base.Strings; | ||
|
||
public class SignedTokenFactory implements SimpleTokenFactory { | ||
|
||
private final SignatureHandler signatureHandler; | ||
private final ZonedDateTimeProvider zonedDateTimeProvider; | ||
|
||
@Inject | ||
public SignedTokenFactory(SignatureHandler signatureHandler, ZonedDateTimeProvider zonedDateTimeProvider) { | ||
this.signatureHandler = signatureHandler; | ||
this.zonedDateTimeProvider = zonedDateTimeProvider; | ||
} | ||
|
||
@Override | ||
public ContinuationToken generateContinuationToken(String username) { | ||
Preconditions.checkNotNull(username); | ||
ZonedDateTime expirationTime = zonedDateTimeProvider.get().plusMinutes(15); | ||
return new ContinuationToken(username, | ||
expirationTime, | ||
signatureHandler.sign( | ||
Joiner.on(ContinuationToken.SEPARATOR) | ||
.join(username, | ||
DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(expirationTime)))); | ||
} | ||
|
||
@Override | ||
public AttachmentAccessToken generateAttachmentAccessToken(String username, String blobId) { | ||
Preconditions.checkArgument(! Strings.isNullOrEmpty(blobId)); | ||
ZonedDateTime expirationTime = zonedDateTimeProvider.get().plusMinutes(5); | ||
return AttachmentAccessToken.builder() | ||
.username(username) | ||
.blobId(blobId) | ||
.expirationDate(expirationTime) | ||
.signature(signatureHandler.sign(Joiner.on(AttachmentAccessToken.SEPARATOR) | ||
.join(username, | ||
blobId, | ||
DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(expirationTime)))) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.