List of usage examples for org.springframework.security.core.authority SimpleGrantedAuthority getAuthority
@Override
public String getAuthority()
From source file:mb.MbKorisnik.java
public String vratiTipKorisnika() { Collection<SimpleGrantedAuthority> authorities = (Collection<SimpleGrantedAuthority>) SecurityContextHolder .getContext().getAuthentication().getAuthorities(); String role = ""; for (SimpleGrantedAuthority a : authorities) { role += a.getAuthority() + " "; }//from ww w. ja va 2 s . c o m return role; }
From source file:org.mitre.oauth2.model.convert.SimpleGrantedAuthorityStringConverter.java
@Override public String convertToDatabaseColumn(SimpleGrantedAuthority attribute) { if (attribute != null) { return attribute.getAuthority(); } else {//ww w.j ava2 s . co m return null; } }
From source file:org.springframework.security.jackson2.SimpleGrantedAuthorityMixinTest.java
@Test public void deserializeGrantedAuthorityTest() throws IOException { String json = "{\"@class\": \"org.springframework.security.core.authority.SimpleGrantedAuthority\", \"role\": \"ROLE_USER\"}"; SimpleGrantedAuthority authority = mapper.readValue(json, SimpleGrantedAuthority.class); assertThat(authority).isNotNull();//from w w w. jav a 2s .co m assertThat(authority.getAuthority()).isNotNull().isEqualTo("ROLE_USER"); }
From source file:org.cloudfoundry.identity.uaa.authorization.external.LdapGroupMappingAuthorizationManager.java
@Override public Set<? extends GrantedAuthority> findScopesFromAuthorities(Set<? extends GrantedAuthority> authorities) { Set<GrantedAuthority> result = new HashSet<>(); for (GrantedAuthority a : authorities) { if (a instanceof LdapAuthority) { LdapAuthority la = (LdapAuthority) a; List<ScimGroupExternalMember> members = extMbrMgr.getExternalGroupMapsByExternalGroup(la.getDn()); for (ScimGroupExternalMember member : members) { SimpleGrantedAuthority mapped = new SimpleGrantedAuthority(member.getDisplayName()); result.add(mapped);/*from ww w .j av a 2s . c o m*/ if (logger.isDebugEnabled()) { logger.debug("Ldap Group Mapped[dn=" + la.getDn() + " scope:" + mapped.getAuthority()); } } } else { result.add(a); } } return result; }
From source file:org.cloudfoundry.identity.uaa.authorization.LdapGroupMappingAuthorizationManager.java
@Override public Set<? extends GrantedAuthority> findScopesFromAuthorities(Set<? extends GrantedAuthority> authorities) { Set<GrantedAuthority> result = new HashSet<>(); for (GrantedAuthority a : authorities) { if (a instanceof LdapAuthority) { LdapAuthority la = (LdapAuthority) a; List<ScimGroupExternalMember> members = extMbrMgr.getExternalGroupMapsByExternalGroup(la.getDn(), OriginKeys.LDAP);//w w w . j a va2 s. c o m for (ScimGroupExternalMember member : members) { SimpleGrantedAuthority mapped = new SimpleGrantedAuthority(member.getDisplayName()); result.add(mapped); if (logger.isDebugEnabled()) { logger.debug("Ldap Group Mapped[dn=" + la.getDn() + " scope:" + mapped.getAuthority()); } } } else { result.add(a); } } return result; }
From source file:org.dspace.rest.Resource.java
/** * Create context to work with DSpace database. It can create context * with or without a logged in user (retrieved from SecurityContextHolder). Throws * WebApplicationException caused by: SQLException if there was a problem * with reading from database. Throws AuthorizeException if there was * a problem with authorization to read from the database. Throws Exception * if there was a problem creating context. * /*from www. j a va 2 s . c om*/ * @return Newly created context with the logged in user unless the specified user was null. * If user is null, create the context without a logged in user. * @throws ContextException * Thrown in case of a problem creating context. Can be caused by * SQLException error in creating context or finding the user to * log in. Can be caused by AuthorizeException if there was a * problem authorizing the found user. * @throws SQLException * An exception that provides information on a database access error or other errors. */ protected static org.dspace.core.Context createContext() throws ContextException, SQLException { org.dspace.core.Context context = new org.dspace.core.Context(); //context.getDBConnection().setAutoCommit(false); // Disable autocommit. Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null) { Collection<SimpleGrantedAuthority> specialGroups = (Collection<SimpleGrantedAuthority>) authentication .getAuthorities(); for (SimpleGrantedAuthority grantedAuthority : specialGroups) { context.setSpecialGroup(EPersonServiceFactory.getInstance().getGroupService() .findByName(context, grantedAuthority.getAuthority()).getID()); } context.setCurrentUser(EPersonServiceFactory.getInstance().getEPersonService().findByEmail(context, authentication.getName())); } return context; }
From source file:org.encuestame.core.security.web.SecurityUtils.java
/** * Check is Session is Expired./* w ww .j a v a 2s .c o m*/ * Iterate the existing permission stored in the {@link Authentication} and check if at least * the ENCUESTAME_USER exist and return true if this condition exist. * @param authentication * @return */ public static boolean checkIsSessionIsExpired(final Authentication authentication) { boolean session = true; if (authentication != null) { session = authentication.isAuthenticated(); for (GrantedAuthority authority : authentication.getAuthorities()) { SimpleGrantedAuthority auth = (SimpleGrantedAuthority) authority; if (auth.getAuthority().equals(EnMePermission.ENCUESTAME_USER.toString())) { session = false; break; } } } log.trace("checkIsSessionIsExpired->" + session); return session; }