本文整理汇总了Java中org.osiam.client.oauth.AccessToken类的典型用法代码示例。如果您正苦于以下问题:Java AccessToken类的具体用法?Java AccessToken怎么用?Java AccessToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AccessToken类属于org.osiam.client.oauth包,在下文中一共展示了AccessToken类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: validateToken
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
@RequestMapping(value = "/validation", method = RequestMethod.POST)
@ResponseBody
public AccessToken validateToken(@RequestHeader("Authorization") final String authorization) {
String token = getToken(authorization);
OAuth2Authentication auth = tokenStore.readAuthentication(token);
OAuth2AccessToken accessToken = tokenStore.getAccessToken(auth);
OAuth2Request authReq = auth.getOAuth2Request();
AccessToken.Builder tokenBuilder = new AccessToken.Builder(token).setClientId(authReq.getClientId());
if (auth.getUserAuthentication() != null && auth.getPrincipal() instanceof User) {
User user = (User) auth.getPrincipal();
tokenBuilder.setUserName(user.getUserName());
tokenBuilder.setUserId(user.getId());
}
tokenBuilder.setExpiresAt(accessToken.getExpiration());
for (String scopeString : authReq.getScope()) {
tokenBuilder.addScope(new Scope(scopeString));
}
return tokenBuilder.build();
}
开发者ID:osiam,项目名称:auth-server,代码行数:24,代码来源:TokenController.java
示例2: createAccessToken
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
public AccessToken createAccessToken() {
Set<String> scopes = new HashSet<>();
scopes.add(Scope.ADMIN.toString());
// Random scope, because the token services generates for every scope but same client
// a different access token. This is only made due to the token expired problem, when the auth server
// takes his actual access token, but the token is expired during the request to the resource server
scopes.add(new Scope(UUID.randomUUID().toString()).toString());
Map<String, String> parameters = new HashMap<>();
parameters.put("client_id", OsiamAuthServerClientProvider.AUTH_SERVER_CLIENT_ID);
OAuth2Request authRequest = new OAuth2Request(
parameters, OsiamAuthServerClientProvider.AUTH_SERVER_CLIENT_ID, null, true, scopes,
null, null, null, null
);
OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(authRequest, null);
OAuth2AccessToken oAuth2AccessToken = new DefaultOAuth2AccessToken(UUID.randomUUID().toString());
tokenStore.storeAccessToken(oAuth2AccessToken, oAuth2Authentication);
return new AccessToken.Builder(oAuth2AccessToken.getValue()).build();
}
开发者ID:osiam,项目名称:auth-server,代码行数:24,代码来源:OsiamAccessTokenProvider.java
示例3: validateToken
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
public AccessToken validateToken(final String token) {
OAuth2Authentication auth = tokenStore.readAuthentication(token);
OAuth2AccessToken accessToken = tokenStore.getAccessToken(auth);
OAuth2Request authReq = auth.getOAuth2Request();
AccessToken.Builder tokenBuilder = new AccessToken.Builder(token).setClientId(authReq.getClientId());
if (auth.getUserAuthentication() != null && auth.getPrincipal() instanceof User) {
User user = (User) auth.getPrincipal();
tokenBuilder.setUserName(user.getUserName());
tokenBuilder.setUserId(user.getId());
}
tokenBuilder.setExpiresAt(accessToken.getExpiration());
for (String scopeString : authReq.getScope()) {
tokenBuilder.addScope(new Scope(scopeString));
}
return tokenBuilder.build();
}
开发者ID:osiam,项目名称:osiam,代码行数:21,代码来源:TokenService.java
示例4: loadAuthentication
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
@Override
public OAuth2Authentication loadAuthentication(String token) {
AccessToken accessToken = validateAccessToken(token);
Set<String> scopes = new HashSet<>();
if (accessToken.getScopes() != null) {
for (Scope scope : accessToken.getScopes()) {
scopes.add(scope.toString());
}
}
Map<String, String> parameters = new HashMap<>();
parameters.put(AccessTokenConverter.CLIENT_ID, accessToken.getClientId());
OAuth2Request authRequest = new OAuth2Request(parameters, accessToken.getClientId(), null, true, scopes, null, null,
null, null);
Authentication auth = null;
if (!accessToken.isClientOnly()) {
User authUser = new User.Builder(accessToken.getUserName()).setId(accessToken.getUserId()).build();
auth = new UsernamePasswordAuthenticationToken(authUser, null, new ArrayList<GrantedAuthority>());
}
return new OAuth2Authentication(authRequest, auth);
}
开发者ID:osiam,项目名称:resource-server,代码行数:27,代码来源:AccessTokenValidationService.java
示例5: readAccessToken
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
@Override
public OAuth2AccessToken readAccessToken(String token) {
AccessToken accessToken = validateAccessToken(token);
Set<String> scopes = new HashSet<>();
for (Scope scope : accessToken.getScopes()) {
scopes.add(scope.toString());
}
DefaultOAuth2AccessToken oAuth2AccessToken = new DefaultOAuth2AccessToken(token);
oAuth2AccessToken.setScope(scopes);
oAuth2AccessToken.setExpiration(accessToken.getExpiresAt());
oAuth2AccessToken.setTokenType(DefaultOAuth2AccessToken.BEARER_TYPE);
return oAuth2AccessToken;
}
开发者ID:osiam,项目名称:resource-server,代码行数:17,代码来源:AccessTokenValidationService.java
示例6: convertOutput
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
@Override
public Object convertOutput(Object toBeFormatted) {
if(toBeFormatted instanceof AccessToken){
final AccessToken at = ((AccessToken)toBeFormatted);
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
StringBuilder sb = new StringBuilder();
sb.append("Token: ");
sb.append(at.getToken());
sb.append("\nType: ");
sb.append(at.getType());
sb.append("\nExpires: ");
sb.append(sdf.format(at.getExpiresAt()));
return sb;
}
return null;
}
开发者ID:osiam,项目名称:shell,代码行数:21,代码来源:AccessTokenConverter.java
示例7: testRemoveUserFromGroup
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
@Test
public void testRemoveUserFromGroup() {
List<Group> groups = new ArrayList<Group>();
groups.add(new Group.Builder("group").build());
SCIMSearchResult<Group> result = mock(SCIMSearchResult.class);
when(result.getResources()).thenReturn(groups);
when(con.searchGroups(eq(OsiamContext.createGroupFilter("group")), any(AccessToken.class))).thenReturn(result);
assertFalse(oc.removeUserFromGroup("user", "group"));
List<GroupRef> groupRefs = new ArrayList<GroupRef>();
groupRefs.add(new GroupRef.Builder().setDisplay("group").build());
User groupUser = new User.Builder("user").setId("userid").setGroups(groupRefs).build();
List<User> users = new ArrayList<User>();
users.add(groupUser);
SCIMSearchResult<User> result2 = mock(SCIMSearchResult.class);
when(result2.getResources()).thenReturn(users);
when(con.searchUsers(eq(OsiamContext.createUserFilter("user")), any(AccessToken.class))).thenReturn(result2);
assertTrue(oc.removeUserFromGroup("user", "group"));
}
开发者ID:osiam,项目名称:osiam-dropwizard,代码行数:24,代码来源:OsiamContextTest.java
示例8: testCreateGroup
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
@Test
public void testCreateGroup() {
List<Group> groups = new ArrayList<Group>();
SCIMSearchResult<Group> result = mock(SCIMSearchResult.class);
when(result.getResources()).thenReturn(groups);
when(con.searchGroups(eq(OsiamContext.createGroupFilter("group")), any(AccessToken.class))).thenReturn(result);
Group group = new Group.Builder("group").build();
when(con.createGroup(eq(group), any(AccessToken.class))).thenReturn(group);
// if group does not exist, we can create it and new group is returned
assertEquals(group, oc.createGroup(group));
groups.add(group);
// if group already exists, null is returned.
assertNull(oc.createGroup(group));
}
开发者ID:osiam,项目名称:osiam-dropwizard,代码行数:20,代码来源:OsiamContextTest.java
示例9: testGetUsersInGroup
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
@Test
public void testGetUsersInGroup() {
List<User> users = new ArrayList<User>();
List<GroupRef> groupA = new ArrayList<GroupRef>();
groupA.add(new GroupRef.Builder().setDisplay("groupA").build());
List<GroupRef> groupB = new ArrayList<GroupRef>();
groupB.add(new GroupRef.Builder().setDisplay("groupB").build());
users.add(new User.Builder("user1").setGroups(groupA).build());
users.add(new User.Builder("user2").setGroups(groupB).build());
when(con.getAllUsers(any(AccessToken.class))).thenReturn(new ArrayList(users));
List<User> result = oc.getUsersWithGroup("groupA", false);
assertEquals(1, result.size());
assertEquals("user1", result.get(0).getUserName());
when(con.getAllUsers(any(AccessToken.class))).thenReturn(new ArrayList(users));
result = oc.getUsersWithGroup("groupA", true);
assertEquals(1, result.size());
assertEquals("user2", result.get(0).getUserName());
}
开发者ID:osiam,项目名称:osiam-dropwizard,代码行数:26,代码来源:OsiamContextTest.java
示例10: testOAuth
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
@Test
public void testOAuth() {
OsiamConnector.Builder bldr = mock(OsiamConnector.Builder.class);
when(bldr.setGrantType(any(GrantType.class))).thenReturn(bldr);
when(bldr.setScope(any(Scope.class))).thenReturn(bldr);
when(bldr.setClientRedirectUri(anyString())).thenReturn(bldr);
OsiamConnector con = mock(OsiamConnector.class);
when(bldr.build()).thenReturn(con);
AccessToken at = new SimpleAccessToken("accesstoken");
when(con.retrieveAccessToken(eq("authcode"))).thenReturn(at);
when(od.getBuilder()).thenReturn(bldr);
Response r = or.oauth2("authcode", "state");
NewCookie c = (NewCookie)r.getMetadata().getFirst("Set-Cookie");
assertEquals(c.getValue(), "accesstoken");
URI u = (URI)r.getMetadata().getFirst("Location");
assertEquals(u.toString(), "http://state");
}
开发者ID:osiam,项目名称:osiam-dropwizard,代码行数:22,代码来源:OsiamResourceTest.java
示例11: getCurrentUserBasic
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
/**
* See {@link OsiamConnector#getCurrentUserBasic(AccessToken)}
*
* @deprecated The BasicUser class has been deprecated. Use {@link #getMe(AccessToken)} with OSIAM 3.x. This method
* is going to go away with version 1.12 or 2.0.
*/
@Deprecated
BasicUser getCurrentUserBasic(AccessToken accessToken) {
checkAccessTokenIsNotNull(accessToken);
StatusType status;
String content;
try {
Response response = targetEndpoint.path("me").request(MediaType.APPLICATION_JSON)
.header("Authorization", BEARER + accessToken.getToken())
.property(ClientProperties.CONNECT_TIMEOUT, getConnectTimeout())
.property(ClientProperties.READ_TIMEOUT, getReadTimeout())
.get();
status = response.getStatusInfo();
content = response.readEntity(String.class);
} catch (ProcessingException e) {
throw new ConnectionInitializationException(CONNECTION_SETUP_ERROR_STRING, e);
}
checkAndHandleResponse(content, status, accessToken);
return mapToType(content, BasicUser.class);
}
开发者ID:osiam,项目名称:connector4java,代码行数:30,代码来源:OsiamUserService.java
示例12: can_replace_other_user
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
@Test
public void can_replace_other_user() {
AccessToken accessToken = OSIAM_CONNECTOR.retrieveAccessToken("marissa", "koala", Scope.ADMIN);
User originalUser = OSIAM_CONNECTOR.getUser(OTHER_USER_ID, accessToken);
Email email = new Email.Builder()
.setValue("[email protected]")
.setType(Email.Type.HOME)
.build();
User replaceUser = new User.Builder(originalUser)
.setDisplayName("Barbara")
.setActive(false)
.addEmail(email)
.build();
User user = OSIAM_CONNECTOR.replaceUser(OTHER_USER_ID, replaceUser, accessToken);
assertThat(user.getDisplayName(), is(equalTo("Barbara")));
assertThat(user.isActive(), is(equalTo(false)));
assertThat(user.getEmails().get(0).getValue(), is(equalTo("[email protected]")));
assertThat(user.getEmails().get(0).getType(), is(equalTo(Email.Type.HOME)));
}
开发者ID:osiam,项目名称:connector4java-integration-tests,代码行数:22,代码来源:AdminScopeIT.java
示例13: deleteResource
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
void deleteResource(String id, AccessToken accessToken) {
checkArgument(!Strings.isNullOrEmpty(id), "The given id must not be null nor empty.");
checkAccessTokenIsNotNull(accessToken);
StatusType status;
String content;
try {
Response response = targetEndpoint.path(typeName + "s").path(id).request(MediaType.APPLICATION_JSON)
.header(AUTHORIZATION, BEARER + accessToken.getToken())
.property(ClientProperties.CONNECT_TIMEOUT, connectTimeout)
.property(ClientProperties.READ_TIMEOUT, readTimeout)
.delete();
status = response.getStatusInfo();
content = response.readEntity(String.class);
} catch (ProcessingException e) {
throw new ConnectionInitializationException(CONNECTION_SETUP_ERROR_STRING, e);
}
checkAndHandleResponse(content, status, accessToken);
}
开发者ID:osiam,项目名称:connector4java,代码行数:22,代码来源:AbstractOsiamService.java
示例14: can_replace_own_user
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
@Test
public void can_replace_own_user() {
AccessToken accessToken = OSIAM_CONNECTOR.retrieveAccessToken("marissa", "koala", Scope.ADMIN);
User originalUser = OSIAM_CONNECTOR.getUser(OWN_USER_ID, accessToken);
Email email = new Email.Builder()
.setValue("[email protected]")
.setType(Email.Type.HOME)
.build();
User replaceUser = new User.Builder(originalUser)
.setDisplayName("Marissa")
.setActive(false)
.addEmail(email)
.build();
User user = OSIAM_CONNECTOR.replaceUser(OWN_USER_ID, replaceUser, accessToken);
assertThat(user.getDisplayName(), is(equalTo("Marissa")));
assertThat(user.isActive(), is(equalTo(false)));
assertThat(user.getEmails().get(0).getValue(), is(equalTo("[email protected]")));
assertThat(user.getEmails().get(0).getType(), is(equalTo(Email.Type.HOME)));
}
开发者ID:osiam,项目名称:connector4java-integration-tests,代码行数:22,代码来源:AdminScopeIT.java
示例15: validateAccessToken
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
/**
* @see OsiamConnector#validateAccessToken(AccessToken)
*/
AccessToken validateAccessToken(AccessToken tokenToValidate) {
checkNotNull(tokenToValidate, "The tokenToValidate must not be null.");
StatusType status;
String content;
try {
Response response = targetEndpoint.path(TOKEN_VALIDATION_ENDPOINT)
.request(MediaType.APPLICATION_JSON)
.property(HttpAuthenticationFeature.HTTP_AUTHENTICATION_USERNAME, clientId)
.property(HttpAuthenticationFeature.HTTP_AUTHENTICATION_PASSWORD, clientSecret)
.property(ClientProperties.CONNECT_TIMEOUT, connectTimeout)
.property(ClientProperties.READ_TIMEOUT, readTimeout)
.header(AUTHORIZATION_HEADER, BEARER + tokenToValidate.getToken())
.post(Entity.json(""));
status = response.getStatusInfo();
content = response.readEntity(String.class);
} catch (ProcessingException e) {
throw createGeneralConnectionInitializationException(e);
}
checkAndHandleResponse(content, status, tokenToValidate);
return getAccessToken(content);
}
开发者ID:osiam,项目名称:connector4java,代码行数:29,代码来源:AuthService.java
示例16: revokeAccessToken
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
void revokeAccessToken(AccessToken tokenToRevoke) {
StatusType status;
String content;
try {
Response response = targetEndpoint.path(TOKEN_REVOCATION_ENDPOINT)
.request(MediaType.APPLICATION_JSON)
.property(HttpAuthenticationFeature.HTTP_AUTHENTICATION_USERNAME, clientId)
.property(HttpAuthenticationFeature.HTTP_AUTHENTICATION_PASSWORD, clientSecret)
.property(ClientProperties.CONNECT_TIMEOUT, connectTimeout)
.property(ClientProperties.READ_TIMEOUT, readTimeout)
.header(AUTHORIZATION_HEADER, BEARER + tokenToRevoke.getToken())
.post(Entity.json(""));
status = response.getStatusInfo();
content = response.readEntity(String.class);
} catch (ProcessingException e) {
throw createGeneralConnectionInitializationException(e);
}
checkAndHandleResponse(content, status, tokenToRevoke);
}
开发者ID:osiam,项目名称:connector4java,代码行数:22,代码来源:AuthService.java
示例17: revokeAllAccessTokens
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
void revokeAllAccessTokens(String id, AccessToken accessToken) {
StatusType status;
String content;
try {
Response response = targetEndpoint.path(TOKEN_REVOCATION_ENDPOINT).path(id)
.request(MediaType.APPLICATION_JSON)
.property(HttpAuthenticationFeature.HTTP_AUTHENTICATION_USERNAME, clientId)
.property(HttpAuthenticationFeature.HTTP_AUTHENTICATION_PASSWORD, clientSecret)
.property(ClientProperties.CONNECT_TIMEOUT, connectTimeout)
.property(ClientProperties.READ_TIMEOUT, readTimeout)
.header(AUTHORIZATION_HEADER, BEARER + accessToken.getToken())
.post(Entity.json(""));
status = response.getStatusInfo();
content = response.readEntity(String.class);
} catch (ProcessingException e) {
throw createGeneralConnectionInitializationException(e);
}
checkAndHandleResponse(content, status, accessToken);
}
开发者ID:osiam,项目名称:connector4java,代码行数:22,代码来源:AuthService.java
示例18: deleteClient
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
void deleteClient(String deleteClientId, AccessToken accessToken) {
StatusType status;
String content;
try {
Response response = targetEndpoint.path(CLIENT_ENDPOINT).path(deleteClientId)
.request(MediaType.APPLICATION_JSON)
.property(HttpAuthenticationFeature.HTTP_AUTHENTICATION_USERNAME, clientId)
.property(HttpAuthenticationFeature.HTTP_AUTHENTICATION_PASSWORD, clientSecret)
.property(ClientProperties.CONNECT_TIMEOUT, connectTimeout)
.property(ClientProperties.READ_TIMEOUT, readTimeout)
.header(AUTHORIZATION_HEADER, BEARER + accessToken.getToken())
.delete();
status = response.getStatusInfo();
content = response.readEntity(String.class);
} catch (ProcessingException e) {
throw createGeneralConnectionInitializationException(e);
}
checkAndHandleResponse(content, status, accessToken);
}
开发者ID:osiam,项目名称:connector4java,代码行数:22,代码来源:AuthService.java
示例19: can_replace_own_user
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
@Test
public void can_replace_own_user() {
AccessToken accessToken = OSIAM_CONNECTOR.retrieveAccessToken("marissa", "koala", Scope.ME);
User originalUser = OSIAM_CONNECTOR.getUser(OWN_USER_ID, accessToken);
Email email = new Email.Builder()
.setValue("[email protected]")
.setType(Email.Type.HOME)
.build();
User replaceUser = new User.Builder(originalUser)
.setDisplayName("Marissa")
.setActive(false)
.addEmail(email)
.build();
User user = OSIAM_CONNECTOR.replaceUser(OWN_USER_ID, replaceUser, accessToken);
assertThat(user.getDisplayName(), is(equalTo("Marissa")));
assertThat(user.getEmails().get(0).getValue(), is(equalTo("[email protected]")));
assertThat(user.getEmails().get(0).getType(), is(equalTo(Email.Type.HOME)));
}
开发者ID:osiam,项目名称:connector4java-integration-tests,代码行数:21,代码来源:MeScopeIT.java
示例20: cannot_create_a_client
import org.osiam.client.oauth.AccessToken; //导入依赖的package包/类
@Test
public void cannot_create_a_client() {
AccessToken accessToken = OSIAM_CONNECTOR.retrieveAccessToken("marissa", "koala", Scope.ME);
String clientAsJsonString = "{\"id\":\"example-client-2\",\"accessTokenValiditySeconds\":2342,\"refreshTokenValiditySeconds\":2342,"
+ "\"redirectUri\":\"http://localhost:5055/oauth2\",\"client_secret\":\"secret-2\","
+ "\"scope\":[\"ADMIN\"],"
+ "\"grants\":[\"refresh_token\",\"client_credentials\",\"authorization_code\",\"password\"],"
+ "\"implicit\":false,\"validityInSeconds\":1337}";
Response response = CLIENT.target(OSIAM_ENDPOINT)
.path("Client")
.request(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + accessToken.getToken())
.post(Entity.entity(clientAsJsonString, MediaType.APPLICATION_JSON));
assertThat(response.getStatus(), is(equalTo(403)));
}
开发者ID:osiam,项目名称:connector4java-integration-tests,代码行数:18,代码来源:MeScopeIT.java
注:本文中的org.osiam.client.oauth.AccessToken类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论