Skip to content

Commit e7192fc

Browse files
authored
[CLOUDTRUST-2708] Add install.sh and fix some Sonar code smells
1 parent 4cd087e commit e7192fc

File tree

65 files changed

+1801
-960
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1801
-960
lines changed

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,46 @@ for its operations.
1515

1616
This module is currently working on 8.0.1 (check tags for compatibility with previous Keycloak versions)
1717

18-
## How to Install
18+
## How to build
19+
20+
Before building this project with a basic `mvn clean install`, you need to first build cloudtrust-common.
21+
22+
```Bash
23+
git clone git@github.com:cloudtrust/cloudtrust-parent.git
24+
cd cloudtrust-parent
25+
mvn clean install
26+
```
27+
28+
Then build keycloak-wsfed:
29+
30+
```Bash
31+
git clone git@github.com:cloudtrust/keycloak-wsfed.git
32+
cd keycloak-wsfed
33+
mvn clean install
34+
```
35+
36+
If you get an error telling `Could not find artifact org.keycloak.testsuite:integration-arquillian-tests:pom`, you might build Keycloak with:
37+
38+
```Bash
39+
mvn install -Pconsole-ui-tests -DskipTests
40+
```
41+
42+
43+
## How to install
44+
45+
After building it, you can automatically install this module using the following command line:
46+
47+
```Bash
48+
./keycloak-wsfed/install.sh {path-to-keycloak}
49+
```
50+
51+
You can uninstall it with:
52+
53+
```Bash
54+
./keycloak-wsfed/install.sh {path-to-keycloak} -u
55+
```
56+
57+
But you can choose to manually install it:
1958

2059
### Copy files
2160

keycloak-wsfed-tests/src/test/java/com/quest/keycloak/broker/wsfed/SAML2RequestedTokenTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import com.quest.keycloak.common.wsfed.MockHelper;
2323
import com.quest.keycloak.protocol.wsfed.builders.WSFedSAML2AssertionTypeBuilder;
2424

25-
import io.cloudtrust.keycloak.exceptions.CtRuntimeException;
25+
import io.cloudtrust.exception.CloudtrustRuntimeException;
2626

2727
import org.junit.Test;
2828
import org.keycloak.dom.saml.v2.assertion.AssertionType;
@@ -81,7 +81,7 @@ public void testInvalidSignature() throws Exception {
8181
generator.initialize(2048);
8282
keyPair = generator.generateKeyPair();
8383
} catch (NoSuchAlgorithmException e) {
84-
throw new CtRuntimeException(e);
84+
throw new CloudtrustRuntimeException(e);
8585
}
8686

8787
EventBuilder event = mock(EventBuilder.class);

keycloak-wsfed-tests/src/test/java/com/quest/keycloak/broker/wsfed/WSFedEndpointTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.quest.keycloak.common.wsfed.WSFedConstants;
2222
import com.quest.keycloak.protocol.wsfed.builders.RequestSecurityTokenResponseBuilder;
2323

24-
import io.cloudtrust.keycloak.exceptions.CtRuntimeException;
24+
import io.cloudtrust.exception.CloudtrustRuntimeException;
2525

2626
import org.junit.Before;
2727
import org.junit.Rule;
@@ -328,7 +328,7 @@ public void testHandleLoginResponseException() throws Exception {
328328
when(token.getSessionIndex()).thenReturn("123");
329329
when(token.getUsername()).thenReturn("username");
330330

331-
when(callback.authenticated(any(BrokeredIdentityContext.class))).thenThrow(new CtRuntimeException("Exception"));
331+
when(callback.authenticated(any(BrokeredIdentityContext.class))).thenThrow(new CloudtrustRuntimeException("Exception"));
332332

333333
expectedException.expect(IdentityBrokerException.class);
334334
expectedException.expectMessage(equalTo("Could not process response from WS-Fed identity provider."));
@@ -397,12 +397,12 @@ public void testHandleWsFedResponseBadSig() throws Exception {
397397
generator.initialize(2048);
398398
keyPair = generator.generateKeyPair();
399399
} catch (NoSuchAlgorithmException e) {
400-
throw new CtRuntimeException(e);
400+
throw new CloudtrustRuntimeException(e);
401401
}
402402
try {
403403
CertificateUtils.generateV1SelfSignedCertificate(keyPair, "junk");
404404
} catch (Exception e) {
405-
throw new CtRuntimeException(e);
405+
throw new CloudtrustRuntimeException(e);
406406
}
407407
RequestSecurityTokenResponseBuilder builder = SAML2RequestedTokenTest.generateRequestSecurityTokenResponseBuilder(mockHelper);
408408
when(config.isValidateSignature()).thenReturn(true);

keycloak-wsfed-tests/src/test/java/com/quest/keycloak/broker/wsfed/WSFedIdentityProviderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.quest.keycloak.common.wsfed.TestHelpers.*;
2121
import com.quest.keycloak.common.wsfed.WSFedConstants;
2222

23-
import io.cloudtrust.keycloak.exceptions.CtRuntimeException;
23+
import io.cloudtrust.exception.CloudtrustRuntimeException;
2424

2525
import org.apache.http.HttpStatus;
2626
import org.junit.Before;
@@ -84,7 +84,7 @@ public void testCallback() throws Exception {
8484

8585
@Test
8686
public void testPerformLoginException() throws Exception {
87-
doThrow(new CtRuntimeException("Message")).when(config).getWsFedRealm();
87+
doThrow(new CloudtrustRuntimeException("Message")).when(config).getWsFedRealm();
8888

8989
expectedException.expect(IdentityBrokerException.class);
9090
expectedException.expectMessage(equalTo("Could not create authentication request."));

keycloak-wsfed-tests/src/test/java/com/quest/keycloak/common/wsfed/MockHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import org.mockito.invocation.InvocationOnMock;
4242
import org.mockito.stubbing.Answer;
4343

44-
import io.cloudtrust.keycloak.exceptions.CtRuntimeException;
44+
import io.cloudtrust.exception.CloudtrustRuntimeException;
4545

4646
import javax.crypto.SecretKey;
4747
import javax.crypto.spec.SecretKeySpec;
@@ -99,7 +99,7 @@ public class MockHelper {
9999
@Mock
100100
private AuthenticationSessionModel authSession;
101101
@Mock
102-
private ClientSessionCode accessCode;
102+
private ClientSessionCode<?> accessCode;
103103
@Mock
104104
private UserSessionModel userSessionModel;
105105

@@ -168,13 +168,13 @@ public static void generateActiveRealmKeys(KeyManager keyManager, KeyManager.Act
168168
generator.initialize(2048);
169169
keyPair = generator.generateKeyPair();
170170
} catch (NoSuchAlgorithmException e) {
171-
throw new CtRuntimeException(e);
171+
throw new CloudtrustRuntimeException(e);
172172
}
173173
X509Certificate certificate = null;
174174
try {
175175
certificate = CertificateUtils.generateV1SelfSignedCertificate(keyPair, realm.getName());
176176
} catch (Exception e) {
177-
throw new CtRuntimeException(e);
177+
throw new CloudtrustRuntimeException(e);
178178
}
179179

180180
KeyWrapper activeKeyWrapper = new KeyWrapper();
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.quest.keycloak.common.wsfed.parsers;
2+
3+
import java.io.ByteArrayInputStream;
4+
import java.io.FileInputStream;
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
import java.nio.charset.StandardCharsets;
8+
import java.util.function.Function;
9+
10+
import javax.xml.stream.XMLEventReader;
11+
12+
import org.picketlink.common.exceptions.ParsingException;
13+
import org.picketlink.common.util.StaxParserUtil;
14+
15+
public abstract class AbstractParserTest {
16+
@SuppressWarnings({ "unchecked" })
17+
protected <T> T parseFile(String filename, Class<T> clazz, Function<String, String>... updaters) throws ParsingException, IOException {
18+
return clazz.cast(new WSTrustParser().parse(getXMLEventReader(filename, updaters)));
19+
}
20+
21+
protected InputStream getInputStream(String filename) {
22+
InputStream stream = WSTRequestSecurityTokenResponseCollectionParserTest.class.getResourceAsStream(filename);
23+
if (stream==null) {
24+
try {
25+
stream = new FileInputStream("src/test/resources"+filename);
26+
} catch (IOException e) {
27+
// Ignore
28+
}
29+
}
30+
return stream;
31+
}
32+
33+
@SuppressWarnings("unchecked")
34+
protected XMLEventReader getXMLEventReader(String filename, Function<String, String>... updaters) throws IOException {
35+
if (updaters==null) {
36+
return StaxParserUtil.getXMLEventReader(getInputStream(filename));
37+
}
38+
String xml;
39+
try (InputStream input = getInputStream(filename)) {
40+
byte[] content = new byte[input.available()];
41+
input.read(content);
42+
xml = new String(content, StandardCharsets.UTF_8);
43+
}
44+
if (updaters!=null) {
45+
for(Function<String, String> updater : updaters) {
46+
xml = updater.apply(xml);
47+
}
48+
}
49+
try (InputStream stream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))) {
50+
return StaxParserUtil.getXMLEventReader(stream);
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)