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


Java Authentication.getAuthorities方法代码示例

本文整理汇总了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;
}
 
开发者ID:Rospaccio,项目名称:pentaho-authentication-ext,代码行数:17,代码来源:ExtensionAuthenticationProvider.java

示例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;
}
 
开发者ID:shevek,项目名称:spring-rich-client,代码行数:23,代码来源:DefaultApplicationSecurityManager.java

示例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;
}
 
开发者ID:eGovFrame,项目名称:egovframework.rte.root,代码行数:31,代码来源:EgovUserDetailsHelper.java

示例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());
}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:17,代码来源:AuthenticationIntegrationTest.java

示例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);

}
 
开发者ID:gocd,项目名称:gocd,代码行数:13,代码来源:GoVelocityView.java

示例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;
}
 
开发者ID:gocd,项目名称:gocd,代码行数:13,代码来源:UserHelper.java

示例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());
}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:12,代码来源:AuthenticationIntegrationTest.java

示例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());
}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:11,代码来源:AuthenticationIntegrationTest.java


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