Skip to content

Commit

Permalink
commit spnego changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoayyed committed Mar 28, 2022
2 parents ab0e3d5 + 4838eef commit 6d500f5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.apereo.cas.support.spnego.authentication.principal;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apereo.cas.authentication.Credential;
import org.apereo.cas.authentication.principal.Principal;

Expand Down Expand Up @@ -45,12 +46,14 @@ public class SpnegoCredential implements Credential {
* The SPNEGO Init Token.
*/
@ToString.Exclude
@JsonIgnore
private byte[] initToken;

/**
* The SPNEGO Next Token.
*/
@ToString.Exclude
@JsonIgnore
private byte[] nextToken;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package org.apereo.cas.support.spnego.authentication.principal;

import org.apereo.cas.authentication.principal.PrincipalFactoryUtils;
import org.apereo.cas.util.serialization.JacksonObjectMapperFactory;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.val;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.junit.jupiter.api.Assertions.*;

/**
Expand All @@ -15,6 +19,8 @@
*/
@Tag("Spnego")
public class SpnegoCredentialsTests {
private static final ObjectMapper MAPPER = JacksonObjectMapperFactory.builder()
.defaultTypingEnabled(false).build().toObjectMapper();

@Test
public void verifyToStringWithNoPrincipal() {
Expand Down Expand Up @@ -42,4 +48,21 @@ public void verifyPrincipalAffectsHash() {
val hash2 = credential.hashCode();
assertNotEquals(hash1, hash2);
}
}

@Test
public void verifyToStringWithToken() {
val credentials = new SpnegoCredential(new byte[16]);
credentials.setNextToken(new byte[16]);
assertThat(credentials.toString(), not(containsString("initToken")));
assertThat(credentials.toString(), not(containsString("nextToken")));
}

@Test
public void verifyJsonWithToken() throws Exception {
val credentials = new SpnegoCredential(new byte[16]);
credentials.setNextToken(new byte[16]);
assertThat(MAPPER.writeValueAsString(credentials), not(containsString("initToken")));
assertThat(MAPPER.writeValueAsString(credentials), not(containsString("nextToken")));
}

}

0 comments on commit 6d500f5

Please sign in to comment.