Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from Acegi to Spring Security in tests #518

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -916,11 +916,11 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
}

/*
* Acegi has this notion that first an {@link org.acegisecurity.Authentication} object is created
* Acegi has this notion that first an {@link Authentication} object is created
* by collecting user information and then the act of authentication is done
* later (by {@link org.acegisecurity.AuthenticationManager}) to verify it. But in case of OpenID,
* we create an {@link org.acegisecurity.Authentication} only after we verified the user identity,
* so {@link org.acegisecurity.AuthenticationManager} becomes no-op.
* later (by {@link AuthenticationManager}) to verify it. But in case of OpenID,
* we create an {@link Authentication} only after we verified the user identity,
* so {@link AuthenticationManager} becomes no-op.
*/
@Override
public SecurityComponents createSecurityComponents() {
Expand Down
24 changes: 13 additions & 11 deletions src/test/java/org/jenkinsci/plugins/oic/OicSecurityRealmTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import hudson.util.Secret;
import org.acegisecurity.AuthenticationManager;
import org.acegisecurity.BadCredentialsException;
import org.acegisecurity.GrantedAuthority;
import org.acegisecurity.GrantedAuthorityImpl;
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
import org.acegisecurity.providers.anonymous.AnonymousAuthenticationToken;
import java.util.Collection;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.crypto.bcrypt.BCrypt;

import static org.junit.Assert.assertEquals;
Expand All @@ -24,7 +26,7 @@ public class OicSecurityRealmTest {

public static final String ADMIN = "admin";

private static final GrantedAuthorityImpl GRANTED_AUTH1 = new GrantedAuthorityImpl(ADMIN);
private static final SimpleGrantedAuthority GRANTED_AUTH1 = new SimpleGrantedAuthority(ADMIN);

@Rule
public WireMockRule wireMockRule = new WireMockRule(new WireMockConfiguration().dynamicPort(), true);
Expand All @@ -35,13 +37,13 @@ public class OicSecurityRealmTest {
@Test
public void testAuthenticate_withAnonymousAuthenticationToken() throws Exception {
TestRealm realm = new TestRealm(wireMockRule);
AuthenticationManager manager = realm.getSecurityComponents().manager;
AuthenticationManager manager = realm.getSecurityComponents().manager2;

assertNotNull(manager);

String key = "testKey";
Object principal = "testUser";
GrantedAuthority[] authorities = new GrantedAuthority[] {GRANTED_AUTH1};
Collection<GrantedAuthority> authorities = List.of(GRANTED_AUTH1);
AnonymousAuthenticationToken token = new AnonymousAuthenticationToken(key, principal, authorities);

assertEquals(token, manager.authenticate(token));
Expand All @@ -50,13 +52,13 @@ public void testAuthenticate_withAnonymousAuthenticationToken() throws Exception
@Test(expected = BadCredentialsException.class)
public void testAuthenticate_withUsernamePasswordAuthenticationToken() throws Exception {
TestRealm realm = new TestRealm(wireMockRule);
AuthenticationManager manager = realm.getSecurityComponents().manager;
AuthenticationManager manager = realm.getSecurityComponents().manager2;

assertNotNull(manager);

String key = "testKey";
Object principal = "testUser";
GrantedAuthority[] authorities = new GrantedAuthority[] {GRANTED_AUTH1};
Collection<GrantedAuthority> authorities = List.of(GRANTED_AUTH1);
UsernamePasswordAuthenticationToken token =
new UsernamePasswordAuthenticationToken(key, principal, authorities);

Expand Down
Loading