Compare commits

..

No commits in common. "main" and "v1.0.1" have entirely different histories.
main ... v1.0.1

6 changed files with 35 additions and 42 deletions

@ -1,13 +1,11 @@
name: Keycloak mailcow Build
name: deploy
on:
push:
branches: [ main ]
pull_request:
jobs:
release:
name: Build und Bereitstellung
deploy:
runs-on: act-runner-user
steps:
- name: Checkout
@ -18,13 +16,11 @@ jobs:
mvn package
- name: Remove old version
if: gitea.event_name == 'push'
run: |
rm -rf /opt/data/keycloak/providers/spring-security-crypto-*.jar
rm -rf /opt/data/keycloak/providers/keycloak-mailcow-*.jar
- name: Deploy
if: gitea.event_name == 'push'
run: |
export SPRINGSEC_VERSION=$(xmlstarlet sel -N x="http://maven.apache.org/POM/4.0.0" -t -m 'x:project/x:properties/x:version.springsec' -v . pom.xml)
curl -sL \
@ -33,15 +29,14 @@ jobs:
export SPI_VERSION=$(xmlstarlet sel -N x="http://maven.apache.org/POM/4.0.0" -t -m 'x:project/x:version' -v . pom.xml)
cp -r target/keycloak-mailcow-$SPI_VERSION.jar /opt/data/keycloak/providers/keycloak-mailcow-$SPI_VERSION.jar
- name: Restart Keycloak
if: gitea.event_name == 'push'
run: |
curl -X POST -H "X-API-KEY: ${{ secrets.PORTAINER_API_KEY }}" https://docker.cantorgymnasium.de/api/stacks/48/stop\?endpointId\=1
curl -X POST -H "X-API-KEY: ${{ secrets.PORTAINER_API_KEY }}" https://docker.cantorgymnasium.de/api/stacks/48/start\?endpointId\=1
- name: Notification
uses: actions/telegram-action@main
if: always()
with:
chat_id: ${{ secrets.TG_CHAT_ID }}
token: ${{ secrets.TG_TOKEN }}
- name: Restart Keycloak
run: |
curl -X POST -H "X-API-KEY: ${{ secrets.PORTAINER_API_KEY }}" https://docker.cantorgymnasium.de/api/stacks/48/stop\?endpointId\=1
curl -X POST -H "X-API-KEY: ${{ secrets.PORTAINER_API_KEY }}" https://docker.cantorgymnasium.de/api/stacks/48/start\?endpointId\=1

12
pom.xml

@ -8,12 +8,12 @@
<groupId>de.cantorgymnasium</groupId>
<artifactId>keycloak-mailcow</artifactId>
<version>1.1.0</version>
<version>1.0.1</version>
<packaging>jar</packaging>
<properties>
<version.keycloak>26.0.5</version.keycloak>
<version.springsec>6.3.4</version.springsec>
<version.keycloak>23.0.1</version.keycloak>
<version.springsec>6.2.1</version.springsec>
</properties>
<dependencies>
@ -31,7 +31,7 @@
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-model-storage</artifactId>
<artifactId>keycloak-model-legacy</artifactId>
<scope>provided</scope>
<version>${version.keycloak}</version>
</dependency>
@ -50,7 +50,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.16</version>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
@ -64,7 +64,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<version>3.11.0</version>
<configuration>
<source>17</source>
<target>17</target>

@ -1,3 +0,0 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
}

@ -5,7 +5,7 @@ import java.util.Map;
import org.keycloak.common.util.MultivaluedHashMap;
import org.keycloak.component.ComponentModel;
import org.keycloak.credential.UserCredentialManager;
import org.keycloak.credential.LegacyUserCredentialManager;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.SubjectCredentialManager;
@ -130,6 +130,6 @@ class mailcowUser extends AbstractUserAdapter {
@Override
public SubjectCredentialManager credentialManager() {
return new UserCredentialManager(session, realm, this);
return new LegacyUserCredentialManager(session, realm, this);
}
}

@ -49,19 +49,19 @@ public class mailcowUserStorageProvider implements UserStorageProvider,
@Override
public void close() {
logger.debug("[mailcow] close()");
logger.info("[mailcow] close()");
}
@Override
public UserModel getUserById(RealmModel realm, String id) {
logger.debug("[mailcow] getUserById({})", id);
logger.info("[mailcow] getUserById({})", id);
StorageId sid = new StorageId(id);
return getUserByUsername(realm, sid.getExternalId());
}
@Override
public UserModel getUserByUsername(RealmModel realm, String username) {
logger.debug("[mailcow] getUserByUsername({})", username);
logger.info("[mailcow] getUserByUsername({})", username);
try (Connection c = DbUtil.getConnection(this.model)) {
PreparedStatement st = c.prepareStatement(
"select username, name, `mailbox`.`domain`, local_part FROM `mailbox` INNER JOIN domain on mailbox.domain = domain.domain WHERE `mailbox`.`active` = '1' AND `domain`.`active`='1' AND username = ?");
@ -80,7 +80,7 @@ public class mailcowUserStorageProvider implements UserStorageProvider,
@Override
public UserModel getUserByEmail(RealmModel realm, String email) {
logger.debug("[mailcow] getUserByEmail({})", email);
logger.info("[mailcow] getUserByEmail({})", email);
try (Connection c = DbUtil.getConnection(this.model)) {
PreparedStatement st = c.prepareStatement(
"select username, name, `mailbox`.`domain`, local_part FROM `mailbox` INNER JOIN domain on mailbox.domain = domain.domain WHERE `mailbox`.`active` = '1' AND `domain`.`active`='1' AND username = ?");
@ -99,13 +99,13 @@ public class mailcowUserStorageProvider implements UserStorageProvider,
@Override
public boolean supportsCredentialType(String credentialType) {
logger.debug("[mailcow] supportsCredentialType({})", credentialType);
logger.info("[mailcow] supportsCredentialType({})", credentialType);
return PasswordCredentialModel.TYPE.endsWith(credentialType);
}
@Override
public boolean isConfiguredFor(RealmModel realm, UserModel user, String credentialType) {
logger.debug("[mailcow] isConfiguredFor(realm={},user={},credentialType={})", realm.getName(),
logger.info("[mailcow] isConfiguredFor(realm={},user={},credentialType={})", realm.getName(),
user.getUsername(), credentialType);
// In our case, password is the only type of credential, so we allways return
// 'true' if
@ -114,7 +114,7 @@ public class mailcowUserStorageProvider implements UserStorageProvider,
}
private boolean verifyHash(String hash, String password) {
logger.debug("[mailcow] verifyHash");
logger.info("[mailcow] verifyHash");
Pattern pattern = Pattern.compile("\\{(.+)\\}(.+)");
Matcher matcher = pattern.matcher(hash);
while (matcher.find()) {
@ -128,7 +128,7 @@ public class mailcowUserStorageProvider implements UserStorageProvider,
@Override
public boolean isValid(RealmModel realm, UserModel user, CredentialInput credentialInput) {
logger.debug("[mailcow] isValid(realm={},user={},credentialInput.type={})", realm.getName(), user.getUsername(),
logger.info("[mailcow] isValid(realm={},user={},credentialInput.type={})", realm.getName(), user.getUsername(),
credentialInput.getType());
if (!this.supportsCredentialType(credentialInput.getType())) {
return false;
@ -157,7 +157,7 @@ public class mailcowUserStorageProvider implements UserStorageProvider,
@Override
public int getUsersCount(RealmModel realm) {
logger.debug("[mailcow] getUsersCount: realm={}", realm.getName());
logger.info("[mailcow] getUsersCount: realm={}", realm.getName());
try (Connection c = DbUtil.getConnection(this.model)) {
Statement st = c.createStatement();
st.execute(
@ -173,7 +173,7 @@ public class mailcowUserStorageProvider implements UserStorageProvider,
@Override
public Stream<UserModel> getGroupMembersStream(RealmModel realm, GroupModel group, Integer firstResult,
Integer maxResults) {
logger.debug("[mailcow] getUsers: realm={}", realm.getName());
logger.info("[mailcow] getUsers: realm={}", realm.getName());
try (Connection c = DbUtil.getConnection(this.model)) {
PreparedStatement st = c.prepareStatement(
@ -182,6 +182,7 @@ public class mailcowUserStorageProvider implements UserStorageProvider,
st.setInt(2, firstResult);
st.execute();
ResultSet rs = st.getResultSet();
logger.info(rs.toString());
List<UserModel> users = new ArrayList<>();
while (rs.next()) {
users.add(mapUser(realm, rs));
@ -197,7 +198,7 @@ public class mailcowUserStorageProvider implements UserStorageProvider,
Integer maxResults) {
String search = params.get(UserModel.SEARCH);
logger.debug("[mailcow] searchForUser: realm={}, search={}", realm.getName(), search);
logger.info("[mailcow] searchForUser: realm={}, search={}", realm.getName(), search);
try (Connection c = DbUtil.getConnection(this.model)) {
PreparedStatement st;

@ -20,7 +20,7 @@ public class mailcowUserStorageProviderFactory implements UserStorageProviderFac
protected final List<ProviderConfigProperty> configMetadata;
public mailcowUserStorageProviderFactory() {
logger.debug("[mailcow] mailcowUserStorageProviderFactory created");
logger.info("[mailcow] mailcowUserStorageProviderFactory created");
// Create config metadata
configMetadata = ProviderConfigurationBuilder.create()
@ -64,13 +64,13 @@ public class mailcowUserStorageProviderFactory implements UserStorageProviderFac
@Override
public mailcowUserStorageProvider create(KeycloakSession ksession, ComponentModel model) {
logger.debug("[mailcow] creating new mailcowUserStorageProvider");
logger.info("[mailcow] creating new mailcowUserStorageProvider");
return new mailcowUserStorageProvider(ksession, model);
}
@Override
public String getId() {
logger.debug("[mailcow] getId()");
logger.info("[mailcow] getId()");
return "mailcow-user-provider";
}
@ -85,9 +85,9 @@ public class mailcowUserStorageProviderFactory implements UserStorageProviderFac
throws ComponentValidationException {
try (Connection c = DbUtil.getConnection(config)) {
logger.debug("[mailcow] Testing connection...");
logger.info("[mailcow] Testing connection...");
c.createStatement().execute(config.get(CONFIG_KEY_VALIDATION_QUERY));
logger.debug("[mailcow] Connection OK !");
logger.info("[mailcow] Connection OK !");
} catch (Exception ex) {
logger.warn("[mailcow] Unable to validate connection: ex={}", ex.getMessage());
throw new ComponentValidationException("Unable to validate database connection", ex);
@ -96,11 +96,11 @@ public class mailcowUserStorageProviderFactory implements UserStorageProviderFac
@Override
public void onUpdate(KeycloakSession session, RealmModel realm, ComponentModel oldModel, ComponentModel newModel) {
logger.debug("[mailcow] onUpdate()");
logger.info("[mailcow] onUpdate()");
}
@Override
public void onCreate(KeycloakSession session, RealmModel realm, ComponentModel model) {
logger.debug("[mailcow] onCreate()");
logger.info("[mailcow] onCreate()");
}
}