Compare commits
41 Commits
Author | SHA1 | Date | |
---|---|---|---|
514ba6bae1 | |||
6c93637dbb | |||
65d80dc82d | |||
4859473938 | |||
99f5a7702c | |||
9412957e89 | |||
9c67dad207 | |||
55619d6b4a | |||
0b032f1f7f | |||
3d3a7433c5 | |||
9c7641b858 | |||
0e34f589c3 | |||
a73543d2a6 | |||
cd472b9269 | |||
bf848b009c | |||
52b86c0de4 | |||
8bc0a7e520 | |||
0601b2b2b2 | |||
93af3639cc | |||
0d402f6014 | |||
e7b6bd644e | |||
343e1b65b9 | |||
14487b62eb | |||
e87a6b68a7 | |||
5ecb627dbf | |||
ea487fee31 | |||
9f9ededab2 | |||
f76105b979 | |||
a3cb17e402 | |||
c6d0977b2f | |||
2405a8a313 | |||
173bfed44f | |||
dc5a7dad39 | |||
10ed99b0a2 | |||
4e4a6aca8d | |||
44d0bf533d | |||
807294881b | |||
a42c754a09 | |||
8b05c51ef6 | |||
8bc03e0ea9 | |||
d32e3c7051 |
@@ -55,6 +55,7 @@ The following properties are used across the functionalities of this extension.
|
|||||||
| --------------------------------- | --------- | ----------- |
|
| --------------------------------- | --------- | ----------- |
|
||||||
| `auth-ext.externalId` | `oauth` | This will serve as the external ID for users and as the prefix for the external ID of groups created or searched by this extension. Anything without an external ID is considered internal. So mismatched external IDs are never considered for anything by this extension. |
|
| `auth-ext.externalId` | `oauth` | This will serve as the external ID for users and as the prefix for the external ID of groups created or searched by this extension. Anything without an external ID is considered internal. So mismatched external IDs are never considered for anything by this extension. |
|
||||||
| `auth-ext.tenant` | | A preselected tenant for all operations in this extension. Only required if there are multiple tenants. |
|
| `auth-ext.tenant` | | A preselected tenant for all operations in this extension. Only required if there are multiple tenants. |
|
||||||
|
| `auth-ext.sync.resyncInMillis` | `300000` | To prevent too many sync checks, how long between seeing the EXACT same token should we wait before doing another sync. The only time this matters is if the user is manually added to or removed from groups in APS by other means. Or those groups are deleted. |
|
||||||
|
|
||||||
### OAuth Authentication/Authorization
|
### OAuth Authentication/Authorization
|
||||||
|
|
||||||
|
178
dependency-reduced-pom.xml
Normal file
178
dependency-reduced-pom.xml
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.inteligr8.activiti</groupId>
|
||||||
|
<artifactId>keycloak-activiti-app-ext</artifactId>
|
||||||
|
<name>Keycloak Authentication & Authorization for APS</name>
|
||||||
|
<version>1.4-SNAPSHOT</version>
|
||||||
|
<description>An Alfresco Process Service App extension providing improved Keycloak/AIS support.</description>
|
||||||
|
<url>https://bitbucket.org/inteligr8/keycloak-activiti-app-ext</url>
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<id>brian.long</id>
|
||||||
|
<name>Brian Long</name>
|
||||||
|
<email>brian@inteligr8.com</email>
|
||||||
|
<url>https://twitter.com/brianmlong</url>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007</name>
|
||||||
|
<url>https://www.gnu.org/licenses/lgpl-3.0.txt</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
<scm>
|
||||||
|
<connection>scm:git:https://bitbucket.org/inteligr8/keycloak-activiti-app-ext.git</connection>
|
||||||
|
<developerConnection>scm:git:git@bitbucket.org:inteligr8/keycloak-activiti-app-ext.git</developerConnection>
|
||||||
|
<url>https://bitbucket.org/inteligr8/keycloak-activiti-app-ext</url>
|
||||||
|
</scm>
|
||||||
|
<organization>
|
||||||
|
<name>Inteligr8</name>
|
||||||
|
<url>https://www.inteligr8.com</url>
|
||||||
|
</organization>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.6.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>shade-jar</id>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern />
|
||||||
|
<shadedPattern>shaded.keycloak.</shadedPattern>
|
||||||
|
<excludes>
|
||||||
|
<exclude>com.activiti.conf.*</exclude>
|
||||||
|
<exclude>com.activiti.extension.conf.*</exclude>
|
||||||
|
<exclude>com.inteligr8.activiti.**</exclude>
|
||||||
|
<exclude>META-INF/**/*</exclude>
|
||||||
|
</excludes>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>ossrh-release</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>source</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>jar-no-fork</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>javadoc</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>jar</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<show>public</show>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-gpg-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>sign</id>
|
||||||
|
<phase>verify</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>sign</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.sonatype.plugins</groupId>
|
||||||
|
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||||
|
<version>1.7.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>ossrh-deploy</id>
|
||||||
|
<phase>deploy</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>deploy</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<serverId>ossrh</serverId>
|
||||||
|
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
|
||||||
|
<autoReleaseAfterClose>true</autoReleaseAfterClose>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<properties>
|
||||||
|
<maven.deploy.skip>true</maven.deploy.skip>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>alfresco-private</id>
|
||||||
|
<url>https://artifacts.alfresco.com/nexus/content/groups/private</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>activiti-releases</id>
|
||||||
|
<url>https://artifacts.alfresco.com/nexus/content/repositories/activiti-enterprise-releases</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.security</groupId>
|
||||||
|
<artifactId>spring-security-oauth2-client</artifactId>
|
||||||
|
<version>6.3.2</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.activiti</groupId>
|
||||||
|
<artifactId>activiti-app</artifactId>
|
||||||
|
<version>24.3.0</version>
|
||||||
|
<classifier>classes</classifier>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>aspose-transformation</artifactId>
|
||||||
|
<groupId>com.activiti</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>aoservices</artifactId>
|
||||||
|
<groupId>org.alfresco.officeservices</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.release>17</maven.compiler.release>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<keycloak.version>23.0.7</keycloak.version>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<slf4j.version>1.7.36</slf4j.version>
|
||||||
|
<spring-security-oauth2.version>6.3.2</spring-security-oauth2.version>
|
||||||
|
<aps.version>24.3.0</aps.version>
|
||||||
|
</properties>
|
||||||
|
</project>
|
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>com.inteligr8.activiti</groupId>
|
<groupId>com.inteligr8.activiti</groupId>
|
||||||
<artifactId>auth-activiti-app-ext</artifactId>
|
<artifactId>auth-activiti-app-ext</artifactId>
|
||||||
<version>2.1-SNAPSHOT</version>
|
<version>2.1.2</version>
|
||||||
|
|
||||||
<name>Authentication & Authorization for APS</name>
|
<name>Authentication & Authorization for APS</name>
|
||||||
<description>An Alfresco Process Service App extension providing improved authentication and authorization support.</description>
|
<description>An Alfresco Process Service App extension providing improved authentication and authorization support.</description>
|
||||||
|
@@ -4,10 +4,12 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
|
import org.springframework.security.oauth2.core.oidc.StandardClaimNames;
|
||||||
import org.springframework.security.oauth2.jwt.Jwt;
|
import org.springframework.security.oauth2.jwt.Jwt;
|
||||||
|
|
||||||
import com.activiti.security.identity.service.config.JwtAuthenticationToken;
|
import com.activiti.security.identity.service.config.JwtAuthenticationToken;
|
||||||
@@ -22,6 +24,9 @@ public class SyncingJwtAuthenticationConverter implements Converter<Jwt, Abstrac
|
|||||||
private final UserSyncService userSyncService;
|
private final UserSyncService userSyncService;
|
||||||
private final GroupSyncService groupSyncService;
|
private final GroupSyncService groupSyncService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TokenRecaller tokenRecaller;
|
||||||
|
|
||||||
public SyncingJwtAuthenticationConverter(UserDetailsService userDetailsService, UserSyncService userSyncService, GroupSyncService groupSyncService) {
|
public SyncingJwtAuthenticationConverter(UserDetailsService userDetailsService, UserSyncService userSyncService, GroupSyncService groupSyncService) {
|
||||||
this.userDetailsService = userDetailsService;
|
this.userDetailsService = userDetailsService;
|
||||||
this.userSyncService = userSyncService;
|
this.userSyncService = userSyncService;
|
||||||
@@ -30,18 +35,24 @@ public class SyncingJwtAuthenticationConverter implements Converter<Jwt, Abstrac
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractAuthenticationToken convert(Jwt source) {
|
public AbstractAuthenticationToken convert(Jwt source) {
|
||||||
this.logger.trace("convert({}, {})", source.getId(), source.getClaim("email"));
|
if (this.logger.isTraceEnabled()) {
|
||||||
|
this.logger.trace("convert({}, {})", source.getId(), source.getClaimAsString(StandardClaimNames.EMAIL));
|
||||||
try {
|
try {
|
||||||
this.logger.debug("jwt: {}", new ObjectMapper().registerModule(new JavaTimeModule()).writeValueAsString(source));
|
this.logger.trace("jwt: {}", new ObjectMapper().registerModule(new JavaTimeModule()).writeValueAsString(source));
|
||||||
} catch (JsonProcessingException jpe) {
|
} catch (JsonProcessingException jpe) {
|
||||||
this.logger.error("error", jpe);
|
this.logger.error("error", jpe);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.tokenRecaller.recall(source.getTokenValue())) {
|
||||||
|
this.logger.trace("Skipping sync for '{}' as the same token was already recently sync'd", source.getClaimAsString(StandardClaimNames.EMAIL));
|
||||||
|
} else {
|
||||||
this.userSyncService.sync(source);
|
this.userSyncService.sync(source);
|
||||||
this.groupSyncService.sync(source);
|
this.groupSyncService.sync(source);
|
||||||
|
this.tokenRecaller.add(source.getTokenValue());
|
||||||
|
}
|
||||||
|
|
||||||
UserDetails springUser = this.userDetailsService.loadUserByUsername(source.getClaim("email"));
|
UserDetails springUser = this.userDetailsService.loadUserByUsername(source.getClaimAsString(StandardClaimNames.EMAIL));
|
||||||
return new JwtAuthenticationToken(
|
return new JwtAuthenticationToken(
|
||||||
springUser,
|
springUser,
|
||||||
new ArrayList<>(springUser.getAuthorities()));
|
new ArrayList<>(springUser.getAuthorities()));
|
||||||
|
@@ -29,7 +29,7 @@ import com.activiti.security.identity.service.config.IdentityServiceKeycloakProp
|
|||||||
@Primary
|
@Primary
|
||||||
public class SyncingUserService extends OidcUserService {
|
public class SyncingUserService extends OidcUserService {
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(SyncingUserService.class);
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserDetailsService userDetailsService;
|
private UserDetailsService userDetailsService;
|
||||||
@@ -43,6 +43,9 @@ public class SyncingUserService extends OidcUserService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IdentityServiceKeycloakProperties identityServiceKeycloakProperties;
|
private IdentityServiceKeycloakProperties identityServiceKeycloakProperties;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TokenRecaller tokenRecaller;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OidcUser loadUser(OidcUserRequest userRequest) throws OAuth2AuthenticationException {
|
public OidcUser loadUser(OidcUserRequest userRequest) throws OAuth2AuthenticationException {
|
||||||
this.logger.trace("loadUser({}, {})", userRequest.getIdToken().getEmail(), userRequest.getAccessToken().getScopes());
|
this.logger.trace("loadUser({}, {})", userRequest.getIdToken().getEmail(), userRequest.getAccessToken().getScopes());
|
||||||
@@ -50,10 +53,14 @@ public class SyncingUserService extends OidcUserService {
|
|||||||
OidcUser oidcUser = super.loadUser(userRequest);
|
OidcUser oidcUser = super.loadUser(userRequest);
|
||||||
this.logger.debug("Loaded OIDC user: {}", oidcUser.getEmail());
|
this.logger.debug("Loaded OIDC user: {}", oidcUser.getEmail());
|
||||||
|
|
||||||
|
if (this.tokenRecaller.recall(userRequest.getAccessToken().getTokenValue())) {
|
||||||
|
this.logger.trace("Skipping sync for '{}' as the same token was already recently sync'd", userRequest.getIdToken().getEmail());
|
||||||
|
} else {
|
||||||
this.userSyncService.sync(oidcUser);
|
this.userSyncService.sync(oidcUser);
|
||||||
this.groupSyncService.sync(oidcUser);
|
this.groupSyncService.sync(oidcUser);
|
||||||
|
this.tokenRecaller.add(userRequest.getAccessToken().getTokenValue());
|
||||||
|
}
|
||||||
|
|
||||||
// reload for sync'd group changes
|
|
||||||
UserDetails springUser = this.userDetailsService.loadUserByUsername(oidcUser.getEmail());
|
UserDetails springUser = this.userDetailsService.loadUserByUsername(oidcUser.getEmail());
|
||||||
|
|
||||||
CustomOAuth2User customOAuth2User = new CustomOAuth2User(
|
CustomOAuth2User customOAuth2User = new CustomOAuth2User(
|
||||||
|
59
src/main/java/com/inteligr8/activiti/auth/service/TokenRecaller.java
Executable file
59
src/main/java/com/inteligr8/activiti/auth/service/TokenRecaller.java
Executable file
@@ -0,0 +1,59 @@
|
|||||||
|
package com.inteligr8.activiti.auth.service;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.map.PassiveExpiringMap;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class TokenRecaller {
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
|
@Value("${auth-ext.sync.resyncInMillis:300000}")
|
||||||
|
private long resyncTimeInMillis;
|
||||||
|
|
||||||
|
private PassiveExpiringMap<String, Long> tokenCache;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
private void init() {
|
||||||
|
this.tokenCache = new PassiveExpiringMap<>(this.resyncTimeInMillis, TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Scheduled(timeUnit = TimeUnit.MINUTES, initialDelay = 10L, fixedDelay = 5L)
|
||||||
|
private void reap() {
|
||||||
|
int tokens = this.tokenCache.size();
|
||||||
|
this.logger.trace("Reaping token cache of size: {}", tokens);
|
||||||
|
|
||||||
|
synchronized (this.tokenCache) {
|
||||||
|
// clear expired keys
|
||||||
|
this.tokenCache.entrySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.debug("Reaped {} expired tokens from cache", this.tokenCache.size() - tokens);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(String token) {
|
||||||
|
synchronized (this.tokenCache) {
|
||||||
|
this.tokenCache.put(token, System.currentTimeMillis() + this.resyncTimeInMillis);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean recall(String token) {
|
||||||
|
Long expirationTimeMillis = this.tokenCache.get(token);
|
||||||
|
if (expirationTimeMillis == null) {
|
||||||
|
return false;
|
||||||
|
} else if (expirationTimeMillis < System.currentTimeMillis()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user