本文整理汇总了Java中org.springframework.security.Authentication.getAuthorities方法的典型用法代码示例。如果您正苦于以下问题:Java Authentication.getAuthorities方法的具体用法?Java Authentication.getAuthorities怎么用?Java Authentication.getAuthorities使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.Authentication
的用法示例。
在下文中一共展示了Authentication.getAuthorities方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authenticate
import org.springframework.security.Authentication; //导入方法依赖的package包/类
@Override
public Authentication authenticate(Authentication authenticationRequest)
throws AuthenticationException {
GrantedAuthority[] authorities = new GrantedAuthorityImpl[authenticationRequest.getAuthorities().length + 1];
authorities[0] = new GrantedAuthorityImpl(AUTHENTICATED_AUTHORITY_NAME);
int i = 1;
for(GrantedAuthority originalAuth : authenticationRequest.getAuthorities()){
authorities[i] = new GrantedAuthorityImpl(originalAuth.getAuthority());
i += 1;
}
UsernamePasswordAuthenticationToken authenticationOutcome = new UsernamePasswordAuthenticationToken(authenticationRequest.getPrincipal(),
authenticationRequest.getCredentials(), authorities);
authenticationOutcome.setDetails(authenticationRequest.getDetails());
return authenticationOutcome;
}
示例2: isUserInRole
import org.springframework.security.Authentication; //导入方法依赖的package包/类
/**
* Determine if the currently authenticated user has the role provided. Note that role
* comparisons are case sensitive.
*
* @param role to check
* @return true if the user has the role requested
*/
public boolean isUserInRole(String role) {
boolean inRole = false;
Authentication authentication = getAuthentication();
if( authentication != null ) {
GrantedAuthority[] authorities = authentication.getAuthorities();
for( int i = 0; i < authorities.length; i++ ) {
if( role.equals( authorities[i].getAuthority() ) ) {
inRole = true;
break;
}
}
}
return inRole;
}
示例3: getAuthorities
import org.springframework.security.Authentication; //导入方法依赖的package包/类
/**
* 인증된 사용자의 권한 정보를 가져온다. 예) [ROLE_ADMIN, ROLE_USER,
* ROLE_A, ROLE_B, ROLE_RESTRICTED,
* IS_AUTHENTICATED_FULLY,
* IS_AUTHENTICATED_REMEMBERED,
* IS_AUTHENTICATED_ANONYMOUSLY]
* @return 사용자 권한정보 목록
*/
public static List<String> getAuthorities() {
List<String> listAuth = new ArrayList<String>();
SecurityContext context = SecurityContextHolder.getContext();
Authentication authentication = context.getAuthentication();
if (EgovObjectUtil.isNull(authentication)) {
log.debug("## authentication object is null!!");
return null;
}
GrantedAuthority[] authorities = authentication.getAuthorities();
for (int i = 0; i < authorities.length; i++) {
listAuth.add(authorities[i].getAuthority());
log.debug("## EgovUserDetailsHelper.getAuthorities : Authority is "
+ authorities[i].getAuthority());
}
return listAuth;
}
示例4: testAuthenticateTempUser
import org.springframework.security.Authentication; //导入方法依赖的package包/类
@Test
public void testAuthenticateTempUser() throws Exception {
OnmsUser user = new OnmsUser("tempuser");
user.setFullName("Temporary User");
user.setPassword("18126E7BD3F84B3F3E4DF094DEF5B7DE");
user.setDutySchedule(Arrays.asList("MoTuWeThFrSaSu800-2300"));
m_userManager.save(user);
Authentication authentication = new UsernamePasswordAuthenticationToken("tempuser", "mike");
Authentication authenticated = m_provider.authenticate(authentication);
assertNotNull("authenticated Authentication object not null", authenticated);
GrantedAuthority[] authorities = authenticated.getAuthorities();
assertNotNull("GrantedAuthorities should not be null", authorities);
assertEquals("GrantedAuthorities size", 1, authorities.length);
assertEquals("GrantedAuthorities zero role", "ROLE_USER", authorities[0].getAuthority());
}
示例5: setAdmininstratorRole
import org.springframework.security.Authentication; //导入方法依赖的package包/类
private void setAdmininstratorRole(Context velocityContext, Authentication authentication) {
final GrantedAuthority[] authorities = authentication.getAuthorities();
if (authorities == null) {
return;
}
removeAdminFromContextIfNecessary(velocityContext, authorities);
removeGroupAdminFromContextIfNecessary(velocityContext, authorities);
removeTemplateAdminFromContextIfNecessary(velocityContext, authorities);
removeTemplateViewUserFromContextIfNecessary(velocityContext, authorities);
removeViewAdminRightsFromContextIfNecessary(velocityContext);
}
示例6: matchesRole
import org.springframework.security.Authentication; //导入方法依赖的package包/类
static boolean matchesRole(Authentication authentication, String roleAgent) {
GrantedAuthority[] authorities = authentication.getAuthorities();
if (authorities == null) {
return false;
}
for (GrantedAuthority authority : authorities) {
if (authority.getAuthority().equals(roleAgent)) {
return true;
}
}
return false;
}
示例7: testAuthenticateAdmin
import org.springframework.security.Authentication; //导入方法依赖的package包/类
@Test
public void testAuthenticateAdmin() {
Authentication authentication = new UsernamePasswordAuthenticationToken("admin", "admin");
Authentication authenticated = m_provider.authenticate(authentication);
assertNotNull("authenticated Authentication object not null", authenticated);
GrantedAuthority[] authorities = authenticated.getAuthorities();
assertNotNull("GrantedAuthorities should not be null", authorities);
assertEquals("GrantedAuthorities size", 2, authorities.length);
assertEquals("GrantedAuthorities zero role", "ROLE_USER", authorities[0].getAuthority());
assertEquals("GrantedAuthorities two name", "ROLE_ADMIN", authorities[1].getAuthority());
}
示例8: testAuthenticateRtc
import org.springframework.security.Authentication; //导入方法依赖的package包/类
@Test
public void testAuthenticateRtc() {
Authentication authentication = new UsernamePasswordAuthenticationToken("rtc", "rtc");
Authentication authenticated = m_provider.authenticate(authentication);
assertNotNull("authenticated Authentication object not null", authenticated);
GrantedAuthority[] authorities = authenticated.getAuthorities();
assertNotNull("GrantedAuthorities should not be null", authorities);
assertEquals("GrantedAuthorities size", 1, authorities.length);
assertEquals("GrantedAuthorities one name", "ROLE_RTC", authorities[0].getAuthority());
}