当前位置: 首页>>代码示例>>Java>>正文


Java Approval类代码示例

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


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


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