diff --git a/src/main/java/hudson/plugins/collabnet/auth/CNFilter.java b/src/main/java/hudson/plugins/collabnet/auth/CNFilter.java index bf3632b..a9b0c9d 100644 --- a/src/main/java/hudson/plugins/collabnet/auth/CNFilter.java +++ b/src/main/java/hudson/plugins/collabnet/auth/CNFilter.java @@ -18,12 +18,14 @@ import hudson.plugins.collabnet.util.CommonUtil; import hudson.security.SecurityRealm; +import jenkins.security.SecurityListener; import org.acegisecurity.Authentication; import org.acegisecurity.GrantedAuthority; import org.acegisecurity.GrantedAuthorityImpl; import org.acegisecurity.context.SecurityContextHolder; import org.acegisecurity.providers.anonymous.AnonymousAuthenticationToken; +import org.acegisecurity.userdetails.UserDetails; import org.apache.commons.lang3.StringUtils; import com.collabnet.ce.webservices.CollabNetApp; @@ -132,6 +134,9 @@ private void loginHudsonUsingCTFSSO(CollabNetSecurityRealm securityRealm, HttpSe // see artf42298 request.getSession(true); SecurityContextHolder.getContext().setAuthentication(auth); + + UserDetails userDetails = new CNUserDetails(auth.getName(), auth.getAuthorities()); + SecurityListener.fireAuthenticated(userDetails); } /** diff --git a/src/main/java/hudson/plugins/collabnet/auth/CNUserDetails.java b/src/main/java/hudson/plugins/collabnet/auth/CNUserDetails.java new file mode 100644 index 0000000..ad262cd --- /dev/null +++ b/src/main/java/hudson/plugins/collabnet/auth/CNUserDetails.java @@ -0,0 +1,36 @@ +/* + * The MIT License + * + * Copyright (c) 2019, CloudBees, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package hudson.plugins.collabnet.auth; + +import org.acegisecurity.GrantedAuthority; +import org.acegisecurity.userdetails.User; +import org.kohsuke.accmod.Restricted; +import org.kohsuke.accmod.restrictions.NoExternalUse; + +@Restricted(NoExternalUse.class) +public class CNUserDetails extends User { + public CNUserDetails(String username, GrantedAuthority[] authorities) throws IllegalArgumentException { + super(username, "", true, true, true, true, authorities); + } +}