Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Closes keycloak/keycloak#17393
chery-pick Add user-storage-simple to GHA
  • Loading branch information
pedro-hos authored and hmlnarik committed Mar 9, 2023
1 parent d555be0 commit 077871f
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 127 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@
<module>app-authz-photoz</module>
<module>authz-js-policies</module>
<module>extend-account-console</module>
<module>user-storage-simple</module>
</modules>

<repositories>
Expand Down
1 change: 1 addition & 0 deletions scripts/build-quickstarts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ else
fi

cp authz-js-policies/target/authz-js-policies.jar $dist/providers
cp user-storage-simple/target/user-storage-properties-example.jar $dist/providers
2 changes: 1 addition & 1 deletion scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ run_tests app-jee-jsp -Pwildfly-managed
run_tests app-profile-jee-html5 -Pwildfly-managed
run_tests app-profile-jee-jsp -Pwildfly-managed
run_tests app-profile-jee-vanilla -Pwildfly-managed
run_tests user-storage-simple -Pkeycloak-remote
# TODO Not working with Quarkus dist (or not working?)
#run_tests app-profile-saml-jee-jsp -Pwildfly-managed

Expand All @@ -89,7 +90,6 @@ run_tests app-profile-jee-vanilla -Pwildfly-managed
#run_tests service-jee-jaxrs -Pwildfly-managed
#run_tests service-springboot-rest -Pspring-boot
#run_tests user-storage-jpa-legacy -Pkeycloak-remote
#run_tests user-storage-simple -Pkeycloak-remote

mvn -f service-springboot-rest spring-boot:run >/dev/null&
run_tests app-springboot -Pspring-boot
Expand Down
20 changes: 16 additions & 4 deletions user-storage-simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,19 @@ All you need to build this project is Java 8.0 (Java SDK 1.8) or later and Maven
Build and Deploy the Quickstart
-------------------------------

To deploy this provider you must have <span>Keycloak</span> running in standalone or standalone-ha mode. Then type the follow maven command:
To build the provider, run the following maven command:

````
mvn clean install wildfly:deploy
mvn clean install
````
If you want to play with and modify the example, simply rerun the maven deploy command above and the new version will be hot deployed.

To install the provider, copy the target/user-storage-properties-example.jar JAR file to the `providers` directory of the server distribution.

Finally, start the server as follows:

```
kc.[sh|bat] start-dev
```

Enable the Provider for a Realm
-------------------------------
Expand All @@ -63,7 +70,12 @@ edit the file yourself to add the username/password pairs you want.
Integration test of the Quickstart
----------------------------------

1. Make sure you have an Keycloak server running with an admin user in the `master` realm or use the provided docker image
1. Make sure you have an Keycloak server running with an admin user in the `master` realm or use the provided docker image. Your <span>Keycloak</span> should be listening on `http://localhost:8180/auth`. You can archive this by running:

```
./kc.sh start-dev --http-port=8180 --http-relative-path="/auth"
```

2. You need to have Chrome browser installed and updated to the latest version.
3. Run `mvn test -Pkeycloak-remote`

Expand Down
10 changes: 0 additions & 10 deletions user-storage-simple/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-phantom-driver</artifactId>
<version>${arquillian-phantom.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -93,15 +92,6 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
<configuration>
<skip>false</skip>
<port>${keycloak.management.port}</port>
</configuration>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,28 @@

package org.keycloak.quickstart.readonly;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Stream;

import org.keycloak.component.ComponentModel;
import org.keycloak.credential.CredentialInput;
import org.keycloak.credential.CredentialInputUpdater;
import org.keycloak.credential.CredentialInputValidator;
import org.keycloak.credential.CredentialModel;
import org.keycloak.credential.LegacyUserCredentialManager;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.SubjectCredentialManager;
import org.keycloak.models.UserCredentialModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.credential.PasswordCredentialModel;
import org.keycloak.storage.ReadOnlyException;
import org.keycloak.storage.StorageId;
import org.keycloak.storage.UserStorageProvider;
import org.keycloak.storage.adapter.AbstractUserAdapter;
import org.keycloak.storage.user.UserLookupProvider;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
Expand All @@ -65,7 +64,7 @@ public PropertyFileUserStorageProvider(KeycloakSession session, ComponentModel m
// UserLookupProvider methods

@Override
public UserModel getUserByUsername(String username, RealmModel realm) {
public UserModel getUserByUsername(RealmModel realm, String username) {
UserModel adapter = loadedUsers.get(username);
if (adapter == null) {
String password = properties.getProperty(username);
Expand All @@ -92,14 +91,14 @@ public SubjectCredentialManager credentialManager() {
}

@Override
public UserModel getUserById(String id, RealmModel realm) {
public UserModel getUserById(RealmModel realm, String id) {
StorageId storageId = new StorageId(id);
String username = storageId.getExternalId();
return getUserByUsername(username, realm);
return getUserByUsername(realm, username);
}

@Override
public UserModel getUserByEmail(String email, RealmModel realm) {
public UserModel getUserByEmail(RealmModel realm, String email) {
return null;
}

Expand All @@ -109,12 +108,12 @@ public UserModel getUserByEmail(String email, RealmModel realm) {
@Override
public boolean isConfiguredFor(RealmModel realm, UserModel user, String credentialType) {
String password = properties.getProperty(user.getUsername());
return credentialType.equals(CredentialModel.PASSWORD) && password != null;
return credentialType.equals(PasswordCredentialModel.TYPE) && password != null;
}

@Override
public boolean supportsCredentialType(String credentialType) {
return credentialType.equals(CredentialModel.PASSWORD);
return credentialType.equals(PasswordCredentialModel.TYPE);
}

@Override
Expand All @@ -131,7 +130,7 @@ public boolean isValid(RealmModel realm, UserModel user, CredentialInput input)

@Override
public boolean updateCredential(RealmModel realm, UserModel user, CredentialInput input) {
if (input.getType().equals(CredentialModel.PASSWORD)) throw new ReadOnlyException("user is read only for this update");
if (input.getType().equals(PasswordCredentialModel.TYPE)) throw new ReadOnlyException("user is read only for this update");

return false;
}
Expand All @@ -142,13 +141,13 @@ public void disableCredentialType(RealmModel realm, UserModel user, String crede
}

@Override
public Set<String> getDisableableCredentialTypes(RealmModel realm, UserModel user) {
return Collections.EMPTY_SET;
public Stream<String> getDisableableCredentialTypesStream(RealmModel realm, UserModel user) {
return Stream.empty();
}


@Override
public void close() {

}
}
}
Loading

0 comments on commit 077871f

Please sign in to comment.