Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
issue-1257 adding organizationNameKey support on /oauth/token post
  • Loading branch information
pmiller7 committed Jan 31, 2017
commit be843bc3cdbd29b538aa00812a37977c0476f4e6
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ public interface OAuthPasswordGrantRequestAuthentication extends OAuthGrantReque
*/
AccountStore getAccountStore();

/**
* Returns the specific organizationNameKey where the provided credentials will be sought in order to authenticate a request.
*
* @return the specific organizationNameKey where the provided credentials will be sought in order to authenticate a request.
*/
String getOrganizationNameKey();

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,12 @@ public interface OAuthPasswordGrantRequestAuthenticationBuilder extends OAuthReq
* @return this instance for method chaining.
*/
OAuthPasswordGrantRequestAuthenticationBuilder setAccountStore(AccountStore accountStore);

/**
* Specifies the target Organization via nameKey to be used for the authentication token creation.
*
* @param organizationNameKey the sole specific nameKey of the {@link com.stormpath.sdk.organization.Organization organization} where the provided credentials will be sought in order to authenticate this request.
* @return this instance for method chaining.
*/
OAuthPasswordGrantRequestAuthenticationBuilder setOrganizationNameKey(String organizationNameKey);
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public OAuthPasswordGrantRequestAuthentication createAccessTokenAuthenticationRe
requestBuilder.setAccountStore(accountStore);
}

if (request.getParameter("organizationNameKey") != null) {
requestBuilder.setOrganizationNameKey(request.getParameter("organizationNameKey"));
}

return requestBuilder.build();
} catch (Exception e){
throw new OAuthException(OAuthErrorCode.INVALID_REQUEST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.stormpath.sdk.application.webconfig.ApplicationWebConfig;
import com.stormpath.sdk.application.webconfig.ApplicationWebConfigStatus;
import com.stormpath.sdk.directory.AccountStore;
import com.stormpath.sdk.directory.AccountStoreVisitor;
import com.stormpath.sdk.directory.AccountStoreVisitorAdapter;
import com.stormpath.sdk.directory.Directory;
import com.stormpath.sdk.group.Group;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ public class DefaultOAuthPasswordGrantAuthenticationAttempt extends AbstractReso
static final StringProperty LOGIN = new StringProperty("username");
static final StringProperty PASSWORD = new StringProperty("password");
static final StringProperty ACCOUNT_STORE_HREF = new StringProperty("accountStore");
static final StringProperty ORGANIZATION_NAME_KEY = new StringProperty("organizationNameKey");
static final StringProperty GRANT_TYPE = new StringProperty("grant_type");

private static final Map<String, Property> PROPERTY_DESCRIPTORS = createPropertyDescriptorMap(LOGIN, PASSWORD, ACCOUNT_STORE_HREF, GRANT_TYPE);
private static final Map<String, Property> PROPERTY_DESCRIPTORS = createPropertyDescriptorMap(LOGIN, PASSWORD, ACCOUNT_STORE_HREF, ORGANIZATION_NAME_KEY, GRANT_TYPE);

public DefaultOAuthPasswordGrantAuthenticationAttempt(InternalDataStore dataStore) {
super(dataStore);
Expand All @@ -58,6 +59,11 @@ public void setAccountStore(AccountStore value) {
setProperty(ACCOUNT_STORE_HREF, value.getHref());
}

@Override
public void setOrganizationNameKey(String organizationNameKey) {
setProperty(ORGANIZATION_NAME_KEY, organizationNameKey);
}

public String getLogin() {
return getString(LOGIN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class DefaultOAuthPasswordGrantRequestAuthentication implements OAuthPass
private final String login;
private final String password;
private AccountStore accountStore;
private String organizationNameKey;
private final static String grant_type = "password";

public DefaultOAuthPasswordGrantRequestAuthentication(String login, String password) {
Expand All @@ -42,6 +43,11 @@ public OAuthPasswordGrantRequestAuthentication setAccountStore(AccountStore acco
return this;
}

public OAuthPasswordGrantRequestAuthentication setOrganizationNameKey(String organizationNameKey) {
this.organizationNameKey = organizationNameKey;
return this;
}

@Override
public String getPassword() {
return password;
Expand All @@ -57,6 +63,10 @@ public AccountStore getAccountStore() {
return accountStore;
}

public String getOrganizationNameKey() {
return organizationNameKey;
}

@Override
public String getGrantType() {
return grant_type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class DefaultOAuthPasswordGrantRequestAuthenticationBuilder implements OA
private String login;
private String password;
private AccountStore accountStore;
private String organizationNameKey;

@Override
public OAuthPasswordGrantRequestAuthenticationBuilder setLogin(String login) {
Expand All @@ -50,17 +51,31 @@ public OAuthPasswordGrantRequestAuthenticationBuilder setAccountStore(AccountSto
return this;
}

@Override
public OAuthPasswordGrantRequestAuthenticationBuilder setOrganizationNameKey(String organizationNameKey) {
Assert.hasText(organizationNameKey, "organizationNameKey cannot be null or empty.");
this.organizationNameKey = organizationNameKey;
return this;
}

@Override
public OAuthPasswordGrantRequestAuthentication build() {
Assert.state(this.login != null, "login has not been set. It is a required attribute.");
Assert.state(this.password != null, "password has not been set. It is a required attribute.");

DefaultOAuthPasswordGrantRequestAuthentication request = new DefaultOAuthPasswordGrantRequestAuthentication(login, password);

Assert.isTrue((this.accountStore == null && this.organizationNameKey == null) ||
this.accountStore != null ^ this.organizationNameKey != null, "only set accountStore or organizationNameKey or neither");

if (this.accountStore != null) {
request.setAccountStore(this.accountStore);
}

if (this.organizationNameKey != null) {
request.setOrganizationNameKey(this.organizationNameKey);
}

return request;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public OAuthGrantRequestAuthenticationResult authenticate(OAuthRequestAuthentica
if (oauthPasswordGrantRequestAuthentication.getAccountStore() != null){
oauthPasswordGrantAuthenticationAttempt.setAccountStore(oauthPasswordGrantRequestAuthentication.getAccountStore());
}
if (oauthPasswordGrantRequestAuthentication.getOrganizationNameKey() != null) {
oauthPasswordGrantAuthenticationAttempt.setOrganizationNameKey(oauthPasswordGrantRequestAuthentication.getOrganizationNameKey());
}

HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public interface OAuthPasswordGrantAuthenticationAttempt extends Resource {
*/
void setAccountStore(AccountStore accountStore);

/**
* Method used to set the organizationNameKey object that will be used for the token exchange request.
* @param organizationNameKey the organizationNameKey that will be used for the token exchange request.
*/
void setOrganizationNameKey(String organizationNameKey);

/**
* Method used to set the Authentication Grant Type that will be used for the token exchange request. Currently only "password" grant type is supported for this operation.
* @param grantType the Authentication Grant Type that will be used for the token exchange request.
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.