Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RHSSO-130: AccessTokenTest migration
- Loading branch information
Bruno Oliveira
committed
Apr 22, 2016
1 parent
2047363
commit 1cc4ca2
Showing
9 changed files
with
521 additions
and
379 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
684 changes: 318 additions & 366 deletions
684
...loak/testsuite/oauth/AccessTokenTest.java → ...loak/testsuite/oauth/AccessTokenTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
93 changes: 93 additions & 0 deletions
93
...n-arquillian/tests/base/src/test/java/org/keycloak/testsuite/util/ProtocolMapperUtil.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,93 @@ | |||
package org.keycloak.testsuite.util; | |||
|
|||
import org.keycloak.models.utils.ModelToRepresentation; | |||
import org.keycloak.protocol.oidc.mappers.AddressMapper; | |||
import org.keycloak.protocol.oidc.mappers.HardcodedClaim; | |||
import org.keycloak.protocol.oidc.mappers.HardcodedRole; | |||
import org.keycloak.protocol.oidc.mappers.RoleNameMapper; | |||
import org.keycloak.protocol.oidc.mappers.UserAttributeMapper; | |||
import org.keycloak.representations.idm.ProtocolMapperRepresentation; | |||
|
|||
/** | |||
* @author <a href="mailto:bruno@abstractj.org">Bruno Oliveira</a>. | |||
*/ | |||
public class ProtocolMapperUtil { | |||
|
|||
/** | |||
* This is the migration of the method present at RoleNameMapper | |||
* | |||
* @param name | |||
* @param role | |||
* @param newName | |||
* @return | |||
*/ | |||
public static ProtocolMapperRepresentation createRoleNameMapper(String name, | |||
String role, | |||
String newName) { | |||
return ModelToRepresentation.toRepresentation(RoleNameMapper.create(name, role, newName)); | |||
|
|||
} | |||
|
|||
public static ProtocolMapperRepresentation createHardcodedRole(String name, | |||
String role) { | |||
return ModelToRepresentation.toRepresentation(HardcodedRole.create(name, role)); | |||
} | |||
|
|||
/** | |||
* This is the migration of the method present at AddressMapper | |||
* | |||
* @param idToken | |||
* @param accessToken | |||
* @return | |||
*/ | |||
public static ProtocolMapperRepresentation createAddressMapper(boolean idToken, boolean accessToken) { | |||
return ModelToRepresentation.toRepresentation(AddressMapper.createAddressMapper(idToken, accessToken)); | |||
} | |||
|
|||
/** | |||
* This is the migration of the method present at HardcodedClaim | |||
* | |||
* @param name | |||
* @param hardcodedName | |||
* @param hardcodedValue | |||
* @param claimType | |||
* @param consentRequired | |||
* @param consentText | |||
* @param accessToken | |||
* @param idToken | |||
* @return | |||
*/ | |||
public static ProtocolMapperRepresentation createHardcodedClaim(String name, | |||
String hardcodedName, | |||
String hardcodedValue, String claimType, | |||
boolean consentRequired, String consentText, | |||
boolean accessToken, boolean idToken) { | |||
return ModelToRepresentation.toRepresentation(HardcodedClaim.create(name, hardcodedName, hardcodedValue, | |||
claimType, consentRequired, consentText, accessToken, idToken)); | |||
} | |||
|
|||
/** | |||
* Migrated from UserAttributeMapper | |||
* | |||
* @param name | |||
* @param userAttribute | |||
* @param tokenClaimName | |||
* @param claimType | |||
* @param consentRequired | |||
* @param consentText | |||
* @param accessToken | |||
* @param idToken | |||
* @param multivalued | |||
* @return | |||
*/ | |||
public static ProtocolMapperRepresentation createClaimMapper(String name, | |||
String userAttribute, | |||
String tokenClaimName, String claimType, | |||
boolean consentRequired, String consentText, | |||
boolean accessToken, boolean idToken, boolean multivalued) { | |||
return ModelToRepresentation.toRepresentation(UserAttributeMapper.createClaimMapper(name, userAttribute, tokenClaimName, | |||
claimType, consentRequired, consentText, accessToken, idToken, multivalued)); | |||
|
|||
} | |||
|
|||
} |
26 changes: 26 additions & 0 deletions
26
...gration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/util/RealmManager.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,26 @@ | |||
package org.keycloak.testsuite.util; | |||
|
|||
import org.keycloak.admin.client.resource.RealmResource; | |||
import org.keycloak.representations.idm.RealmRepresentation; | |||
|
|||
/** | |||
* @author <a href="mailto:bruno@abstractj.org">Bruno Oliveira</a>. | |||
*/ | |||
public class RealmManager { | |||
|
|||
private static RealmResource realm; | |||
|
|||
private RealmManager() { | |||
} | |||
|
|||
public static RealmManager realm(RealmResource realm) { | |||
RealmManager.realm = realm; | |||
return new RealmManager(); | |||
} | |||
|
|||
public void accessCodeLifeSpan(Integer accessCodeLifespan) { | |||
RealmRepresentation realmRepresentation = realm.toRepresentation(); | |||
realmRepresentation.setAccessCodeLifespan(accessCodeLifespan); | |||
realm.update(realmRepresentation); | |||
} | |||
} |
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
74 changes: 74 additions & 0 deletions
74
...egration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/util/UserManager.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,74 @@ | |||
package org.keycloak.testsuite.util; | |||
|
|||
import org.keycloak.admin.client.resource.RealmResource; | |||
import org.keycloak.admin.client.resource.UserResource; | |||
import org.keycloak.representations.idm.UserRepresentation; | |||
|
|||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
|
|||
import static org.keycloak.testsuite.admin.ApiUtil.findUserByUsernameId; | |||
|
|||
/** | |||
* @author <a href="mailto:bruno@abstractj.org">Bruno Oliveira</a>. | |||
*/ | |||
public class UserManager { | |||
|
|||
private static RealmResource realm; | |||
|
|||
private UserManager() { | |||
} | |||
|
|||
public static UserManager realm(RealmResource realm) { | |||
UserManager.realm = realm; | |||
return new UserManager(); | |||
} | |||
|
|||
public UserManagerBuilder username(String username) { | |||
return new UserManagerBuilder(findUserByUsernameId(realm, username)); | |||
} | |||
|
|||
public UserManagerBuilder user(UserResource user) { | |||
return new UserManagerBuilder(user); | |||
} | |||
|
|||
public class UserManagerBuilder { | |||
|
|||
private final UserResource userResource; | |||
|
|||
public UserManagerBuilder(UserResource userResource) { | |||
this.userResource = userResource; | |||
} | |||
|
|||
public void removeRequiredAction(String action) { | |||
UserRepresentation user = initializeRequiredActions(); | |||
user.getRequiredActions().remove(action); | |||
userResource.update(user); | |||
} | |||
|
|||
public void addRequiredAction(String... actions) { | |||
UserRepresentation user = initializeRequiredActions(); | |||
user.setRequiredActions(Arrays.asList(actions)); | |||
userResource.update(user); | |||
} | |||
|
|||
public void assignRoles(String... roles) { | |||
UserRepresentation user = userResource.toRepresentation(); | |||
if (user != null && user.getRealmRoles() == null) { | |||
user.setRealmRoles(new ArrayList<String>()); | |||
} | |||
user.setRealmRoles(Arrays.asList(roles)); | |||
userResource.update(user); | |||
} | |||
|
|||
|
|||
private UserRepresentation initializeRequiredActions() { | |||
UserRepresentation user = userResource.toRepresentation(); | |||
if (user != null && user.getRequiredActions() == null) { | |||
user.setRequiredActions(new ArrayList<String>()); | |||
} | |||
return user; | |||
} | |||
|
|||
} | |||
} |