• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Approval类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.security.oauth2.provider.approval.Approval的典型用法代码示例。如果您正苦于以下问题:Java Approval类的具体用法?Java Approval怎么用?Java Approval使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Approval类属于org.springframework.security.oauth2.provider.approval包,在下文中一共展示了Approval类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: addApprovals

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
@Override
public boolean addApprovals(Collection<Approval> approvals) {
	Objects.requireNonNull(approvals);
	approvals.forEach(a -> {
		UserOAuth2ClientApprovalEntity approval = approvalRepository.findByUserUsernameAndClientIdAndScope(a.getUserId(),
				a.getClientId(), a.getScope());
		UserOAuth2ClientApprovalEntity newApproval = new UserOAuth2ClientApprovalEntity();
		if (approval != null) {
			newApproval.setId(approval.getId());
			newApproval.setCreatedBy(approval.getCreatedBy());
			newApproval.setCreatedDate(approval.getCreatedDate());
		}
		newApproval
				.setUser(userRepository.findByUsername(a.getUserId()))
				.setClient(new OAuth2ClientEntity().setId(a.getClientId()))
				.setScope(a.getScope())
				.setApprovalStatus(a.getStatus());
		approvalRepository.save(newApproval);
	});

	return true;
}
 
开发者ID:codenergic,项目名称:theskeleton,代码行数:23,代码来源:UserOAuth2ClientApprovalStore.java


示例2: testAddApprovals

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
@Test
public void testAddApprovals() {
	assertThatThrownBy(() -> {
		approvalStore.addApprovals(null);
	}).isInstanceOf(NullPointerException.class);
	when(approvalRepository.findByUserUsernameAndClientIdAndScope(anyString(), anyString(), eq("read")))
			.thenReturn(new UserOAuth2ClientApprovalEntity()
					.setUser(new UserEntity().setId("1"))
					.setClient(new OAuth2ClientEntity().setId("2"))
					.setScope("read")
					.setApprovalStatus(ApprovalStatus.APPROVED));
	approvalStore.addApprovals(Arrays.asList(new Approval("1", "2", "read", new Date(), ApprovalStatus.APPROVED)));
	verify(approvalRepository).findByUserUsernameAndClientIdAndScope(anyString(), anyString(), eq("read"));
	when(approvalRepository.findByUserUsernameAndClientIdAndScope(anyString(), anyString(), eq("write")))
			.thenReturn(null);
	approvalStore.addApprovals(Arrays.asList(new Approval("1", "2", "write", new Date(), ApprovalStatus.APPROVED)));
	verify(approvalRepository).findByUserUsernameAndClientIdAndScope(anyString(), anyString(), eq("write"));
	verify(approvalRepository, times(2)).save(any(UserOAuth2ClientApprovalEntity.class));
}
 
开发者ID:codenergic,项目名称:theskeleton,代码行数:20,代码来源:UserOauth2ClientApprovalStoreTest.java


示例3: testRevokeApprovals

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
@Test
public void testRevokeApprovals() {
	assertThatThrownBy(() -> {
		approvalStore.revokeApprovals(null);
	}).isInstanceOf(NullPointerException.class);
	when(approvalRepository.findByUserUsernameAndClientIdAndScope(anyString(), anyString(), eq("read")))
			.thenReturn(new UserOAuth2ClientApprovalEntity()
					.setUser(new UserEntity().setId("1"))
					.setClient(new OAuth2ClientEntity().setId("2"))
					.setScope("read")
					.setApprovalStatus(ApprovalStatus.APPROVED));
	when(approvalRepository.findByUserUsernameAndClientIdAndScope(anyString(), anyString(), eq("write"))).thenReturn(null);
	List<Approval> approvals = new ArrayList<>();
	approvals.add(new Approval("", "", "write", new Date(), ApprovalStatus.APPROVED));
	for (int i = 0; i < 3; i++) {
		approvals.add(new Approval("", "", "read", new Date(), ApprovalStatus.APPROVED));
	}
	approvalStore.revokeApprovals(approvals);
	verify(approvalRepository, times(1)).findByUserUsernameAndClientIdAndScope(anyString(), anyString(), eq("write"));
	verify(approvalRepository, times(3)).findByUserUsernameAndClientIdAndScope(anyString(), anyString(), eq("read"));
	verify(approvalRepository, times(3)).delete(any(UserOAuth2ClientApprovalEntity.class));
}
 
开发者ID:codenergic,项目名称:theskeleton,代码行数:23,代码来源:UserOauth2ClientApprovalStoreTest.java


示例4: testGetApprovals

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
@Test
@SuppressWarnings("serial")
public void testGetApprovals() {
	when(approvalRepository.findByUserUsernameAndClientId(anyString(), anyString()))
			.thenReturn(Arrays.asList(new UserOAuth2ClientApprovalEntity() {{ setCreatedDate(new Date()); }}
							.setApprovalStatus(ApprovalStatus.APPROVED)
							.setUser(new UserEntity())
							.setClient(new OAuth2ClientEntity()),
					new UserOAuth2ClientApprovalEntity() {{ setCreatedDate(new Date()); }}
							.setApprovalStatus(ApprovalStatus.DENIED)
							.setUser(new UserEntity())
							.setClient(new OAuth2ClientEntity())));
	List<Approval> approvals = new ArrayList<>(approvalStore.getApprovals("1", "2"));
	assertThat(approvals.size()).isEqualTo(2);
	assertThat(approvals.get(0).getStatus()).isEqualTo(ApprovalStatus.APPROVED);
	assertThat(approvals.get(1).getStatus()).isEqualTo(ApprovalStatus.DENIED);
	verify(approvalRepository).findByUserUsernameAndClientId(anyString(), anyString());
}
 
开发者ID:codenergic,项目名称:theskeleton,代码行数:19,代码来源:UserOauth2ClientApprovalStoreTest.java


示例5: testFindOAuth2ClientApprovalByUsername

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
@Test
public void testFindOAuth2ClientApprovalByUsername() throws Exception {
	final UserOAuth2ClientApprovalEntity result = new UserOAuth2ClientApprovalEntity()
		.setId("123")
		.setUser(new UserEntity().setUsername("user"))
		.setClient(new OAuth2ClientEntity().setId("123"))
		.setApprovalStatus(Approval.ApprovalStatus.APPROVED)
		.setScope("scope1");
	when(approvalRepository.findByUserUsername("user"))
		.thenReturn(Collections.singletonList(result));
	List<UserOAuth2ClientApprovalEntity> approvals = profileService.findOAuth2ClientApprovalByUsername("user");
	assertThat(approvals).isNotEmpty();
	assertThat(approvals).hasSize(1);
	assertThat(approvals.get(0)).isEqualTo(result);
	verify(approvalRepository).findByUserUsername("user");
}
 
开发者ID:codenergic,项目名称:theskeleton,代码行数:17,代码来源:ProfileServiceTest.java


示例6: getAccessConfirmation

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
@RequestMapping("/oauth/confirm_access")
public ModelAndView getAccessConfirmation(Map<String, Object> model, Principal principal) throws Exception {
	AuthorizationRequest clientAuth = (AuthorizationRequest) model.remove("authorizationRequest");
	ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
	model.put("auth_request", clientAuth);
	model.put("client", client);
	Map<String, String> scopes = new LinkedHashMap<String, String>();
	for (String scope : clientAuth.getScope()) {
		scopes.put(OAuth2Utils.SCOPE_PREFIX + scope, "false");
	}
	for (Approval approval : approvalStore.getApprovals(principal.getName(), client.getClientId())) {
		if (clientAuth.getScope().contains(approval.getScope())) {
			scopes.put(OAuth2Utils.SCOPE_PREFIX + approval.getScope(),
					approval.getStatus() == ApprovalStatus.APPROVED ? "true" : "false");
		}
	}
	model.put("scopes", scopes);
	return new ModelAndView("authorize", model);
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:20,代码来源:AccessConfirmationController.java


示例7: getAccessConfirmation

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
@RequestMapping("/oauth/confirm_access")
public ModelAndView getAccessConfirmation(Map<String, Object> model, Principal principal) throws Exception {
    AuthorizationRequest clientAuth = (AuthorizationRequest) model.remove("authorizationRequest");
    ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
    model.put("auth_request", clientAuth);
    model.put("client", client);
    Map<String, String> scopes = new LinkedHashMap<String, String>();
    for (String scope : clientAuth.getScope()) {
        scopes.put(OAuth2Utils.SCOPE_PREFIX + scope, "false");
    }
    for (Approval approval : approvalStore.getApprovals(principal.getName(), client.getClientId())) {
        if (clientAuth.getScope().contains(approval.getScope())) {
            scopes.put(OAuth2Utils.SCOPE_PREFIX + approval.getScope(),
                    approval.getStatus() == Approval.ApprovalStatus.APPROVED ? "true" : "false");
        }
    }
    model.put("scopes", scopes);
    return new ModelAndView("access_confirmation", model); // 订阅 appproval 页面
}
 
开发者ID:h819,项目名称:spring-boot,代码行数:20,代码来源:AccessConfirmationController.java


示例8: revokeApprovals

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
@Override
public boolean revokeApprovals(final Collection<Approval> approvals) {
    boolean success = true;

    final Collection<MongoApproval> mongoApprovals = transform(approvals, toMongoApproval());

    for (final MongoApproval mongoApproval : mongoApprovals) {
        if (handleRevocationsAsExpiry) {
            final boolean updateResult = mongoApprovalRepository.updateExpiresAt(LocalDate.now(), mongoApproval);
            if (!updateResult) {
                success = false;
            }

        }
        else {
            final boolean deleteResult = mongoApprovalRepository.deleteByUserIdAndClientIdAndScope(mongoApproval);

            if (!deleteResult) {
                success = false;
            }
        }
    }
    return success;
}
 
开发者ID:cloudade,项目名称:authorization-server-with-mongodb,代码行数:25,代码来源:MongoApprovalStore.java


示例9: getApprovals

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
@Override
public List<Approval> getApprovals(String userName, String clientId) {
    BasicDBObject query = new BasicDBObject(userIdFieldName, userName).append(clientIdFieldName, clientId);
    DBCursor cursor = null;
    try {
        List<Approval> approvals = new ArrayList<Approval>();
        cursor = getApprovalsCollection().find(query);
        while (cursor.hasNext()) {
            DBObject dbo = cursor.next();
            approvals.add(new Approval((String) dbo.get(userIdFieldName), (String) dbo.get(clientIdFieldName),
                    (String) dbo.get(scopeFieldName), (Date) dbo.get(expiresAtFieldName),
                    Approval.ApprovalStatus.valueOf((String) dbo.get(statusFieldName)),
                    (Date) dbo.get(lastModifiedAtFieldName)));
        }
        return approvals;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
 
开发者ID:cedac-software,项目名称:spring-security-mongodb,代码行数:22,代码来源:MongoApprovalStore.java


示例10: shouldRevokeApprovalsByRemoveWhenHandleRevocationsAsExpiryIsFalse

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
@Test
public void shouldRevokeApprovalsByRemoveWhenHandleRevocationsAsExpiryIsFalse() {
    //Given
    final List<Approval> approvals = list(ofApproval()).next();

    //And
    mongoApprovalStore.setHandleRevocationsAsExpiry(false);

    //And
    given(mongoApprovalRepository.deleteByUserIdAndClientIdAndScope(any(MongoApproval.class))).willReturn(true);

    //When
    final boolean result = mongoApprovalStore.revokeApprovals(approvals);

    //Then
    assertThat(result).isTrue();
    verify(mongoApprovalRepository, never()).updateExpiresAt(any(LocalDate.class), any(MongoApproval.class));
}
 
开发者ID:caelwinner,项目名称:spring-security-mongo,代码行数:19,代码来源:MongoApprovalStoreTest.java


示例11: shouldRevokeApprovalsByUpdateWhenHandleRevocationsAsExpiryIsTrue

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
@Test
public void shouldRevokeApprovalsByUpdateWhenHandleRevocationsAsExpiryIsTrue() {
    //Given
    final List<Approval> approvals = list(ofApproval()).next();

    //And
    mongoApprovalStore.setHandleRevocationsAsExpiry(true);

    //And
    given(mongoApprovalRepository.updateExpiresAt(any(LocalDate.class), any(MongoApproval.class))).willReturn(true);

    //When
    final boolean result = mongoApprovalStore.revokeApprovals(approvals);

    //Then
    assertThat(result).isTrue();
    verify(mongoApprovalRepository, never()).deleteByUserIdAndClientIdAndScope(any(MongoApproval.class));
}
 
开发者ID:caelwinner,项目名称:spring-security-mongo,代码行数:19,代码来源:MongoApprovalStoreTest.java


示例12: shouldGetApprovals

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
@Test
public void shouldGetApprovals() {
    //Given
    final String userId = string().next();
    final String clientId = string().next();

    //And
    final List<MongoApproval> expectedMongoApprovals = list(ofMongoApproval()).next();
    given(mongoApprovalRepository.findByUserIdAndClientId(userId, clientId)).willReturn(expectedMongoApprovals);

    //When
    final Collection<Approval> approvals = mongoApprovalStore.getApprovals(userId, clientId);

    //Then
    assertThat(approvals).hasSameSizeAs(expectedMongoApprovals);
}
 
开发者ID:caelwinner,项目名称:spring-security-mongo,代码行数:17,代码来源:MongoApprovalStoreTest.java


示例13: getAccessConfirmation

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
@RequestMapping("/oauth/confirm_access")
public ModelAndView getAccessConfirmation(Map<String, Object> model, Principal principal) throws Exception {
	AuthorizationRequest clientAuth = (AuthorizationRequest) model.remove("authorizationRequest");
	ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
	model.put("auth_request", clientAuth);
	model.put("client", client);
	Map<String, String> scopes = new LinkedHashMap<String, String>();
	for (String scope : clientAuth.getScope()) {
		scopes.put(OAuth2Utils.SCOPE_PREFIX + scope, "false");
	}
	for (Approval approval : approvalStore.getApprovals(principal.getName(), client.getClientId())) {
		if (clientAuth.getScope().contains(approval.getScope())) {
			scopes.put(OAuth2Utils.SCOPE_PREFIX + approval.getScope(),
					approval.getStatus() == ApprovalStatus.APPROVED ? "true" : "false");
		}
	}
	model.put("scopes", scopes);
	return new ModelAndView("access_confirmation", model);
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:20,代码来源:AccessConfirmationController.java


示例14: revokeApprovals

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
@Override
public boolean revokeApprovals(Collection<Approval> approvals) {
	Objects.requireNonNull(approvals);
	approvals.forEach(a -> {
		UserOAuth2ClientApprovalEntity approval = approvalRepository.findByUserUsernameAndClientIdAndScope(a.getUserId(),
				a.getClientId(), a.getScope());
		if (approval != null) {
			approvalRepository.delete(approval);
		}
	});

	return true;
}
 
开发者ID:codenergic,项目名称:theskeleton,代码行数:14,代码来源:UserOAuth2ClientApprovalStore.java


示例15: getApprovals

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
@Override
@Transactional(readOnly = true)
public Collection<Approval> getApprovals(String userId, String clientId) {
	return approvalRepository.findByUserUsernameAndClientId(userId, clientId).stream()
			.map(UserOAuth2ClientApprovalEntity::toApproval)
			.collect(Collectors.toList());
}
 
开发者ID:codenergic,项目名称:theskeleton,代码行数:8,代码来源:UserOAuth2ClientApprovalStore.java


示例16: testFindProfileConnectedApps

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
@Test
@WithMockUser("user123")
public void testFindProfileConnectedApps() throws Exception {
	final UserEntity user = new UserEntity().setUsername("user123");
	final OAuth2ClientEntity client = new OAuth2ClientEntity().setId("client123").setName("client123");
	final UserOAuth2ClientApprovalEntity approval1 = new UserOAuth2ClientApprovalEntity()
		.setUser(user)
		.setClient(client)
		.setScope("scope1")
		.setApprovalStatus(Approval.ApprovalStatus.APPROVED);
	final UserOAuth2ClientApprovalEntity approval2 = new UserOAuth2ClientApprovalEntity()
		.setUser(user)
		.setClient(client)
		.setScope("scope2")
		.setApprovalStatus(Approval.ApprovalStatus.DENIED);
	when(profileService.findOAuth2ClientApprovalByUsername("user123")).thenReturn(Arrays.asList(approval1, approval2));
	MockHttpServletRequestBuilder request = get("/api/profile/connected-apps")
		.contentType(MediaType.APPLICATION_JSON);
	MockHttpServletResponse response = mockMvc.perform(request)
		.andDo(document("user-profile-connected-apps-view"))
		.andReturn()
		.getResponse();
	assertThat(response.getStatus()).isEqualTo(200);
	CollectionType collectionType = objectMapper.getTypeFactory().constructCollectionType(List.class, UserOAuth2ClientApprovalRestData.class);
	List<UserOAuth2ClientApprovalRestData> returnedData = objectMapper
		.readValue(response.getContentAsByteArray(), collectionType);
	assertThat(returnedData).hasSize(1);
	UserOAuth2ClientApprovalRestData restData = returnedData.get(0);
	assertThat(restData.getClientId()).isEqualTo(client.getId());
	assertThat(restData.getClientName()).isEqualTo(client.getName());
	assertThat(restData.getUsername()).isEqualTo(user.getUsername());
	ImmutableMap<String, Approval.ApprovalStatus> scopeAndStatus = restData.getScopeAndStatus();
	assertThat(scopeAndStatus).hasSize(2);
	assertThat(scopeAndStatus).containsEntry(approval1.getScope(), approval1.getApprovalStatus());
	assertThat(scopeAndStatus).containsEntry(approval2.getScope(), approval2.getApprovalStatus());
	verify(profileService).findOAuth2ClientApprovalByUsername("user123");
}
 
开发者ID:codenergic,项目名称:theskeleton,代码行数:38,代码来源:ProfileRestControllerTest.java


示例17: isApprovedClient

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
public boolean isApprovedClient(String clientId, String username) {
    OauthApprovals oa = this.oauthApprovalsRepository.findByUserIdAndClientId(username, clientId);
    if (oa != null && Approval.ApprovalStatus.valueOf(oa.getStatus()) == Approval.ApprovalStatus.APPROVED) {
        return true;
    }
    return false;
}
 
开发者ID:bndynet,项目名称:web-framework-for-java,代码行数:8,代码来源:OauthService.java


示例18: toMongoApproval

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
private Function<Approval, MongoApproval> toMongoApproval() {
    return new Function<Approval, MongoApproval>() {
        @Override
        public MongoApproval apply(final Approval approval) {
            return new MongoApproval(UUID.randomUUID().toString(),
                    approval.getUserId(),
                    approval.getClientId(),
                    approval.getScope(),
                    approval.getStatus() == null ? Approval.ApprovalStatus.APPROVED: approval.getStatus(),
                    LocalDate.fromDateFields(approval.getExpiresAt()),
                    LocalDate.fromDateFields(approval.getLastUpdatedAt()));
        }
    };
}
 
开发者ID:cloudade,项目名称:authorization-server-with-mongodb,代码行数:15,代码来源:MongoApprovalStore.java


示例19: toApproval

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
private Function<MongoApproval, Approval> toApproval() {
    return new Function<MongoApproval, Approval>() {
        @Override
        public Approval apply(final MongoApproval mongoApproval) {
            return new Approval(mongoApproval.getUserId(),
                    mongoApproval.getClientId(),
                    mongoApproval.getScope(),
                    mongoApproval.getExpiresAt().toDate(),
                    mongoApproval.getStatus(),
                    mongoApproval.getLastUpdatedAt().toDate());
        }
    };
}
 
开发者ID:cloudade,项目名称:authorization-server-with-mongodb,代码行数:14,代码来源:MongoApprovalStore.java


示例20: getList

import org.springframework.security.oauth2.provider.approval.Approval; //导入依赖的package包/类
@RequestMapping("/list")
public String getList(Model model, Principal principal) {
	List<Approval> approvals = clientDetailsService
			.listClientDetails()
			.stream()
			.map(clientDetail -> approvalStore.getApprovals(
					principal.getName(), clientDetail.getClientId()))
					.flatMap(Collection::stream).collect(Collectors.toList());
	model.addAttribute("approvals", approvals);
	return "approvals";
}
 
开发者ID:cloudade,项目名称:authorization-server-with-mongodb,代码行数:12,代码来源:ApprovalController.java



注:本文中的org.springframework.security.oauth2.provider.approval.Approval类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DisallowSnapshotResponseProto类代码示例发布时间:2022-05-22
下一篇:
Java FTPException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap