Skip to content

Commit 4bc3b59

Browse files
committed
Add support for OAuth 2.0 Token Exchange Grant
Issue spring-projectsgh-60
1 parent a04b336 commit 4bc3b59

15 files changed

+1101
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2020-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.oauth2.server.authorization.authentication;
18+
19+
import java.io.Serializable;
20+
import java.util.Collections;
21+
22+
import org.springframework.security.authentication.AbstractAuthenticationToken;
23+
import org.springframework.util.Assert;
24+
25+
/**
26+
* @author Steve Riesenberg
27+
*/
28+
public class OAuth2ActorAuthenticationToken extends AbstractAuthenticationToken implements Serializable {
29+
30+
private final String name;
31+
32+
public OAuth2ActorAuthenticationToken(String name) {
33+
super(Collections.emptyList());
34+
Assert.hasText(name, "name cannot be empty");
35+
this.name = name;
36+
}
37+
38+
@Override
39+
public Object getPrincipal() {
40+
return this.name;
41+
}
42+
43+
@Override
44+
public Object getCredentials() {
45+
return null;
46+
}
47+
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2020-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.oauth2.server.authorization.authentication;
18+
19+
import java.io.Serializable;
20+
import java.util.ArrayList;
21+
import java.util.Collections;
22+
import java.util.List;
23+
24+
import org.springframework.security.authentication.AbstractAuthenticationToken;
25+
import org.springframework.security.core.Authentication;
26+
import org.springframework.util.Assert;
27+
28+
/**
29+
* @author Steve Riesenberg
30+
*/
31+
public class OAuth2CompositeAuthenticationToken extends AbstractAuthenticationToken implements Serializable {
32+
33+
private final Authentication subject;
34+
35+
private final List<Authentication> actors;
36+
37+
public OAuth2CompositeAuthenticationToken(Authentication subject, List<Authentication> actors) {
38+
super(subject.getAuthorities());
39+
Assert.notNull(subject, "subject cannot be null");
40+
Assert.notNull(actors, "actors cannot be null");
41+
this.subject = subject;
42+
this.actors = Collections.unmodifiableList(new ArrayList<>(actors));
43+
setDetails(subject.getDetails());
44+
setAuthenticated(subject.isAuthenticated());
45+
}
46+
47+
@Override
48+
public Object getPrincipal() {
49+
return this.subject.getPrincipal();
50+
}
51+
52+
@Override
53+
public Object getCredentials() {
54+
return null;
55+
}
56+
57+
public Authentication getSubject() {
58+
return this.subject;
59+
}
60+
61+
public List<Authentication> getActors() {
62+
return this.actors;
63+
}
64+
}

0 commit comments

Comments
 (0)