use of org.finos.legend.sdlc.server.auth.Token.TokenReader in project legend-sdlc by finos.
the class TestToken method testBytes.
@Test
public void testBytes() {
TokenBuilder builder = Token.newBuilder();
for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) {
builder.putByte(b);
}
builder.putByte(Byte.MAX_VALUE);
String tokenString = builder.toTokenString();
assertIsURLSafe(tokenString);
TokenReader reader = Token.newReader(tokenString);
for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) {
Assert.assertEquals(b, reader.getByte());
}
Assert.assertEquals(Byte.MAX_VALUE, reader.getByte());
Assert.assertFalse(reader.hasRemaining());
}
use of org.finos.legend.sdlc.server.auth.Token.TokenReader in project legend-sdlc by finos.
the class TestToken method testMixedTypes.
@Test
public void testMixedTypes() {
Object[] objects = { 0, true, "aa0b05f2c8", 5, Integer.MAX_VALUE, "", false, "the quick brown fox jumped over the lazy dog" };
TokenBuilder builder = Token.newBuilder();
for (Object object : objects) {
if (object instanceof Integer) {
builder.putInt((Integer) object);
} else if (object instanceof Boolean) {
builder.putBoolean((Boolean) object);
} else if (object instanceof String) {
builder.putString((String) object);
} else {
throw new RuntimeException("Unhandled: " + object);
}
}
String tokenString = builder.toTokenString();
assertIsURLSafe(tokenString);
TokenReader reader = Token.newReader(tokenString);
for (Object expected : objects) {
Object actual;
if (expected instanceof Integer) {
actual = reader.getInt();
} else if (expected instanceof Boolean) {
actual = reader.getBoolean();
} else if (expected instanceof String) {
actual = reader.getString();
} else {
throw new RuntimeException("Unhandled: " + expected);
}
Assert.assertEquals(expected, actual);
}
Assert.assertFalse(reader.hasRemaining());
}
use of org.finos.legend.sdlc.server.auth.Token.TokenReader in project legend-sdlc by finos.
the class TestToken method testBooleans.
@Test
public void testBooleans() {
TokenBuilder builder = Token.newBuilder();
builder.putBoolean(true);
builder.putBoolean(false);
String tokenString = builder.toTokenString();
assertIsURLSafe(tokenString);
TokenReader reader = Token.newReader(tokenString);
Assert.assertTrue(reader.getBoolean());
Assert.assertFalse(reader.getBoolean());
Assert.assertFalse(reader.hasRemaining());
}
use of org.finos.legend.sdlc.server.auth.Token.TokenReader in project legend-sdlc by finos.
the class TestToken method testShorts.
@Test
public void testShorts() {
TokenBuilder builder = Token.newBuilder();
for (short s = Short.MIN_VALUE; s < Short.MAX_VALUE; s++) {
builder.putShort(s);
}
builder.putShort(Short.MAX_VALUE);
String tokenString = builder.toTokenString();
assertIsURLSafe(tokenString);
TokenReader reader = Token.newReader(tokenString);
for (short s = Short.MIN_VALUE; s < Short.MAX_VALUE; s++) {
Assert.assertEquals(s, reader.getShort());
}
Assert.assertEquals(Short.MAX_VALUE, reader.getShort());
Assert.assertFalse(reader.hasRemaining());
}
use of org.finos.legend.sdlc.server.auth.Token.TokenReader in project legend-sdlc by finos.
the class GitLabAuthResource method processAuthCallback.
private Object processAuthCallback(String code, String state) {
TokenReader reader = Token.newReader(state);
String gitLabModeName = reader.getString();
String originalRequestMethod = reader.getString();
String originalRequestURL = reader.getString();
GitLabMode mode;
try {
mode = GitLabMode.valueOf(gitLabModeName);
} catch (IllegalArgumentException e) {
throw new LegendSDLCServerException("Unknown GitLab mode: " + gitLabModeName, Status.INTERNAL_SERVER_ERROR);
}
try {
this.userContext.gitLabAuthCallback(mode, code);
} catch (LegendSDLCServerException e) {
throw e;
} catch (Exception e) {
StringBuilder message = new StringBuilder("Error processing auth callback");
String eMessage = e.getMessage();
if (eMessage != null) {
message.append(": ").append(eMessage);
}
throw new LegendSDLCServerException(message.toString(), Status.INTERNAL_SERVER_ERROR, e);
}
if (!"GET".equalsIgnoreCase(originalRequestMethod)) {
// TODO consider whether 503 is the right status code
throw new LegendSDLCServerException("Please retry request: " + originalRequestMethod + " " + originalRequestURL, Status.SERVICE_UNAVAILABLE);
}
// Redirect to original request URL
throw new LegendSDLCServerException(originalRequestURL, Status.FOUND);
}
Aggregations