-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kie-issues#262: Spring-Boot 3.0.5 migration: Fix SVG Addon
* `keycloak-spring-boot-starter` removal in favour of springboot ouath2 * IT test fixes
- Loading branch information
Showing
8 changed files
with
210 additions
and
55 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
26 changes: 26 additions & 0 deletions
26
...ot/addons/process-svg/src/main/java/org/kie/kogito/svg/auth/PrincipalAuthTokenReader.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.kie.kogito.svg.auth; | ||
|
||
public interface PrincipalAuthTokenReader<T> { | ||
|
||
boolean acceptsPrincipal(Object principal); | ||
|
||
String readToken(T principal); | ||
} |
56 changes: 56 additions & 0 deletions
56
...ngboot/addons/process-svg/src/main/java/org/kie/kogito/svg/auth/SpringBootAuthHelper.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.kie.kogito.svg.auth; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.security.core.context.SecurityContext; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@ConditionalOnClass({ SecurityContextHolder.class }) | ||
public class SpringBootAuthHelper { | ||
|
||
private List<PrincipalAuthTokenReader> authTokenReaders; | ||
|
||
public SpringBootAuthHelper(@Autowired List<PrincipalAuthTokenReader> authTokenReaders) { | ||
this.authTokenReaders = authTokenReaders; | ||
} | ||
|
||
public Optional<String> getAuthToken() { | ||
return Optional.ofNullable(getToken()); | ||
} | ||
|
||
private String getToken() { | ||
SecurityContext securityContext = SecurityContextHolder.getContext(); | ||
|
||
if (securityContext == null || securityContext.getAuthentication() == null) { | ||
return null; | ||
} | ||
|
||
Object principal = securityContext.getAuthentication().getPrincipal(); | ||
|
||
return this.authTokenReaders.stream().filter(reader -> reader.acceptsPrincipal(principal)).findFirst() | ||
.map(reader -> "Bearer " + reader.readToken(principal)).orElse(null); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...s/process-svg/src/main/java/org/kie/kogito/svg/auth/impl/JwtPrincipalAuthTokenReader.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.kie.kogito.svg.auth.impl; | ||
|
||
import org.kie.kogito.svg.auth.PrincipalAuthTokenReader; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.security.oauth2.jwt.Jwt; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@ConditionalOnClass(Jwt.class) | ||
public class JwtPrincipalAuthTokenReader implements PrincipalAuthTokenReader<Jwt> { | ||
|
||
@Override | ||
public boolean acceptsPrincipal(Object principal) { | ||
return principal instanceof Jwt; | ||
} | ||
|
||
@Override | ||
public String readToken(Jwt principal) { | ||
return principal.getTokenValue(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
.../process-svg/src/main/java/org/kie/kogito/svg/auth/impl/OIDCPrincipalAuthTokenReader.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.kie.kogito.svg.auth.impl; | ||
|
||
import org.kie.kogito.svg.auth.PrincipalAuthTokenReader; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.security.oauth2.core.oidc.user.OidcUser; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@ConditionalOnClass({ OidcUser.class }) | ||
public class OIDCPrincipalAuthTokenReader implements PrincipalAuthTokenReader<OidcUser> { | ||
|
||
@Override | ||
public boolean acceptsPrincipal(Object principal) { | ||
return principal instanceof OidcUser; | ||
} | ||
|
||
@Override | ||
public String readToken(OidcUser principal) { | ||
return principal.getIdToken().getTokenValue(); | ||
} | ||
} |
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