Skip to content

Commit b578198

Browse files
committed
first funcitonal plugin
1 parent 4e09863 commit b578198

16 files changed

+109
-64
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
gocd/plugins/
2+
13
# Intellij files
24
.idea/
35

CHANGELOG.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
## 1.1.0 - 2020-06-11
2-
3-
Switching the Okta client ID variable for secure to plain text one. The client ID is present in the authentication and refresh tokens requests to Okta. Having it encrypted resulted in bad requests which is now no longer the case.
4-
5-
- Fix for the Okta Client ID [#6](https://github.com/szamfirov/gocd-okta-oauth-authorization-plugin/pull/6)
6-
7-
## 1.0.0 - 2018-03-12
1+
## 1.0.0 - 2020-11-13
82

93
Initial release of plugin
104

INSTALL.md

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,25 @@ on Windows.
1313

1414
## Configuration
1515

16-
### Configure Okta API Issuer
17-
18-
1. Sign in to Okta [API credentials](https://developer.okta.com/signup/)
19-
2. Click on **_API_** _>_ **_Authorization Servers_**
20-
3. Click on **_default_** as that will be your Authorization Server
21-
4. Navigate to **_Scopes_** _>_ **_Add Scope_**
22-
5. Create a scope with name _groups_ and select `Include in public metadata`
23-
6. Navigate to **_Claims_** _>_ **_Add Claim_**
24-
7. Create a claim with name _groups_ as following:
25-
1. Choose the `Token type` to be: _ID Token_
26-
2. Select `Value type`: _Groups_
27-
3. Set the `Filter` to: _Regex_ and value: `.*` (there is a dot in there)
28-
29-
### Configure Okta Application
30-
31-
1. Sign in to Okta [API credentials](https://developer.okta.com/signup/)
32-
2. Click on **_Applications_** and from there **_Add Application_**.
33-
3. Select type `Web`.
34-
4. Fill in the `Login redirect URI` as follows: `https://{your_base_url}/go/plugin/cd.go.authorization.keycloak/authenticate`
35-
5. Click **_Save_** and afterwards change the `Initiate login URI` to: `https://{your_base_url}/go/plugin/cd.go.authorization.keycloak/login`
36-
37-
### Create Authorization Configuration
38-
39-
1. Login to `GoCD server` as admin and navigate to **_Admin_** _>_ **_Security_** _>_ **_Authorization Configuration_**.
40-
2. Click on **_Add_** to create new authorization configuration.
41-
1. Specify `id` for auth config.
42-
2. Select `Okta oauth authorization plugin for GoCD` for **_Plugin id_**
43-
3. Specify your Okta API Issuer: `https://{your_okta_url}/oauth2/default`
44-
4. Specify **_Client ID_** and **_Client Secret_** that come from the Application.
45-
5. Save your configuration and you'll be redirected to GoCD login page.
46-
3. Click on the Okta button and you should be logged in.
16+
### Configure Keycloak API Issuer
17+
18+
1. Sign in Keycloak Console
19+
2. Select the realm that you want to configure. Ex. **Master**
20+
3. Click in **Clients** menu
21+
4. Click **Add** button
22+
5. On the form insert the client name
23+
6. On the next page, set this configs:
24+
1. In **Access Type** select **Confidential**
25+
2. In **Valid Redirect URIs** insert the URL of GoCD, ex.: **http://localhost:8153**
26+
3. In **Credentials** tab copy value of **Secret**
4727

4828
### Create Role Configuration
4929

50-
1. Login to `GoCD server` as admin and navigate to **_Admin_** _>_ **_Security_** _>_ **_Role Configuration_**.
51-
2. Click on **_Add_** to create new role configuration.
52-
1. Select `Plugin Role` as the type of role.
53-
2. Specify the name of the role in `Role name`.
54-
3. _(Optional)_ Use `Okta Groups` to choose which groups will use this role.
55-
4. _(Optional)_ Use `Okta Users` to choose which users will use this role.
56-
3. All your users matching the criteria will have this role associated with their account in GoCD.
30+
1. Sign in Keycloak Console
31+
2. Select the realm that you want to configure. Ex. **Master**
32+
3. Click in **Roles** menu
33+
1. Click **Add Role** button
34+
2. Insert the name of **Role** and it description
35+
3. Save the **Role**
36+
4. Select the user that you want to configure this role
37+
5. Select **Role Mappings** tab and select tht **Role** created

gocd/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.PHONY: help
2+
help:
3+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / { printf "\033[36m%-30s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
4+
.DEFAULT_GOAL := help
5+
6+
# DOCKER TASKS
7+
start: ## Run servers to develop test
8+
mkdir -p ./plugins/external
9+
cp ../build/libs/*.jar ./plugins/external
10+
docker-compose up -d
11+
12+
stop: ## Stop servers
13+
rm -rf ./plugins
14+
docker-compose down

gocd/docker-compose.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: '3'
2+
3+
services:
4+
keycloak:
5+
image: jboss/keycloak:11.0.3
6+
environment:
7+
ROOT_LOGLEVEL: INFO
8+
KEYCLOAK_USER: admin
9+
KEYCLOAK_PASSWORD: admin
10+
DB_VENDOR: h2
11+
ports:
12+
- 8080:8080
13+
gocd:
14+
image: gocd/gocd-server:v20.9.0
15+
volumes:
16+
- ./plugins:/godata/plugins
17+
ports:
18+
- 8153:8153
19+
- 8154:8154

src/main/java/cd/go/authorization/keycloak/KeycloakApiClient.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,20 @@ public void verifyConnection() throws Exception {
5656

5757
public String authorizationServerUrl(String callbackUrl) throws Exception {
5858
LOG.debug("[KeycloakApiClient] Generating Keycloak oauth url.");
59+
String realm = keycloakConfiguration.keycloakRealm();
5960

6061
return HttpUrl.parse(keycloakConfiguration.keycloakEndpoint())
6162
.newBuilder()
6263
.addPathSegments("auth")
6364
.addPathSegments("realms")
64-
.addPathSegments("master")
65+
.addPathSegments(realm)
6566
.addPathSegments("protocol")
6667
.addPathSegments("openid-connect")
6768
.addPathSegments("auth")
6869
.addQueryParameter("client_id", keycloakConfiguration.clientId())
6970
.addQueryParameter("redirect_uri", callbackUrl)
7071
.addQueryParameter("response_type", "code")
71-
.addQueryParameter("scope", "openid profile email groups")
72+
.addQueryParameter("scope", "openid profile email roles")
7273
.addQueryParameter("state", UUID.randomUUID().toString())
7374
.addQueryParameter("nonce", UUID.randomUUID().toString())
7475
.build().toString();
@@ -81,12 +82,13 @@ public TokenInfo fetchAccessToken(Map<String, String> params) throws Exception {
8182
}
8283

8384
LOG.debug("[KeycloakApiClient] Fetching access token using authorization code.");
85+
String realm = keycloakConfiguration.keycloakRealm();
8486

8587
final String accessTokenUrl = HttpUrl.parse(keycloakConfiguration.keycloakEndpoint())
8688
.newBuilder()
8789
.addPathSegments("auth")
8890
.addPathSegments("realms")
89-
.addPathSegments("master")
91+
.addPathSegments(realm)
9092
.addPathSegments("protocol")
9193
.addPathSegments("openid-connect")
9294
.addPathSegments("token")
@@ -112,12 +114,13 @@ public KeycloakUser userProfile(TokenInfo tokenInfo) throws Exception {
112114
validateTokenInfo(tokenInfo);
113115

114116
LOG.debug("[KeycloakApiClient] Fetching user profile using access token.");
117+
String realm = keycloakConfiguration.keycloakRealm();
115118

116119
final String userProfileUrl = HttpUrl.parse(keycloakConfiguration.keycloakEndpoint())
117120
.newBuilder()
118121
.addPathSegments("auth")
119122
.addPathSegments("realms")
120-
.addPathSegments("master")
123+
.addPathSegments(realm)
121124
.addPathSegments("protocol")
122125
.addPathSegments("openid-connect")
123126
.addPathSegments("userinfo")

src/main/java/cd/go/authorization/keycloak/executors/GetPluginIconRequestExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ private String getContentType() {
4242
}
4343

4444
private String getIcon() {
45-
return "/keycloak.svg";
45+
return "/keycloak.png";
4646
}
4747
}

src/main/java/cd/go/authorization/keycloak/models/KeycloakConfiguration.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public class KeycloakConfiguration implements Validatable {
3333
@ProfileField(key = "KeycloakEndpoint", required = true, secure = false)
3434
private String keycloakEndpoint;
3535

36+
@Expose
37+
@SerializedName("KeycloakRealm")
38+
@ProfileField(key = "KeycloakRealm", required = true, secure = false)
39+
private String keycloakRealm;
40+
3641
@Expose
3742
@SerializedName("ClientId")
3843
@ProfileField(key = "ClientId", required = true, secure = false)
@@ -58,6 +63,10 @@ public String keycloakEndpoint() {
5863
return keycloakEndpoint;
5964
}
6065

66+
public String keycloakRealm() {
67+
return keycloakRealm;
68+
}
69+
6170
public String clientId() {
6271
return clientId;
6372
}

src/main/resources/auth-config.template.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@
9797
<span class="form_error form-error" ng-class="{'is-visible': GOINPUTNAME[KeycloakEndpoint].$error.server}" ng-show="GOINPUTNAME[KeycloakEndpoint].$error.server">{{GOINPUTNAME[KeycloakEndpoint].$error.server}}</span>
9898
</div>
9999

100+
<div class="form_item_block">
101+
<label ng-class="{'is-invalid-label': GOINPUTNAME[KeycloakRealm].$error.server}">Keycloak Realm:<span class='asterix'>*</span>
102+
<div class="tooltip-info">
103+
<span class="tooltip-content">
104+
Your Keycloak Realm.
105+
</span>
106+
</div>
107+
</label>
108+
<input ng-class="{'is-invalid-input': GOINPUTNAME[KeycloakRealm].$error.server}" type="text" ng-model="KeycloakRealm" ng-required="true"/>
109+
<span class="form_error form-error" ng-class="{'is-visible': GOINPUTNAME[KeycloakRealm].$error.server}" ng-show="GOINPUTNAME[KeycloakRealm].$error.server">{{GOINPUTNAME[KeycloakRealm].$error.server}}</span>
110+
</div>
111+
100112
<div class="form_item_block">
101113
<label ng-class="{'is-invalid-label': GOINPUTNAME[ClientId].$error.server}">Keycloak Client ID:<span class='asterix'>*</span>
102114
<div class="tooltip-info">

src/main/resources/keycloak.png

5.33 KB
Loading

0 commit comments

Comments
 (0)