-
Notifications
You must be signed in to change notification settings - Fork 741
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from ttomsu/google-oauth-multi
Make all configs use SpinnakerUserDetails
- Loading branch information
Showing
9 changed files
with
140 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
gate-web/src/main/groovy/com/netflix/spinnaker/gate/security/SpinnakerUserDetails.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2016 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.gate.security | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore | ||
import com.netflix.spinnaker.security.User | ||
import groovy.transform.Canonical | ||
import org.springframework.security.core.authority.SimpleGrantedAuthority | ||
import org.springframework.security.core.userdetails.UserDetails | ||
|
||
@Canonical | ||
class SpinnakerUserDetails implements UserDetails { | ||
User spinnakerUser | ||
|
||
@Override | ||
List getAuthorities() { | ||
spinnakerUser?.roles?.collect { new SimpleGrantedAuthority(it) } | ||
} | ||
|
||
/** Not used **/ | ||
@JsonIgnore String username | ||
@JsonIgnore String password | ||
|
||
@Override | ||
boolean isAccountNonExpired() { return true } | ||
|
||
@Override | ||
boolean isAccountNonLocked() { return true } | ||
|
||
@Override | ||
boolean isCredentialsNonExpired() { return true } | ||
|
||
@Override | ||
boolean isEnabled() { return true } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...oovy/com/netflix/spinnaker/gate/security/x509/X509AuthenticationUserDetailsService.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2016 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.gate.security.x509 | ||
|
||
import com.netflix.spinnaker.gate.security.AnonymousAccountsService | ||
import com.netflix.spinnaker.gate.security.SpinnakerUserDetails | ||
import com.netflix.spinnaker.security.User | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.security.core.userdetails.AuthenticationUserDetailsService | ||
import org.springframework.security.core.userdetails.UserDetails | ||
import org.springframework.security.core.userdetails.UsernameNotFoundException | ||
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken | ||
import org.springframework.stereotype.Component | ||
|
||
import java.security.cert.X509Certificate | ||
|
||
/** | ||
* This class is similar to a UserDetailService, but instead of passing in a username to loadUserDetails, | ||
* it passess in a token containing the x509 certificate. A user can control the principal through the | ||
* `spring.x509.subjectPrincipalRegex` property. | ||
*/ | ||
@Component | ||
class X509AuthenticationUserDetailsService implements AuthenticationUserDetailsService<PreAuthenticatedAuthenticationToken> { | ||
|
||
@Autowired | ||
AnonymousAccountsService anonymousAccountsService | ||
|
||
@Override | ||
UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token) throws UsernameNotFoundException { | ||
if (!(token.credentials instanceof X509Certificate)) { | ||
return null | ||
} | ||
|
||
return new SpinnakerUserDetails( | ||
spinnakerUser: new User(email: token.principal, | ||
allowedAccounts: anonymousAccountsService.allowedAccounts)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters