8000 composite tests and fix distro by patriot1burke · Pull Request #191 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<dependency>
<groupId>net.iharder</groupId>
<artifactId>base64</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,9 @@ public Composites getComposites() {
public void setComposites(Composites composites) {
this.composites = composites;
}

@Override
public String toString() {
return name;
}
}
4 changes: 4 additions & 0 deletions distribution/modules/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
~ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-->

<module-def name="net.iharder.base64">
<maven-resource group="net.iharder" artifact="base64"/>
</module-def>

<module-def name="org.bouncycastle">
<maven-resource group="org.bouncycastle" artifact="bcprov-jdk16"/>
</module-def>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2010, Red Hat, Inc., and individual contributors
~ as indicated by the @author tags. See the copyright.txt file in the
~ distribution for a full listing of individual contributors.
~
~ This is free software; you can redistribute it and/or modify it
~ under the terms of the GNU Lesser General Public License as
~ published by the Free Software Foundation; either version 2.1 of
~ the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
~ Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public
~ License along with this software; if not, write to the Free
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->

<module xmlns="urn:jboss:module:1.1" name="net.iharder.base64">
<resources>
<!-- Insert resources here -->
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>

</module>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<module name="org.codehaus.jackson.jackson-mapper-asl"/>
<module name="org.codehaus.jackson.jackson-xc"/>
<module name="org.bouncycastle"/>
<module name="net.iharder.base64"/>
<module name="javax.api"/>
</dependencies>

Expand Down
4 changes: 4 additions & 0 deletions integration/as7-eap6/adapter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<artifactId>httpclient</artifactId>
<version>${keycloak.apache.httpcomponents.version}</version>
</dependency>
<dependency>
<groupId>net.iharder</groupId>
<artifactId>base64</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk16</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions integration/servlet-oauth-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
</dependency>
<dependency>
<groupId>net.iharder</groupId>
<artifactId>base64</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions integration/undertow/pom.xml
< BD0 td class="blob-code blob-code-inner blob-code-hunk">@@ -34,6 +34,10 @@
Original file line number Diff line number Diff line change
Expand Up
<artifactId>httpclient</artifactId>
<version>${keycloak.apache.httpcomponents.version}</version>
</dependency>
<dependency>
<groupId>net.iharder</groupId>
<artifactId>base64</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk16</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,8 @@ public boolean equals(Object o) {
ApplicationAdapter app = (ApplicationAdapter)o;
return app.getId().equals(getId());
}

public String toString() {
return getName();
}
}
4 changes: 4 additions & 0 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk16</artifactId>
</dependency>
<dependency>
<groupId>net.iharder</groupId>
<artifactId>base64</artifactId>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,6 @@ public void importRealm(RealmRepresentation rep, RealmModel newRealm) {
}
}

if (rep.getRoles() != null && rep.getRoles().getRealm() != null) {
for (RoleRepresentation roleRep : rep.getRoles().getRealm()) {
createRole(newRealm, roleRep);
}
}

if (rep.getRoles() != null) {
if (rep.getRoles().getRealm() != null) { // realm roles
for (RoleRepresentation roleRep : rep.getRoles().getRealm()) {
Expand All @@ -270,10 +264,11 @@ public void importRealm(RealmRepresentation rep, RealmModel newRealm) {
}
}
}
// now that all roles are created, re-interate and set up composites
// now that all roles are created, re-iterate and set up composites
if (rep.getRoles().getRealm() != null) { // realm roles
for (RoleRepresentation roleRep : rep.getRoles().getRealm()) {
createRole(newRealm, roleRep);
RoleModel role = newRealm.getRole(roleRep.getName());
addComposites(role, roleRep, newRealm);
}
}
if (rep.getRoles().getApplication() != null) {
Expand All @@ -283,9 +278,8 @@ public void importRealm(RealmRepresentation rep, RealmModel newRealm) {
throw new RuntimeException("App doesn't exist in role definitions: " + entry.getKey());
}
for (RoleRepresentation roleRep : entry.getValue()) {
RoleModel role = app.addRole(roleRep.getName());
role.setDescription(roleRep.getDescription());
role.setComposite(roleRep.isComposite());
RoleModel role = app.getRole(roleRep.getName());
addComposites(role, roleRep, newRealm);
}
}
}
Expand All @@ -298,27 +292,6 @@ public void importRealm(RealmRepresentation rep, RealmModel newRealm) {
}
}

if (rep.getRoles() != null) {
if (rep.getRoles().getRealm() != null) { // realm roles
for (RoleRepresentation roleRep : rep.getRoles().getRealm()) {
RoleModel role = newRealm.getRole(roleRep.getName());
addComposites(role, roleRep, newRealm);
}
}
if (rep.getRoles().getApplication() != null) {
for (Map.Entry<String, List<RoleRepresentation>> entry : rep.getRoles().getApplication().entrySet()) {
ApplicationModel app = newRealm.getApplicationByName(entry.getKey());
if (app == null) {
throw new RuntimeException("App doesn't exist in role definitions: " + entry.getKey());
}
for (RoleRepresentation roleRep : entry.getValue()) {
RoleModel role = app.getRole(roleRep.getName());
addComposites(role, roleRep, newRealm);
}
}
}
}

if (rep.getOauthClients() != null) {
Map<String, OAuthClientModel> oauthMap = createOAuthClients(rep, newRealm);
for (OAuthClientModel app : oauthMap.values()) {
Expand Down Expand Up @@ -431,6 +404,7 @@ public void addComposites(RoleModel role, RoleRepresentation roleRep, RealmModel
public void createRole(RealmModel newRealm, RoleRepresentation roleRep) {
RoleModel role = newRealm.addRole(roleRep.getName());
if (roleRep.getDescription() != null) role.setDescription(roleRep.getDescription());
role.setComposite(roleRep.isComposite());
}

public void createRole(RealmModel newRealm, ApplicationModel app, RoleRepresentation roleRep) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.jboss.resteasy.logging.Logger;
import org.keycloak.jose.jws.JWSBuilder;
import org.keycloak.models.ApplicationModel;
import org.keycloak.models.Constants;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleModel;
import org.keycloak.models.UserModel;
Expand All @@ -15,7 +14,6 @@
import javax.ws.rs.core.MultivaluedMap;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -62,7 +60,7 @@ protected boolean isEmpty(SkeletonKeyScope scope) {
return scope == null || scope.isEmpty();
}

public static void addScopes(RoleModel role, RoleModel scope, Set<RoleModel> visited, Set<RoleModel> requested) {
public static void applyScope(RoleModel role, RoleModel scope, Set<RoleModel> visited, Set<RoleModel> requested) {
if (visited.contains(scope)) return;
visited.add(scope);
if (role.hasRole(scope)) {
Expand All @@ -72,7 +70,7 @@ public static void addScopes(RoleModel role, RoleModel scope, Set<RoleModel> vis
if (!scope.isComposite()) return;

for (RoleModel contained : scope.getComposites()) {
addScopes(role, contained, visited, requested);
applyScope(role, contained, visited, requested);
}
}

Expand All @@ -98,7 +96,7 @@ public AccessCodeEntry createAccessCode(String scopeParam, String state, String
if (clientApp != null && role.getContainer().equals(clientApp)) requestedRoles.add(role);
for (RoleModel desiredRole : scopeMappings) {
Set<RoleModel> visited = new HashSet<RoleModel>();
addScopes(role, desiredRole, visited, requestedRoles);
applyScope(role, desiredRole, visited, requestedRoles);
}
}

Expand All @@ -114,35 +112,6 @@ public AccessCodeEntry createAccessCode(String scopeParam, String state, String
}
}




Set<RoleModel> realmRoleMappings = realm.getRealmRoleMappings(user);

for (RoleModel role : realmRoleMappings) {
if (!desiresScope(scopeMap, "realm", role.getName())) continue;
for (RoleModel desiredRole : scopeMappings) {
if (desiredRole.hasRole(role)) {
realmRolesRequested.add(role);
} else if (role.hasRole(desiredRole)) {
realmRolesRequested.add(desiredRole);
}
}
}

for (ApplicationModel application : realm.getApplications()) {
if (!desiresScopeGroup(scopeMap, application.getName())) continue;
Set<RoleModel> appRoleMappings = application.getApplicationRoleMappings(user);
for (RoleModel role : appRoleMappings) {
if (!desiresScope(scopeMap, application.getName(), role.getName())) continue;
for (RoleModel desiredRole : scopeMappings) {
if (!application.getApplicationUser().getLoginName().equals(client.getLoginName())
&& !desiredRole.hasRole(role)) continue;
resourceRolesRequested.add(application.getName(), role);
}
}
}

createToken(code, realm, client, user);
code.setRealm(realm);
code.setExpiration((System.currentTimeMillis() / 1000) + realm.getAccessCodeLifespan());
Expand Down
Loading
0