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

Commit c3289e4

Browse files
committed
1137 - refactor class hierachy to collate common code for mapping rules for SAML, social provider
1 parent 7045051 commit c3289e4

File tree

8 files changed

+95
-176
lines changed

8 files changed

+95
-176
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.stormpath.sdk.provider;
2+
3+
import java.util.Set;
4+
5+
/**
6+
* @since 1.3.0
7+
*/
8+
public interface MappingRule {
9+
10+
/**
11+
* Returns the attribute name for a Social Provider or SAML Provider, that when encountered, should have its value
12+
* applied as Account field values.
13+
* When this name is encountered when processing UserInfo from a Social Provider or SAML Attribute Statement,
14+
* its associated value will be set as the value for all Stormpath Account field names specified in the
15+
* {@link #getAccountAttributes() accountAttributes} collection.
16+
*
17+
* @return attribute name, that when encountered, should have its value set on the
18+
* {@link #getAccountAttributes() specified} Account fields.
19+
*/
20+
String getName();
21+
22+
/**
23+
* Returns the Stormpath account fields that should be updated when encountering {@link #getName() named}
24+
* attribute name. If discovered, that attribute value will be set on all of the Stormpath account
25+
* fields named in this collection.
26+
*
27+
* @return the Stormpath account fields that should be updated when encountering {@link #getName() named}
28+
* attribute name.
29+
*/
30+
Set<String> getAccountAttributes();
31+
}
Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.stormpath.sdk.provider.social;
22

3-
import java.util.Set;
3+
import com.stormpath.sdk.provider.MappingRule;
44

55
/**
66
* A rule that indicates how a userInfo attribute from a Social Provider should populate one or more Stormpath Account field values. By
@@ -25,27 +25,6 @@
2525
*
2626
* @since 1.3.0
2727
*/
28-
public interface UserInfoMappingRule {
28+
public interface UserInfoMappingRule extends MappingRule {
2929

30-
/**
31-
* Returns the UserInfo attribute name for a Social Provider, that when encountered, should have its value applied
32-
* as Account field values.
33-
* When this name is encountered when processing UserInfo from a Social Provider, its associated value will be set
34-
* as the value for all Stormpath Account field names specified in the
35-
* {@link #getAccountAttributes() accountAttributes} collection.
36-
*
37-
* @return UserInfo attribute name, that when encountered, should have its value set on the
38-
* {@link #getAccountAttributes() specified} Account fields.
39-
*/
40-
String getName();
41-
42-
/**
43-
* Returns the Stormpath account fields that should be updated when encountering {@link #getName() named}
44-
* UserInfo attribute name. If discovered, that UserInfo attribute value will be set on all of the Stormpath account
45-
* fields named in this collection.
46-
*
47-
* @return the Stormpath account fields that should be updated when encountering {@link #getName() named}
48-
* UserInfo attribute name.
49-
*/
50-
Set<String> getAccountAttributes();
5130
}

api/src/main/java/com/stormpath/sdk/provider/social/UserInfoMappingRuleBuilder.java

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.stormpath.sdk.provider.social;
1717

18-
import java.util.Set;
18+
import com.stormpath.sdk.provider.MappingRuleBuilder;
1919

2020
/**
2121
* A Builder to construct {@link UserInfoMappingRule} resources.
@@ -30,42 +30,6 @@
3030
*
3131
* @since 1.3.0
3232
*/
33-
public interface UserInfoMappingRuleBuilder {
33+
public interface UserInfoMappingRuleBuilder extends MappingRuleBuilder {
3434

35-
/**
36-
* Sets the UserInfo attribute name, that when encountered, should have its value applied as Account field values.
37-
* When this name is encountered when processing UserInfo from a Social Provider, 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 UserInfo 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 UserInfo 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 UserInfo 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();
7135
}

api/src/main/java/com/stormpath/sdk/saml/AttributeStatementMappingRule.java

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.stormpath.sdk.saml;
1717

18-
import java.util.Set;
18+
import com.stormpath.sdk.provider.MappingRule;
1919

2020
/**
2121
* A rule that indicates how a SAML Attribute Statement should populate one or more Stormpath Account field values. By
@@ -40,18 +40,7 @@
4040
*
4141
* @since 1.0.RC8
4242
*/
43-
public interface AttributeStatementMappingRule {
44-
45-
/**
46-
* Returns the SAML Attribute name, that when encountered, should have its value applied as Account field values.
47-
* When this name is encountered when processing a SAML Attribute Statement, its associated value will be set as the
48-
* value for all Stormpath Account field names specified in the
49-
* {@link #getAccountAttributes() accountAttributes} collection.
50-
*
51-
* @return SAML Attribute name, that when encountered, should have its value set on the
52-
* {@link #getAccountAttributes() specified} Account fields.
53-
*/
54-
String getName();
43+
public interface AttributeStatementMappingRule extends MappingRule {
5544

5645
/**
5746
* Returns the format for the SAML Attribute identified by {@link #getName() getName()}.
@@ -60,13 +49,4 @@ public interface AttributeStatementMappingRule {
6049
*/
6150
String getNameFormat();
6251

63-
/**
64-
* Returns the Stormpath account fields that should be updated when encountering {@link #getName() named}
65-
* SAML Attribute name. If discovered, that SAML Attribute value will be set on all of the Stormpath account
66-
* fields named in this collection.
67-
*
68-
* @return the Stormpath account fields that should be updated when encountering {@link #getName() named}
69-
* SAML Attribute name.
70-
*/
71-
Set<String> getAccountAttributes();
7252
}

api/src/main/java/com/stormpath/sdk/saml/AttributeStatementMappingRuleBuilder.java

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.stormpath.sdk.saml;
1717

18-
import java.util.Set;
18+
import com.stormpath.sdk.provider.MappingRuleBuilder;
1919

2020
/**
2121
* A Builder to construct {@link AttributeStatementMappingRule} resources.
@@ -30,17 +30,7 @@
3030
*
3131
* @since 1.0.RC8
3232
*/
33-
public interface AttributeStatementMappingRuleBuilder {
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 AttributeStatementMappingRule#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-
AttributeStatementMappingRuleBuilder setName(String name);
33+
public interface AttributeStatementMappingRuleBuilder extends MappingRuleBuilder {
4434

4535
/**
4636
* Sets the format for the SAML Attribute specified by {@link com.stormpath.sdk.saml.AttributeStatementMappingRule#getName() getName()}.
@@ -55,28 +45,4 @@ public interface AttributeStatementMappingRuleBuilder {
5545
*/
5646
AttributeStatementMappingRuleBuilder setNameFormat(String nameFormat);
5747

58-
/**
59-
* Sets the Stormpath account fields that should be updated when encountering {@link AttributeStatementMappingRule#getName() named}
60-
* SAML Attribute name. If discovered, that SAML Attribute value will be set on all of the Stormpath account
61-
* fields named in this collection.
62-
*
63-
* @param accountAttributes the account fields that should be updated when there's a match with SAML Attribute name.
64-
*/
65-
AttributeStatementMappingRuleBuilder setAccountAttributes(String... accountAttributes);
66-
67-
/**
68-
* Sets the Stormpath account fields that should be updated when encountering {@link AttributeStatementMappingRule#getName() named}
69-
* SAML Attribute name. If discovered, that SAML Attribute value will be set on all of the Stormpath account
70-
* fields named in this collection.
71-
*
72-
* @param accountAttributes the account fields that should be updated when there's a match with SAML Attribute name.
73-
*/
74-
AttributeStatementMappingRuleBuilder setAccountAttributes(Set<String> accountAttributes);
75-
76-
/**
77-
* Builds a new {@link AttributeStatementMappingRule} based on the current state of this builder.
78-
*
79-
* @return a new {@link AttributeStatementMappingRule} to be included in the {@link AttributeStatementMappingRules} for a Saml Provider.
80-
*/
81-
AttributeStatementMappingRule build();
8248
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.stormpath.sdk.impl.provider;
2+
3+
import com.stormpath.sdk.lang.Assert;
4+
import com.stormpath.sdk.provider.MappingRule;
5+
import com.stormpath.sdk.provider.MappingRuleBuilder;
6+
7+
import java.util.LinkedHashSet;
8+
import java.util.Set;
9+
10+
/**
11+
* @since 1.3.0
12+
*/
13+
public abstract class AbstractMappingRuleBuilder implements MappingRuleBuilder {
14+
15+
protected String name;
16+
protected Set<String> accountAttributes;
17+
18+
@Override
19+
public MappingRuleBuilder setName(String name) {
20+
Assert.hasText(name, "name argument cannot be null or empty.");
21+
this.name = name;
22+
return this;
23+
}
24+
25+
@Override
26+
public MappingRuleBuilder setAccountAttributes(String... accountAttributes) {
27+
Assert.notEmpty(accountAttributes, "accountAttributes cannot be null or empty.");
28+
29+
Set<String> names = new LinkedHashSet<String>(accountAttributes.length);
30+
for (String attrName : accountAttributes) {
31+
Assert.hasText("individual accountAttributes cannot be null or empty.");
32+
names.add(attrName);
33+
}
34+
this.accountAttributes = names;
35+
return this;
36+
}
37+
38+
@Override
39+
public MappingRuleBuilder setAccountAttributes(Set<String> accountAttributes) {
40+
Assert.notEmpty(accountAttributes, "accountAttributes cannot be null or empty.");
41+
42+
this.accountAttributes = accountAttributes;
43+
return this;
44+
}
45+
46+
public abstract MappingRule build();
47+
}

impl/src/main/java/com/stormpath/sdk/impl/provider/social/DefaultUserInfoMappingRuleBuilder.java

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,47 +15,19 @@
1515
*/
1616
package com.stormpath.sdk.impl.provider.social;
1717

18+
import com.stormpath.sdk.impl.provider.AbstractMappingRuleBuilder;
1819
import com.stormpath.sdk.lang.Assert;
19-
import com.stormpath.sdk.provider.social.UserInfoMappingRule;
20+
import com.stormpath.sdk.provider.MappingRule;
2021
import com.stormpath.sdk.provider.social.UserInfoMappingRuleBuilder;
2122

22-
import java.util.LinkedHashSet;
23-
import java.util.Set;
24-
2523
/**
2624
* @since 1.3.0
2725
*/
28-
public class DefaultUserInfoMappingRuleBuilder implements UserInfoMappingRuleBuilder {
29-
30-
private String name;
31-
private Set<String> accountAttributes;
32-
33-
public UserInfoMappingRuleBuilder setName(String name){
34-
Assert.hasText(name, "name argument cannot be null or empty.");
35-
this.name = name;
36-
return this;
37-
}
38-
39-
public UserInfoMappingRuleBuilder setAccountAttributes(String... accountAttributes){
40-
Assert.notEmpty(accountAttributes, "accountAttributes cannot be null or empty.");
41-
42-
Set<String> names = new LinkedHashSet<String>(accountAttributes.length);
43-
for (String attrName : accountAttributes) {
44-
Assert.hasText("individual accountAttributes cannot be null or empty.");
45-
names.add(attrName);
46-
}
47-
this.accountAttributes = names;
48-
return this;
49-
}
26+
public class DefaultUserInfoMappingRuleBuilder extends AbstractMappingRuleBuilder implements UserInfoMappingRuleBuilder {
5027

51-
public UserInfoMappingRuleBuilder setAccountAttributes(Set<String> accountAttributes){
52-
Assert.notEmpty(accountAttributes, "accountAttributes cannot be null or empty.");
53-
54-
this.accountAttributes = accountAttributes;
55-
return this;
56-
}
28+
@Override
29+
public MappingRule build() {
5730

58-
public UserInfoMappingRule build(){
5931
Assert.hasText(name, "name argument cannot be null or empty.");
6032
Assert.notEmpty(accountAttributes, "accountAttributes cannot be null or empty.");
6133

impl/src/main/java/com/stormpath/sdk/impl/saml/DefaultAttributeStatementMappingRuleBuilder.java

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,55 +15,35 @@
1515
*/
1616
package com.stormpath.sdk.impl.saml;
1717

18+
import com.stormpath.sdk.impl.provider.AbstractMappingRuleBuilder;
1819
import com.stormpath.sdk.lang.Assert;
20+
import com.stormpath.sdk.provider.MappingRule;
1921
import com.stormpath.sdk.saml.AttributeStatementMappingRuleBuilder;
20-
import com.stormpath.sdk.saml.AttributeStatementMappingRule;
2122

22-
import java.util.LinkedHashSet;
2323
import java.util.Set;
2424

2525
/**
2626
* @since 1.0.RC8
2727
*/
28-
public class DefaultAttributeStatementMappingRuleBuilder implements AttributeStatementMappingRuleBuilder {
28+
public class DefaultAttributeStatementMappingRuleBuilder extends AbstractMappingRuleBuilder implements AttributeStatementMappingRuleBuilder {
2929

30-
private String name;
31-
private Set<String> accountAttributes;
3230
private String nameFormat;
3331

34-
public AttributeStatementMappingRuleBuilder setName(String name){
35-
Assert.hasText(name, "name argument cannot be null or empty.");
36-
this.name = name;
37-
return this;
38-
}
39-
4032
@Override
4133
public AttributeStatementMappingRuleBuilder setNameFormat(String nameFormat) {
4234
Assert.hasText(nameFormat, "nameFormat argument cannot be null or empty.");
4335
this.nameFormat = nameFormat;
4436
return this;
4537
}
4638

47-
public AttributeStatementMappingRuleBuilder setAccountAttributes(String... accountAttributes){
48-
Assert.notEmpty(accountAttributes, "accountAttributes cannot be null or empty.");
49-
50-
Set<String> names = new LinkedHashSet<String>(accountAttributes.length);
51-
for (String attrName : accountAttributes) {
52-
Assert.hasText("individual accountAttributes cannot be null or empty.");
53-
names.add(attrName);
54-
}
55-
this.accountAttributes = names;
56-
return this;
57-
}
58-
5939
public AttributeStatementMappingRuleBuilder setAccountAttributes(Set<String> accountAttributes){
6040
Assert.notEmpty(accountAttributes, "accountAttributes cannot be null or empty.");
6141

6242
this.accountAttributes = accountAttributes;
6343
return this;
6444
}
6545

66-
public AttributeStatementMappingRule build(){
46+
public MappingRule build(){
6747
Assert.hasText(name, "name argument cannot be null or empty.");
6848
Assert.notEmpty(accountAttributes, "accountAttributes cannot be null or empty.");
6949

0 commit comments

Comments
 (0)