Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#105489788] https://www.pivotaltracker.com/story/show/105489788 Signed-off-by: Jonathan Lo <jlo@us.ibm.com>
- Loading branch information
Showing
10 changed files
with
499 additions
and
27 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
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
29 changes: 29 additions & 0 deletions
29
scim/src/main/java/org/cloudfoundry/identity/uaa/scim/endpoints/VerificationResponse.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,29 @@ | ||
/******************************************************************************* | ||
* Cloud Foundry | ||
* Copyright (c) [2009-2015] Pivotal Software, Inc. All Rights Reserved. | ||
* <p> | ||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this product except in compliance with the License. | ||
* <p> | ||
* This product includes a number of subcomponents with | ||
* separate copyright notices and license terms. Your use of these | ||
* subcomponents is subject to the terms and conditions of the | ||
* subcomponent's license, as noted in the LICENSE file. | ||
*******************************************************************************/ | ||
package org.cloudfoundry.identity.uaa.scim.endpoints; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import java.net.URL; | ||
public class VerificationResponse { | ||
@JsonProperty(value="verify_link") | ||
private URL verifyLink; | ||
|
||
public URL getVerifyLink() { | ||
return verifyLink; | ||
} | ||
|
||
public void setVerifyLink(URL verifyLink) { | ||
this.verifyLink = verifyLink; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
.../main/java/org/cloudfoundry/identity/uaa/scim/exception/UserAlreadyVerifiedException.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,24 @@ | ||
package org.cloudfoundry.identity.uaa.scim.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
/******************************************************************************* | ||
* Cloud Foundry | ||
* Copyright (c) [2009-2015] Pivotal Software, Inc. All Rights Reserved. | ||
* <p> | ||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this product except in compliance with the License. | ||
* <p> | ||
* This product includes a number of subcomponents with | ||
* separate copyright notices and license terms. Your use of these | ||
* subcomponents is subject to the terms and conditions of the | ||
* subcomponent's license, as noted in the LICENSE file. | ||
*******************************************************************************/ | ||
public class UserAlreadyVerifiedException extends ScimException { | ||
|
||
public static final String DESC = "This user has already been verified."; | ||
|
||
public UserAlreadyVerifiedException() { | ||
super(DESC, HttpStatus.METHOD_NOT_ALLOWED); | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
scim/src/main/java/org/cloudfoundry/identity/uaa/scim/util/ScimUtils.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,104 @@ | ||
package org.cloudfoundry.identity.uaa.scim.util; | ||
|
||
import org.cloudfoundry.identity.uaa.codestore.ExpiringCode; | ||
import org.cloudfoundry.identity.uaa.codestore.ExpiringCodeStore; | ||
import org.cloudfoundry.identity.uaa.util.JsonUtils; | ||
import org.cloudfoundry.identity.uaa.util.UaaUrlUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.util.Assert; | ||
|
||
import java.io.IOException; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.sql.Timestamp; | ||
import java.util.HashMap; | ||
import java.util.IllegalFormatCodePointException; | ||
import java.util.Map; | ||
|
||
/******************************************************************************* | ||
* Cloud Foundry | ||
* Copyright (c) [2009-2015] Pivotal Software, Inc. All Rights Reserved. | ||
* <p> | ||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this product except in compliance with the License. | ||
* <p> | ||
* This product includes a number of subcomponents with | ||
* separate copyright notices and license terms. Your use of these | ||
* subcomponents is subject to the terms and conditions of the | ||
* subcomponent's license, as noted in the LICENSE file. | ||
*******************************************************************************/ | ||
public final class ScimUtils { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(ScimUtils.class); | ||
|
||
private ScimUtils() {} | ||
|
||
/** | ||
* Generates a 1 hour expiring code. This code is revokable using {@link ExpiringCodeStore#retrieveLatest(String, String)}. | ||
* | ||
* @param codeStore | ||
* the code store to use, must not be null | ||
* @param userId | ||
* the user id that will be included in the code's data, must not be null | ||
* @param email | ||
* the email that will be included in the code's data, must not be null | ||
* @param clientId | ||
* client id that will be included in the code's data, must not be null | ||
* @param redirectUri | ||
* the redirect uri that will be included in the code's data, may be null | ||
* @return | ||
* the expiring code | ||
*/ | ||
public static ExpiringCode getExpiringCode(ExpiringCodeStore codeStore, String userId, String email, String clientId, String redirectUri) { | ||
Assert.notNull(codeStore); | ||
Assert.notNull(userId); | ||
Assert.notNull(email); | ||
|
||
Map<String, String> codeData = new HashMap<>(); | ||
codeData.put("user_id", userId); | ||
codeData.put("email", email); | ||
codeData.put("client_id", clientId); | ||
if (redirectUri != null) { | ||
codeData.put("redirect_uri", redirectUri); | ||
} | ||
String codeDataString = JsonUtils.writeValueAsString(codeData); | ||
|
||
Timestamp expiresAt = new Timestamp(System.currentTimeMillis() + (60 * 60 * 1000)); // 1 hour | ||
return codeStore.generateCode(codeDataString, expiresAt); | ||
} | ||
|
||
/** | ||
* Returns a verification URL that may be sent to a user. | ||
* | ||
* @param expiringCode | ||
* the expiring code to include on the URL, may be null | ||
* @param email | ||
* the email to include on the URL, may be null | ||
* @return | ||
* the verification URL | ||
*/ | ||
public static URL getVerificationURL(ExpiringCode expiringCode, String email) { | ||
String url = ""; | ||
try { | ||
url = UaaUrlUtils.getUaaUrl("/verify_user"); | ||
|
||
if (expiringCode != null) { | ||
url += "?code=" + expiringCode.getCode(); | ||
} | ||
|
||
if (email != null) { | ||
if (expiringCode != null) { | ||
url += "&email=" + email; | ||
} else { | ||
url += "?email=" + email; | ||
} | ||
} | ||
|
||
return new URL(url); | ||
} catch (MalformedURLException mfue) { | ||
logger.error(String.format("Unexpected error creating user verification URL from %s", url), mfue); | ||
} | ||
throw new IllegalStateException(); | ||
} | ||
} |
Oops, something went wrong.