Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.

Commit a11ce1b

Browse files
committed
AM-3581 - social login v2 - JSDK effort #1137 - issue 1137 - Social Provider - UserInfoAttributeMapping
1 parent c82ac67 commit a11ce1b

25 files changed

Lines changed: 685 additions & 46 deletions

api/src/main/java/com/stormpath/sdk/provider/CreateProviderRequestBuilder.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.stormpath.sdk.provider;
1717

18+
import com.stormpath.sdk.provider.social.UserInfoMappingRules;
19+
1820
/**
1921
* A Builder to construct {@link CreateProviderRequest}s.
2022
*
@@ -41,6 +43,17 @@ public interface CreateProviderRequestBuilder<T extends CreateProviderRequestBui
4143
*/
4244
T setClientSecret(String clientSecret);
4345

46+
/**
47+
* set rules for mapping fields from userInfo provided by the social provider to Stormpath Account attributes
48+
* for Accounts created in the associated Stormpath Directory.
49+
*
50+
* @param userInfoMappingRules rules for mapping fields from userInfo provided by the social provider to Stormpath
51+
* Account attributes.
52+
* @return the current builder instance for method chaining.
53+
* @since 1.3.0
54+
*/
55+
T setUserInfoMappingRules(UserInfoMappingRules userInfoMappingRules);
56+
4457
/**
4558
* Creates a new {@code CreateProviderRequest} instance based on the current builder state.
4659
*

api/src/main/java/com/stormpath/sdk/provider/OAuthProvider.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.stormpath.sdk.provider;
1717

18+
import com.stormpath.sdk.provider.social.UserInfoMappingRules;
19+
1820
import java.util.List;
1921

2022
/**
@@ -42,4 +44,11 @@ public interface OAuthProvider extends Provider {
4244
* @since 1.2.0
4345
*/
4446
List<String> getScope();
47+
48+
/**
49+
* Returns the userInfoMappingRules configured for the oauth provider
50+
* @return the userInfoMappingRules configured for the oauth provider
51+
* @since 1.3.0
52+
*/
53+
UserInfoMappingRules getUserInfoMappingRules();
4554
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2015 Stormpath, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.stormpath.sdk.provider.social;
17+
18+
import com.stormpath.sdk.lang.Classes;
19+
20+
/**
21+
* Static utility/helper methods for working with userInfo from Social Provider related resources.
22+
* Most methods are <a href="http://en.wikipedia.org/wiki/Factory_method_pattern">factory method</a>s used for
23+
* creating {@link UserInfoMappingRule} and {@link UserInfoMappingRules} entities.
24+
*
25+
* @since 1.3.0
26+
*/
27+
public final class SocialUserInfoMappingRules {
28+
29+
/**
30+
* Returns a new {@link UserInfoMappingRuleBuilder} instance, used to construct {@link UserInfoMappingRule} objects,
31+
* to be added to the {@link UserInfoMappingRules#getItems() getItems()} collection of {@link UserInfoMappingRules} class.
32+
*
33+
* @return a new {@link UserInfoMappingRuleBuilder} instance, used to construct {@link UserInfoMappingRule} objects.
34+
*/
35+
public static UserInfoMappingRuleBuilder ruleBuilder() {
36+
return (UserInfoMappingRuleBuilder) Classes.newInstance("com.stormpath.sdk.impl.provider.social.DefaultUserInfoMappingRuleBuilder");
37+
}
38+
39+
/**
40+
* Returns a new {@link UserInfoMappingRulesBuilder} instance, used to construct {@link UserInfoMappingRules},
41+
* to be added to the {@link com.stormpath.sdk.provider.OAuthProvider} entity, for example, when creating a new Social Directory.
42+
*
43+
* @return a new {@link UserInfoMappingRulesBuilder} instance, used to construct {@link UserInfoMappingRules}.
44+
*/
45+
public static UserInfoMappingRulesBuilder rulesBuilder() {
46+
return (UserInfoMappingRulesBuilder) Classes.newInstance("com.stormpath.sdk.impl.provider.social.DefaultUserInfoMappingRulesBuilder");
47+
}
48+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2015 Stormpath, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.stormpath.sdk.provider.social;
17+
18+
import java.util.Set;
19+
20+
/**
21+
* A Builder to construct {@link UserInfoMappingRule} resources.
22+
* Usage Example:
23+
*
24+
* UserInfoMappingRule rule = SocialUserInfoMappingRule.ruleBuilder()
25+
* .setName("name")
26+
* .setAccountAttributes("field1", "field2")
27+
* .build();
28+
*
29+
* @see UserInfoMappingRule
30+
*
31+
* @since 1.3.0
32+
*/
33+
public interface UserInfoMappingRuleBuilder {
34+
35+
/**
36+
* Sets the SAML Attribute name, that when encountered, should have its value applied as Account field values.
37+
* When this name is encountered when processing a SAML Attribute Statement, its associated value will be set as the
38+
* value for all Stormpath Account field names specified in the
39+
* {@link UserInfoMappingRule#getAccountAttributes() accountAttributes} collection.
40+
*
41+
* @param name the SAML Attribute name that when encountered, should have its value applied as Account field values.
42+
*/
43+
UserInfoMappingRuleBuilder setName(String name);
44+
45+
/**
46+
* Sets the Stormpath account fields that should be updated when encountering {@link UserInfoMappingRule#getName() named}
47+
* field from the userInfo provided by the social provider. If discovered, that SAML Attribute value will be set on
48+
* all of the Stormpath account fields named in this collection.
49+
*
50+
* @param accountAttributes the account fields that should be updated when there's a match with a field name in userInfo
51+
* provided by the social provider.
52+
*/
53+
UserInfoMappingRuleBuilder setAccountAttributes(String... accountAttributes);
54+
55+
/**
56+
* Sets the Stormpath account fields that should be updated when encountering {@link UserInfoMappingRule#getName() named}
57+
* field from the userInfo provided by the social provider. If discovered, that SAML Attribute value will be set on
58+
* all of the Stormpath account fields named in this collection.
59+
*
60+
* @param accountAttributes the account fields that should be updated when there's a match with a field name in userInfo
61+
* provided by the social provider.
62+
*/
63+
UserInfoMappingRuleBuilder setAccountAttributes(Set<String> accountAttributes);
64+
65+
/**
66+
* Builds a new {@link UserInfoMappingRule} based on the current state of this builder.
67+
*
68+
* @return a new {@link UserInfoMappingRule} to be included in the {@link UserInfoMappingRules} for a Social Provider.
69+
*/
70+
UserInfoMappingRule build();
71+
}
Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,32 @@
11
package com.stormpath.sdk.provider.social;
22

33

4+
import com.stormpath.sdk.resource.Auditable;
45
import com.stormpath.sdk.resource.Resource;
6+
import com.stormpath.sdk.resource.Saveable;
57

6-
import java.util.Set;
8+
import java.util.List;
79

8-
public interface UserInfoMappingRules extends Resource, Set<UserInfoMappingRule> {
9-
10-
/**
11-
* Removes the {@link UserInfoMappingRule}(s) identified by {@code ruleNames}.
12-
*
13-
* @param ruleNames the name of the {@link UserInfoMappingRule}(s) to remove.
14-
*
15-
* @return the {@code Set<AttributeStatementMappingRule>} after the "remove" operation is performed.
16-
*/
17-
Set<UserInfoMappingRule> removeByName(String... ruleNames);
10+
public interface UserInfoMappingRules extends Resource, Saveable, Auditable {
1811

1912
/**
2013
* Specifies the Set of all {@link UserInfoMappingRule}s that indicate how SAML Attribute Statements should
2114
* populate one or more Stormpath Account field values after a successful SAML login.
2215
*
23-
* @param attributeStatementMappingRules the set of {@link UserInfoMappingRule AttributeStatementMappingRule}s to build a SAML provider.
16+
* @param userInfoMappingRules the set of {@link UserInfoMappingRule userInfoMappingRules}s to build a Social provider.
2417
*
2518
* @return this instance for method chaining.
19+
* @since 1.3.0
2620
*/
27-
void setItems(Set<UserInfoMappingRule> attributeStatementMappingRules);
21+
void setItems(List<UserInfoMappingRule> userInfoMappingRules);
2822

2923
/**
3024
* Returns the Set of all {@link UserInfoMappingRule}s that indicate how SAML Attribute Statements should
3125
* populate one or more Stormpath Account field values after a successful SAML login.
3226
*
3327
* @return the Set of all {@link UserInfoMappingRule}s that indicate how SAML Attribute Statements should
3428
* populate one or more Stormpath Account field values after a successful SAML login.
29+
* @since 1.3.0
3530
*/
36-
Set<UserInfoMappingRule> getItems();
31+
List<UserInfoMappingRule> getItems();
3732
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2015 Stormpath, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.stormpath.sdk.provider.social;
17+
18+
/**
19+
* A Builder to construct {@link UserInfoMappingRulesBuilder} resources.
20+
* Use example:
21+
*
22+
* UserInfoMappingRulesBuilder userInfoMappingRulesBuilder = UserInfoMappingRulesBuilder.rulesBuilder()
23+
* .addUserInfoMappingRule(userInfoMappingRule1)
24+
* .addUserInfoMappingRule(userInfoMappingRule2)
25+
* ...
26+
* .build();
27+
*
28+
* @see UserInfoMappingRulesBuilder
29+
30+
* @since 1.3.0
31+
*/
32+
public interface UserInfoMappingRulesBuilder {
33+
/**
34+
* Adds a new {@link UserInfoMappingRule UserInfoMappingRule} to the set of {@link UserInfoMappingRule UserInfoMappingRule}s,
35+
* indicating how a fields from the userInfo provided by the social provider should populate one or more Stormpath Account
36+
* field values after a successful Social login.
37+
*
38+
* @param userInfoMappingRule the {@link UserInfoMappingRule UserInfoMappingRule} to add to the {@link UserInfoMappingRules UserInfoMappingRules} object.
39+
*
40+
* @return this instance for method chaining.
41+
*/
42+
UserInfoMappingRulesBuilder addUserInfoMappingRule(UserInfoMappingRule userInfoMappingRule);
43+
44+
/**
45+
* Builds a new {@link UserInfoMappingRules UserInfoMappingRules} instance based on the state of this builder.
46+
*
47+
* @return a new {@link UserInfoMappingRules UserInfoMappingRules} instance.
48+
*/
49+
UserInfoMappingRules build();
50+
}

0 commit comments

Comments
 (0)