本文整理汇总了Java中org.acegisecurity.GrantedAuthorityImpl类的典型用法代码示例。如果您正苦于以下问题:Java GrantedAuthorityImpl类的具体用法?Java GrantedAuthorityImpl怎么用?Java GrantedAuthorityImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GrantedAuthorityImpl类属于org.acegisecurity包,在下文中一共展示了GrantedAuthorityImpl类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadUserByUsername
import org.acegisecurity.GrantedAuthorityImpl; //导入依赖的package包/类
@Override
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException, DataAccessException {
com.ramussoft.net.common.User user = getUserFactory().getUser(username);
if (user == null) {
throw new UsernameNotFoundException(MessageFormat.format(
"User {0} not found", username));
}
List<Group> list = user.getGroups();
GrantedAuthority[] arrayAuths = new GrantedAuthority[list.size() + 1];
for (int i = 0; i < list.size(); i++) {
arrayAuths[i] = new GrantedAuthorityImpl("ROLE_"
+ list.get(i).getName().toUpperCase());
}
arrayAuths[list.size()] = new GrantedAuthorityImpl("ROLE_USER");
return new User(user.getLogin(), user.getPassword(), true, true, true,
true, arrayAuths);
}
示例2: loadUserByUsername
import org.acegisecurity.GrantedAuthorityImpl; //导入依赖的package包/类
/**
* Locates the user based on the username.
*
* @param username The username presented to the {@link DaoAuthenticationProvider}
* @return A fully populated user record (never <code>null</code>)
* @throws UsernameNotFoundException if the user could not be found or the user has no GrantedAuthority.
* @throws DataAccessException If user could not be found for a repository-specific reason.
*/
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
User user = getUserByName(username);
if (user == null) {
throw new UsernameNotFoundException("User \"" + username + "\" was not found.");
}
String[] roles = userDao.getRolesForUser(username);
GrantedAuthority[] authorities = new GrantedAuthority[roles.length];
for (int i = 0; i < roles.length; i++) {
authorities[i] = new GrantedAuthorityImpl("ROLE_" + roles[i].toUpperCase());
}
// If user is LDAP authenticated, disable user. The proper authentication should in that case
// be done by SubsonicLdapBindAuthenticator.
boolean enabled = !user.isLdapAuthenticated();
return new org.acegisecurity.userdetails.User(username, user.getPassword(), enabled, true, true, true, authorities);
}
示例3: buildGrantedAuthorities
import org.acegisecurity.GrantedAuthorityImpl; //导入依赖的package包/类
private Collection<GrantedAuthority> buildGrantedAuthorities(String gitLabUrl, GitlabUser user, String privateToken) throws IOException {
Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
if(user.isAdmin()) {
authorities.add(new GrantedAuthorityImpl(StringUtils.substringBetween(gitLabUrl, "://", "/") + GitLabGrantedAuthority.GITLAB_ADMIN_SUFFIX));
return authorities;
}
if(StringUtils.isBlank(privateToken)) {
return authorities;
}
GitlabAPI gitlabAPI = GitlabAPI.connect(gitLabUrl, privateToken);
List<GitlabProject> projects = gitlabAPI.getProjects();
for (GitlabProject project: projects) {
authorities.add(buildGrantedAuthority(gitlabAPI, project));
}
return authorities;
}
示例4: mapRow
import org.acegisecurity.GrantedAuthorityImpl; //导入依赖的package包/类
protected Object mapRow(ResultSet rs, int rownum)
throws SQLException {
String username = rs.getString(1);
String password = rs.getString(2);
boolean enabled = rs.getBoolean(3);
boolean credentialsNonExpired = rs.getBoolean(4);
if (password == null) {
//set the password to blank for users authenticated by an external Authentication source
password = "";
}
UserDetails user = new User(username, password, enabled, true,
!credentialsNonExpired, true,
new GrantedAuthority[] {new GrantedAuthorityImpl("HOLDER")});
return user;
}
示例5: getGrantedAuthorities
import org.acegisecurity.GrantedAuthorityImpl; //导入依赖的package包/类
/**
* Select the granted authorities for the sepcified user and return and
* array of the authorities found.
* @param username the user name to get the authorities for
* @return the list of granted authorities
* @throws LdapDataAccessException thrown if there is an error
*/
private GrantedAuthority[] getGrantedAuthorities(String username) throws LdapDataAccessException {
List privileges = auth.getUserPrivileges(username);
if (privileges != null) {
int privSize = privileges.size();
GrantedAuthority roles[] = new GrantedAuthority[privSize];
int i=0;
Iterator it = privileges.iterator();
while (it.hasNext()) {
RolePrivilege priv = (RolePrivilege) it.next();
GrantedAuthority ga = new GrantedAuthorityImpl("ROLE_"+priv.getPrivilege());
roles[i++] = ga;
}
return roles;
}
return new GrantedAuthority[0];
}
示例6: buildRoles
import org.acegisecurity.GrantedAuthorityImpl; //导入依赖的package包/类
private static GrantedAuthority[] buildRoles(AccessToken accessToken) {
List<GrantedAuthority> roles;
roles = new ArrayList<GrantedAuthority>();
if (accessToken != null && accessToken.getRealmAccess() != null) {
for (String role : accessToken.getRealmAccess().getRoles()) {
roles.add(new GrantedAuthorityImpl(role));
}
}
roles.add(SecurityRealm.AUTHENTICATED_AUTHORITY);
return roles.toArray(new GrantedAuthority[roles.size()]);
}
示例7: getAuthenticatedUserGroups
import org.acegisecurity.GrantedAuthorityImpl; //导入依赖的package包/类
/**
* Retrieves the array of granted authorities for the given user.
* It will always contain at least one entry - "authenticated"
*
* @param username
* @return the array of granted authorities, with at least
*/
private GrantedAuthority[] getAuthenticatedUserGroups(final String username) {
try {
HtGroupFile htgroups = getHtGroupFile();
List<String> groups = htgroups.getGroups(username);
ArrayList<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(groups.size() + 1);
authorities.add(AUTHENTICATED_AUTHORITY);
for (String group : groups) {
authorities.add(new GrantedAuthorityImpl(group));
}
return authorities.toArray(GRANTED_AUTHORITY_TYPE);
} catch (Exception ex) {
return DEFAULT_AUTHORITY;
}
}
示例8: getUserGroups
import org.acegisecurity.GrantedAuthorityImpl; //导入依赖的package包/类
private GrantedAuthority[] getUserGroups(final String username) {
try {
HtGroupFile htgroups = getHtGroupFile();
List<String> groups = htgroups.getGroups(username);
ArrayList<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(groups.size());
for (String group : groups) {
authorities.add(new GrantedAuthorityImpl(group));
}
return authorities.toArray(GRANTED_AUTHORITY_TYPE);
} catch (Exception ex) {
return GRANTED_AUTHORITY_TYPE;
}
}
示例9: loadUserByUsername
import org.acegisecurity.GrantedAuthorityImpl; //导入依赖的package包/类
/**
* Locates the user based on the username.
*
* @param username The username presented to the {@link DaoAuthenticationProvider}
* @return A fully populated user record (never <code>null</code>)
* @throws UsernameNotFoundException if the user could not be found or the user has no GrantedAuthority.
* @throws DataAccessException If user could not be found for a repository-specific reason.
*/
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
boolean unlocked = true;
User user = getUserByName(username);
if (user == null) {
throw new UsernameNotFoundException("User \"" + username + "\" was not found.");
}
// block disabled user at logon
if (username.equalsIgnoreCase("default") || user.isLocked()) {
unlocked = false;
}
String[] roles = userDao.getRolesForUser(username);
GrantedAuthority[] authorities = new GrantedAuthority[roles.length];
for (int i = 0; i < roles.length; i++) {
authorities[i] = new GrantedAuthorityImpl("ROLE_" + roles[i].toUpperCase());
}
// If user is LDAP authenticated, disable user. The proper authentication should in that case
// be done by SubsonicLdapBindAuthenticator.
boolean enabled = !user.isLdapAuthenticated();
return new org.acegisecurity.userdetails.User(username, user.getPassword(), enabled, true, true, unlocked, authorities);
}
示例10: loadUserByTicketResponse
import org.acegisecurity.GrantedAuthorityImpl; //导入依赖的package包/类
/**
* This overridden method appends the Distributed Session Ticket to the
* granted authorities
*
* @see org.kuali.rice.kim.client.acegi.KualiUserDetailsService#loadUserByTicketResponse(org.kuali.rice.kim.client.acegi.KualiTicketResponse)
*/
public UserDetails loadUserByTicketResponse(KualiTicketResponse response) {
GrantedAuthority[] authorities = new GrantedAuthority[1];
authorities[0]= new GrantedAuthorityImpl(response.getDistributedSessionToken());
if (logger.isDebugEnabled()) {
logger.debug("loadUserByTicketResponse:" + response.getDistributedSessionToken());
}
return loadUserByUsernameAndAuthorities(response.getUser(), authorities);
}
示例11: loadUserByUsernameAndAuthorities
import org.acegisecurity.GrantedAuthorityImpl; //导入依赖的package包/类
/**
* This method is necessary for loading users by the ticket response
*
* @param username
* @param authorities
* @return the UserDetails
*/
public UserDetails loadUserByUsernameAndAuthorities(String username, GrantedAuthority[] authorities) {
if (logger.isDebugEnabled()) {
logger.debug("loadUserByUsernameAndAuthorities");
}
GrantedAuthority[] newAuthorities = new GrantedAuthority[authorities.length+1];
System.arraycopy(authorities, 0, newAuthorities, 0, authorities.length);
newAuthorities[authorities.length]= new GrantedAuthorityImpl("ROLE_KUALI_USER");
logger.warn("setting granted authorities:" + newAuthorities.toString());
UserDetails user = new User(username, "empty_password", true, true, true, true, newAuthorities);
return user;
}
示例12: getAuthorityCollection
import org.acegisecurity.GrantedAuthorityImpl; //导入依赖的package包/类
private GrantedAuthority[] getAuthorityCollection(String csmUserId) {
Set pePrivContextSet = null;
try {
pePrivContextSet = authorizationManagerInstance().getProtectionElementPrivilegeContextForUser(csmUserId);
} catch (CSObjectNotFoundException e) {
throw new DataRetrievalFailureException("Could not retrieve Granted Authorities for user.");
}
Collection<GrantedAuthority> authorityCollection = new ArrayList<GrantedAuthority>();
Iterator iter = pePrivContextSet.iterator();
while(iter.hasNext()){
ProtectionElementPrivilegeContext pepc = (ProtectionElementPrivilegeContext)iter.next();
String peName = pepc.getProtectionElement().getProtectionElementName();
Set privSet = pepc.getPrivileges();
Iterator ite = privSet.iterator();
while(ite.hasNext()){
Privilege priv = (Privilege)ite.next();
authorityCollection.add(new GrantedAuthorityImpl(peName+"_"+priv.getName().toUpperCase()));
}
}
GrantedAuthority[] grantedAuthorities = new GrantedAuthorityImpl[authorityCollection.size()];
Iterator it = authorityCollection.iterator();
for(int i=0;i<authorityCollection.size();i++){
grantedAuthorities[i]=(GrantedAuthority) it.next();
}
return grantedAuthorities;
}
示例13: loadUserByUsername
import org.acegisecurity.GrantedAuthorityImpl; //导入依赖的package包/类
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
ISession session = getSession();
IModelService msrvc = (IModelService) session.getService(IModelService.class);
IModelService mService = (IModelService)session.getService(IModelService.class);
QueryCriteria<ICi> criteria = new QueryCriteria<ICi>();
criteria.setOffspringOfAlias(this.userTemplateAlias);
criteria.setMatchCiInstances(true);
criteria.setMatchAttribute(true);
criteria.setMatchAttributeAlias(userNameAlias);
criteria.setText(username);
criteria.setTextMatchValue(true);
QueryResult<ICi> result = mService.query(criteria);
if (result.size() == 0) {
// Username not found.
throw new UsernameNotFoundException("Could not find user: " + username);
}
if (result.size() > 1) {
// More than one username exists!
throw new UsernameNotFoundException("Found more then one (" + result.size() + ") user with name : " + username);
}
ICi account = result.get(0);
String userName = getSingleStringValue(account, userNameAlias);
String password = getSingleStringValue(account, "password");
Boolean enabled = getSingleBooleanValue(account, "enabled");
Boolean accountExpired = getSingleBooleanValue(account, "accountExpired");
Boolean credentialsExpired = getSingleBooleanValue(account, "credentialsExpired");
Boolean accountLocked = getSingleBooleanValue(account, "accountLocked");
String defaultRole = getSingleStringValue(account, "defaultRole");
List<IAttribute> roles = account.getAttributesWithAlias("role");
List<GrantedAuthority> granted = new ArrayList<GrantedAuthority>();
for (IAttribute role : roles) {
IValue value = role.getValue();
if (value != null) {
String roleName = value.getAsString();
if (roleName != null || roleName.length() > 0) {
if (roleName.equalsIgnoreCase(defaultRole)) {
granted.add(0, new GrantedAuthorityImpl(roleName));
} else {
granted.add(new GrantedAuthorityImpl(roleName));
}
}
}
}
OneCMDBUser user = new OneCMDBUser(userName,
password,
enabled,
!accountExpired,
!credentialsExpired,
!accountLocked,
granted.toArray(new GrantedAuthority[0]));
user.setAccount(account);
return(user);
}
示例14: authenticateNow
import org.acegisecurity.GrantedAuthorityImpl; //导入依赖的package包/类
private UsernamePasswordAuthenticationToken authenticateNow(Authentication authentication) throws AuthenticationException {
return new UsernamePasswordAuthenticationToken(authentication.getPrincipal(), authentication.getCredentials(), new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_KUALI_USER")});
}