Skip to content

Commit

Permalink
[CLOUDTRUST-2708] Add install.sh and fix some Sonar code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
fperot74 authored Nov 2, 2020
1 parent 4cd087e commit e7192fc
Show file tree
Hide file tree
Showing 65 changed files with 1,801 additions and 960 deletions.
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,46 @@ for its operations.

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

## How to Install
## How to build

Before building this project with a basic `mvn clean install`, you need to first build cloudtrust-common.

```Bash
git clone git@github.com:cloudtrust/cloudtrust-parent.git
cd cloudtrust-parent
mvn clean install
```

Then build keycloak-wsfed:

```Bash
git clone git@github.com:cloudtrust/keycloak-wsfed.git
cd keycloak-wsfed
mvn clean install
```

If you get an error telling `Could not find artifact org.keycloak.testsuite:integration-arquillian-tests:pom`, you might build Keycloak with:

```Bash
mvn install -Pconsole-ui-tests -DskipTests
```


## How to install

After building it, you can automatically install this module using the following command line:

```Bash
./keycloak-wsfed/install.sh {path-to-keycloak}
```

You can uninstall it with:

```Bash
./keycloak-wsfed/install.sh {path-to-keycloak} -u
```

But you can choose to manually install it:

### Copy files

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.quest.keycloak.common.wsfed.MockHelper;
import com.quest.keycloak.protocol.wsfed.builders.WSFedSAML2AssertionTypeBuilder;

import io.cloudtrust.keycloak.exceptions.CtRuntimeException;
import io.cloudtrust.exception.CloudtrustRuntimeException;

import org.junit.Test;
import org.keycloak.dom.saml.v2.assertion.AssertionType;
Expand Down Expand Up @@ -81,7 +81,7 @@ public void testInvalidSignature() throws Exception {
generator.initialize(2048);
keyPair = generator.generateKeyPair();
} catch (NoSuchAlgorithmException e) {
throw new CtRuntimeException(e);
throw new CloudtrustRuntimeException(e);
}

EventBuilder event = mock(EventBuilder.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.quest.keycloak.common.wsfed.WSFedConstants;
import com.quest.keycloak.protocol.wsfed.builders.RequestSecurityTokenResponseBuilder;

import io.cloudtrust.keycloak.exceptions.CtRuntimeException;
import io.cloudtrust.exception.CloudtrustRuntimeException;

import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -328,7 +328,7 @@ public void testHandleLoginResponseException() throws Exception {
when(token.getSessionIndex()).thenReturn("123");
when(token.getUsername()).thenReturn("username");

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

expectedException.expect(IdentityBrokerException.class);
expectedException.expectMessage(equalTo("Could not process response from WS-Fed identity provider."));
Expand Down Expand Up @@ -397,12 +397,12 @@ public void testHandleWsFedResponseBadSig() throws Exception {
generator.initialize(2048);
keyPair = generator.generateKeyPair();
} catch (NoSuchAlgorithmException e) {
throw new CtRuntimeException(e);
throw new CloudtrustRuntimeException(e);
}
try {
CertificateUtils.generateV1SelfSignedCertificate(keyPair, "junk");
} catch (Exception e) {
throw new CtRuntimeException(e);
throw new CloudtrustRuntimeException(e);
}
RequestSecurityTokenResponseBuilder builder = SAML2RequestedTokenTest.generateRequestSecurityTokenResponseBuilder(mockHelper);
when(config.isValidateSignature()).thenReturn(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.quest.keycloak.common.wsfed.TestHelpers.*;
import com.quest.keycloak.common.wsfed.WSFedConstants;

import io.cloudtrust.keycloak.exceptions.CtRuntimeException;
import io.cloudtrust.exception.CloudtrustRuntimeException;

import org.apache.http.HttpStatus;
import org.junit.Before;
Expand Down Expand Up @@ -84,7 +84,7 @@ public void testCallback() throws Exception {

@Test
public void testPerformLoginException() throws Exception {
doThrow(new CtRuntimeException("Message")).when(config).getWsFedRealm();
doThrow(new CloudtrustRuntimeException("Message")).when(config).getWsFedRealm();

expectedException.expect(IdentityBrokerException.class);
expectedException.expectMessage(equalTo("Could not create authentication request."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import io.cloudtrust.keycloak.exceptions.CtRuntimeException;
import io.cloudtrust.exception.CloudtrustRuntimeException;

import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
Expand Down Expand Up @@ -99,7 +99,7 @@ public class MockHelper {
@Mock
private AuthenticationSessionModel authSession;
@Mock
private ClientSessionCode accessCode;
private ClientSessionCode<?> accessCode;
@Mock
private UserSessionModel userSessionModel;

Expand Down Expand Up @@ -168,13 +168,13 @@ public static void generateActiveRealmKeys(KeyManager keyManager, KeyManager.Act
generator.initialize(2048);
keyPair = generator.generateKeyPair();
} catch (NoSuchAlgorithmException e) {
throw new CtRuntimeException(e);
throw new CloudtrustRuntimeException(e);
}
X509Certificate certificate = null;
try {
certificate = CertificateUtils.generateV1SelfSignedCertificate(keyPair, realm.getName());
} catch (Exception e) {
throw new CtRuntimeException(e);
throw new CloudtrustRuntimeException(e);
}

KeyWrapper activeKeyWrapper = new KeyWrapper();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.quest.keycloak.common.wsfed.parsers;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.function.Function;

import javax.xml.stream.XMLEventReader;

import org.picketlink.common.exceptions.ParsingException;
import org.picketlink.common.util.StaxParserUtil;

public abstract class AbstractParserTest {
@SuppressWarnings({ "unchecked" })
protected <T> T parseFile(String filename, Class<T> clazz, Function<String, String>... updaters) throws ParsingException, IOException {
return clazz.cast(new WSTrustParser().parse(getXMLEventReader(filename, updaters)));
}

protected InputStream getInputStream(String filename) {
InputStream stream = WSTRequestSecurityTokenResponseCollectionParserTest.class.getResourceAsStream(filename);
if (stream==null) {
try {
stream = new FileInputStream("src/test/resources"+filename);
} catch (IOException e) {
// Ignore
}
}
return stream;
}

@SuppressWarnings("unchecked")
protected XMLEventReader getXMLEventReader(String filename, Function<String, String>... updaters) throws IOException {
if (updaters==null) {
return StaxParserUtil.getXMLEventReader(getInputStream(filename));
}
String xml;
try (InputStream input = getInputStream(filename)) {
byte[] content = new byte[input.available()];
input.read(content);
xml = new String(content, StandardCharsets.UTF_8);
}
if (updaters!=null) {
for(Function<String, String> updater : updaters) {
xml = updater.apply(xml);
}
}
try (InputStream stream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))) {
return StaxParserUtil.getXMLEventReader(stream);
}
}
}
Loading

0 comments on commit e7192fc

Please sign in to comment.