本文整理匯總了Java中org.springframework.security.authentication.InsufficientAuthenticationException類的典型用法代碼示例。如果您正苦於以下問題:Java InsufficientAuthenticationException類的具體用法?Java InsufficientAuthenticationException怎麽用?Java InsufficientAuthenticationException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
InsufficientAuthenticationException類屬於org.springframework.security.authentication包,在下文中一共展示了InsufficientAuthenticationException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: decide
import org.springframework.security.authentication.InsufficientAuthenticationException; //導入依賴的package包/類
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes)
throws AccessDeniedException, InsufficientAuthenticationException {
//System.err.println(" ---------------MaxAccessDecisionManager decide--------------- ");
if(configAttributes == null) {
return;
}
//所請求的資源擁有的權限(一個資源對多個權限)
Iterator<ConfigAttribute> iterator = configAttributes.iterator();
while(iterator.hasNext()) {
ConfigAttribute configAttribute = iterator.next();
//訪問所請求資源所需要的權限
String needPermission = configAttribute.getAttribute();
//System.out.println("NEED-> "+needPermission);
//用戶所擁有的權限authentication
for(GrantedAuthority ga : authentication.getAuthorities()) {
//System.out.println("USER-> "+ga.getAuthority());
if(needPermission.equals(ga.getAuthority())) {
//System.out.println("pass");
return;
}
}
}
//沒有權限
throw new AccessDeniedException("Access Denide!");
}
示例2: decide
import org.springframework.security.authentication.InsufficientAuthenticationException; //導入依賴的package包/類
@Override
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException {
if(null== configAttributes || configAttributes.size() <=0) {
return;
}
ConfigAttribute c;
String needRole;
for(Iterator<ConfigAttribute> iter = configAttributes.iterator(); iter.hasNext(); ) {
c = iter.next();
needRole = c.getAttribute();
for(GrantedAuthority ga : authentication.getAuthorities()) {
if(needRole.trim().equals(ga.getAuthority())) {
return;
}
}
}
throw new AccessDeniedException("no right");
}
示例3: decide
import org.springframework.security.authentication.InsufficientAuthenticationException; //導入依賴的package包/類
@Override
public void decide(Authentication authentication, Object o, Collection<ConfigAttribute> collection)
throws AccessDeniedException, InsufficientAuthenticationException {
if (collection == null) {
return;
}
String needRole;
//遍曆需要的角色,如果一樣,則通過
CustomerUserDetail userDetail = (CustomerUserDetail) authentication.getPrincipal();
List<Role> userRoleList = securityService.getUserRoleList(userDetail.getUsername(), userDetail.getAccountType());
for (ConfigAttribute configAttribute : collection) {
needRole = configAttribute.getAttribute();
for (Role role : userRoleList) {
if (needRole.equals(role.getRoleCode())) {
return;
}
}
}
throw new AccessDeniedException("Cannot Access!");
}
示例4: canCurrentUserAccessView
import org.springframework.security.authentication.InsufficientAuthenticationException; //導入依賴的package包/類
/**
* @param viewClass
* @return true si l'utilisateur peut accéder à la vue
*/
public boolean canCurrentUserAccessView(Class<? extends View> viewClass, Authentication auth) {
if (auth == null) {
return false;
}
MethodInvocation methodInvocation = MethodInvocationUtils.createFromClass(viewClass, "enter");
Collection<ConfigAttribute> configAttributes = methodSecurityInterceptor.obtainSecurityMetadataSource()
.getAttributes(methodInvocation);
/* Renvoie true si la vue n'est pas sécurisée */
if (configAttributes.isEmpty()) {
return true;
}
/* Vérifie que l'utilisateur a les droits requis */
try {
methodSecurityInterceptor.getAccessDecisionManager().decide(auth, methodInvocation, configAttributes);
} catch (InsufficientAuthenticationException | AccessDeniedException e) {
return false;
}
return true;
}
示例5: decide
import org.springframework.security.authentication.InsufficientAuthenticationException; //導入依賴的package包/類
@Override
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException {
if(null== configAttributes || configAttributes.size() <=0) {
return;
}
ConfigAttribute c;
String needRole;
for(Iterator<ConfigAttribute> iter = configAttributes.iterator(); iter.hasNext(); ) {
c = iter.next();
needRole = c.getAttribute();
for(GrantedAuthority ga : authentication.getAuthorities()) {
if(needRole.trim().equals(ga.getAuthority())) {
return;
}
}
}
throw new AccessDeniedException("no right");
}
示例6: decide
import org.springframework.security.authentication.InsufficientAuthenticationException; //導入依賴的package包/類
@Override
public void decide(Authentication authentication, Object o, Collection<ConfigAttribute> collection)
throws AccessDeniedException, InsufficientAuthenticationException {
if (collection == null) {
return;
}
String needRole;
//遍曆需要的角色,如果一樣,則通過,避免角色信息變了,從數據庫取
CustomerUserDetail userDetail = (CustomerUserDetail) authentication.getPrincipal();
List<Role> roleList = securityService.getUserRoleList(userDetail.getUsername(), userDetail.getAccountType());
for (ConfigAttribute configAttribute : collection) {
needRole = configAttribute.getAttribute();
for (Role aRoleList : roleList) {
if (aRoleList != null && needRole.equals(aRoleList.getRoleCode())) {
return;
}
}
}
throw new AccessDeniedException("Cannot Access!");
}
示例7: decide
import org.springframework.security.authentication.InsufficientAuthenticationException; //導入依賴的package包/類
@Override
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException {
if (configAttributes == null) {
return;
}
for (ConfigAttribute ca : configAttributes) {
String needRole = ca.getAttribute();
//ga 為用戶所被賦予的權限。 needRole 為訪問相應的資源應該具有的權限。
for (GrantedAuthority ga : authentication.getAuthorities()) {
if (needRole.trim().equals(ga.getAuthority().trim())) {
return;
}
}
}
throw new AccessDeniedException("沒有權限進行操作!");
}
示例8: authenticate
import org.springframework.security.authentication.InsufficientAuthenticationException; //導入依賴的package包/類
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
Assert.notNull(authentication, "No authentication data provided");
String username = (String) authentication.getPrincipal();
String password = (String) authentication.getCredentials();
User user = userService.getByUsername(username).orElseThrow(() -> new UsernameNotFoundException("User not found: " + username));
if (!encoder.matches(password, user.getPassword())) {
throw new BadCredentialsException("Authentication Failed. Username or Password not valid.");
}
if (user.getRoles() == null) throw new InsufficientAuthenticationException("User has no roles assigned");
List<GrantedAuthority> authorities = user.getRoles().stream()
.map(authority -> new SimpleGrantedAuthority(authority.getRole().authority()))
.collect(Collectors.toList());
UserContext userContext = UserContext.create(user.getUsername(), authorities);
return new UsernamePasswordAuthenticationToken(userContext, null, userContext.getAuthorities());
}
示例9: decide
import org.springframework.security.authentication.InsufficientAuthenticationException; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public void decide(Authentication authentication, Object object,Collection<ConfigAttribute> configAttributes)throws AccessDeniedException, InsufficientAuthenticationException {
if((authentication.getPrincipal() instanceof IUser)){
IUser loginUser=(IUser)authentication.getPrincipal();
if(loginUser.isAdministrator())return;
}
int result=10;
for (AccessDecisionVoter<Object> voter : getDecisionVoters()) {
result = voter.vote(authentication, object, configAttributes);
if(result==AccessDecisionVoter.ACCESS_ABSTAIN){
continue;
}
if(result==AccessDecisionVoter.ACCESS_DENIED){
throw new AccessDeniedException("Access is denied");
}
if(result==AccessDecisionVoter.ACCESS_GRANTED){
break;
}
}
if(result==AccessDecisionVoter.ACCESS_ABSTAIN && configAttributes.size()>0){
throw new AccessDeniedException("Access is denied");
}
}
示例10: authenticateByUserId
import org.springframework.security.authentication.InsufficientAuthenticationException; //導入依賴的package包/類
private SecurityUser authenticateByUserId(UserId userId) {
User user = userService.findUserById(userId);
if (user == null) {
throw new UsernameNotFoundException("User not found by refresh token");
}
UserCredentials userCredentials = userService.findUserCredentialsByUserId(user.getId());
if (userCredentials == null) {
throw new UsernameNotFoundException("User credentials not found");
}
if (!userCredentials.isEnabled()) {
throw new DisabledException("User is not active");
}
if (user.getAuthority() == null)
throw new InsufficientAuthenticationException("User has no authority assigned");
UserPrincipal userPrincipal = new UserPrincipal(UserPrincipal.Type.USER_NAME, user.getEmail());
SecurityUser securityUser = new SecurityUser(user, userCredentials.isEnabled(), userPrincipal);
return securityUser;
}
示例11: decide
import org.springframework.security.authentication.InsufficientAuthenticationException; //導入依賴的package包/類
@Override
public void decide(Authentication authentication, Object object,Collection<ConfigAttribute> configAttributes)
throws AccessDeniedException, InsufficientAuthenticationException {
if(configAttributes == null){
return ;
}
Iterator<ConfigAttribute> ite = configAttributes.iterator();
while(ite.hasNext()){
ConfigAttribute ca = ite.next();
String needRole = ((SecurityConfig)ca).getAttribute();
for(GrantedAuthority grantedAuthority : authentication.getAuthorities()){
if(needRole.trim().equals(grantedAuthority.getAuthority().trim())){
return;
}
}
}
//û��Ȩ����
throw new AccessDeniedException("û��Ȩ���ʣ�");
}
示例12: attemptAuthentication
import org.springframework.security.authentication.InsufficientAuthenticationException; //導入依賴的package包/類
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException,
ServletException {
if (!"POST".equalsIgnoreCase(request.getMethod())) {
throw new InsufficientAuthenticationException("Invalid HTTP Method. it accepts only POST ");
}
if (!isContentTypeValid(request)) {
throw new InsufficientAuthenticationException("Invalid content type. It accepts JSON only.");
}
final LoginRequest loginRequest = getLoginRequest(request);
System.err.println("attemptAuthentication");
final UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(loginRequest.getUsername(), loginRequest.getPassword());
// Allow subclasses to set the "details" property
// setDetails(request, authRequest);
return getAuthenticationManager().authenticate(authRequest);
}
示例13: decide
import org.springframework.security.authentication.InsufficientAuthenticationException; //導入依賴的package包/類
/**
* Decide.
*
* @param authentication
* the authentication
* @param object
* the object
* @param configAttributes
* the configuration attributes
* @throws AccessDeniedException
* the access denied exception
* @throws InsufficientAuthenticationException
* the insufficient authentication exception
*/
@Override
public void decide(final Authentication authentication, final Object object, final Collection<ConfigAttribute> configAttributes)
throws AccessDeniedException, InsufficientAuthenticationException {
boolean allowAccess = false;
for (final GrantedAuthority grantedAuthority : authentication.getAuthorities()) {
for (final ConfigAttribute attribute : configAttributes) {
allowAccess = attribute.getAttribute().equals(grantedAuthority.getAuthority());
if (allowAccess) {
break;// this loop
}
}
}
if (!allowAccess) {
throw new AccessDeniedException("Access is denied");
}
}
示例14: decide
import org.springframework.security.authentication.InsufficientAuthenticationException; //導入依賴的package包/類
/**
* 自定義訪問策略
*
* @param authentication
* 用戶及用戶權限信息
* @param object
* @param configAttributes
* 訪問資源需要的權限
* @throws AccessDeniedException
* @throws InsufficientAuthenticationException
* @see org.springframework.security.access.AccessDecisionManager#decide(org.springframework.security.core.Authentication,
* java.lang.Object, java.util.Collection)
*/
public void decide(Authentication authentication, Object object,
Collection<ConfigAttribute> configAttributes)
throws AccessDeniedException, InsufficientAuthenticationException {
SysUserVO user = (SysUserVO) authentication.getPrincipal();
logger.info("訪問資源的用戶為" + user.getUsername());
// 如果訪問資源不需要任何權限則直接通過
if (configAttributes == null) {
return;
}
Iterator<ConfigAttribute> ite = configAttributes.iterator();
// 遍曆configAttributes看用戶是否有訪問資源的權限
while (ite.hasNext()) {
ConfigAttribute ca = ite.next();
String needRole = ((SecurityConfig) ca).getAttribute();
// ga 為用戶所被賦予的權限。 needRole 為訪問相應的資源應該具有的權限。
for (GrantedAuthority ga : authentication.getAuthorities()) {
if (needRole.trim().equals(ga.getAuthority().trim())) {
return;
}
}
}
throw new AccessDeniedException("沒有權限訪問! ");
}
示例15: securityCheck
import org.springframework.security.authentication.InsufficientAuthenticationException; //導入依賴的package包/類
private void securityCheck(String signatureName, ProceedingJoinPoint pjp) throws Exception {
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
final UserClass theUser = getUser(authentication);
if (theUser != null) {
Collection<? extends SecurityPolicy> rules = securityCache.retrieve(theUser, signatureName);
if (!checkRules(pjp, theUser, rules)) {
throw new InsufficientAuthenticationException(
"Access to method "
// + AspectSecurityUtils.getSignatureString(pjp)
+ " is not allowed!");
}
} else {
if (!getChecker(defaultPolicy).check(pjp, null)) {
throw new InsufficientAuthenticationException(
"Access to method "
// + AspectSecurityUtils.getSignatureString(pjp)
+ " is not allowed!");
}
}
}