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


Java AuthenticationFailureException类代码示例

本文整理汇总了Java中org.biokoframework.system.services.authentication.AuthenticationFailureException的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationFailureException类的具体用法?Java AuthenticationFailureException怎么用?Java AuthenticationFailureException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AuthenticationFailureException类属于org.biokoframework.system.services.authentication包,在下文中一共展示了AuthenticationFailureException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: executeCommand

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //导入依赖的package包/类
@Override
public Fields executeCommand(Fields input) throws SystemException, ValidationException {
       AuthResponse authResponse = null;
	try {
		authResponse = fAuthService.authenticate(input, fRequiredRoles);
		input.putAll(authResponse.getMergeFields());
	} catch (AuthenticationFailureException exception) {
		if (fRequireValidAuthentication) {
			throw exception;
		}
	}
       Fields output = fWrappedHandler.executeCommand(input);
       if (authResponse != null && authResponse.getOverrideFields() != null) {
           output.putAll(authResponse.getOverrideFields());
       }
	return output;
}
 
开发者ID:bioko,项目名称:http-exposer,代码行数:18,代码来源:SecurityHandler.java

示例2: httpAuthenticate

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //导入依赖的package包/类
@Override
public Fields httpAuthenticate(Fields input) throws AuthenticationFailureException {
	String encodedAuth = getHeader(AUTHORIZATION);
	String decodedAuth = new String(Base64.decodeBase64(encodedAuth.substring(BASIC_AUTH_START.length())));
	
	String userName = decodedAuth.replaceFirst(":.*", "");
	String password = decodedAuth.replaceFirst(".*:", "");
	
	Login login = fLoginRepository.retrieveByForeignKey(GenericFieldNames.USER_EMAIL, userName);
	if (login == null) {
		throw CommandExceptionsFactory.createInvalidLoginException();
	} else if (!login.get(GenericFieldNames.PASSWORD).equals(password)) {
		throw CommandExceptionsFactory.createInvalidLoginException();
	}
	
	return new Fields(Login.class.getSimpleName(), login);
}
 
开发者ID:bioko,项目名称:http-exposer,代码行数:18,代码来源:BasicAccessAuthenticationStrategy.java

示例3: authenticate

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //导入依赖的package包/类
@Override
public AuthResponse authenticate(Fields fields, List<String> requiredRoles) throws AuthenticationFailureException {
	for (IAuthenticationService anAuthService : fAuthServices) {
		if (!(anAuthService instanceof AllAuthenticationService)) {
               try {
                   AuthResponse authResponse = anAuthService.authenticate(fields, requiredRoles);
                   if (authResponse != null) {
                       return authResponse;
                   }
               } catch (AuthenticationFailureException exception) {
                   Long errorCode = exception.getErrors().get(0).get(ErrorEntity.ERROR_CODE);
                   if (FieldNames.AUTHENTICATION_REQUIRED_CODE != errorCode) {
                       throw exception;
                   }
               }
		}
	}
	
	throw CommandExceptionsFactory.createUnauthorisedAccessException();
}
 
开发者ID:bioko,项目名称:system,代码行数:21,代码来源:AllAuthenticationService.java

示例4: testSuccessfulAuthenticationUsingToken

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //导入依赖的package包/类
@Test
public void testSuccessfulAuthenticationUsingToken() throws ValidationException, RepositoryException, AuthenticationFailureException {
    TestCurrentTimeService.setCalendar("2014-01-22T18:00:05Z");

    Login login = fLoginBuilder.loadDefaultExample().build(false);
    login = fLoginRepo.save(login);

    fAuthService = fInjector.getInstance(TokenAuthenticationServiceImpl.class);

    Authentication auth = fAuthBuilder.loadDefaultExample()
            .set(Authentication.LOGIN_ID, login.getId()).build(false);
    fAuthRepo.save(auth);

    Fields fields = new Fields("authToken", auth.get(Authentication.TOKEN));
    AuthResponse authResponse = fAuthService.authenticate(fields, Collections.<String>emptyList());

    assertThat(authResponse.getMergeFields(), contains(GenericFieldNames.AUTH_LOGIN_ID, login.getId()));

    DateTime authTokenExpire = ISODateTimeFormat.dateTimeNoMillis().parseDateTime((String) authResponse.getOverrideFields().get(Authentication.TOKEN_EXPIRE));
    assertThat(authTokenExpire, is(equalTo(fTimeService.getCurrentTimeAsDateTime().plus(fTokenValiditySecs * 1000))));
}
 
开发者ID:bioko,项目名称:system,代码行数:22,代码来源:TokenAuthenticationServiceImplTest.java

示例5: testFailedAuthenticationBecauseTokenExpired

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //导入依赖的package包/类
@Test
public void testFailedAuthenticationBecauseTokenExpired() throws ValidationException, RepositoryException, AuthenticationFailureException {
       TestCurrentTimeService.setCalendar("2014-01-24T18:00:05Z");

       Login login = fLoginBuilder.loadDefaultExample().build(false);
       login = fLoginRepo.save(login);

       fAuthService = fInjector.getInstance(TokenAuthenticationServiceImpl.class);

       Authentication auth = fAuthBuilder.loadDefaultExample()
               .set(Authentication.LOGIN_ID, login.getId())
               .build(false);
       auth = fAuthRepo.save(auth);

       Fields fields = new Fields("authToken", auth.get(Authentication.TOKEN));

       try {
           fAuthService.authenticate(fields, Collections.<String>emptyList());
           fail(AuthenticationFailureException.class + " not thrown");
       } catch (AuthenticationFailureException exception) {
           assertThat(exception.getErrors(), is(equalTo(CommandExceptionsFactory.createTokenExpiredException().getErrors())));
       }

       assertThat(fAuthRepo.retrieve(auth.getId()), is(nullValue()));
   }
 
开发者ID:bioko,项目名称:system,代码行数:26,代码来源:TokenAuthenticationServiceImplTest.java

示例6: testFailedBecauseRoleExpected

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //导入依赖的package包/类
@Test
public void testFailedBecauseRoleExpected() throws ValidationException, RepositoryException, AuthenticationFailureException {
    TestCurrentTimeService.setCalendar("2014-01-22T18:00:05Z");

    Login login = fLoginBuilder.loadDefaultExample().build(false);
    login = fLoginRepo.save(login);

    fAuthService = fInjector.getInstance(TokenAuthenticationServiceImpl.class);

    Authentication auth = fAuthBuilder.loadDefaultExample()
            .set(Authentication.LOGIN_ID, login.getId())
            .build(false);
    auth = fAuthRepo.save(auth);

    Fields fields = new Fields("authToken", auth.get(Authentication.TOKEN));

    expected.expect(AuthenticationFailureException.class);
    expected.expectMessage(containsString("\"errorCode\":113"));
    fAuthService.authenticate(fields, Collections.singletonList("aRole"));
}
 
开发者ID:bioko,项目名称:system,代码行数:21,代码来源:TokenAuthenticationServiceImplTest.java

示例7: simpleAuthenticationTest

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //导入依赖的package包/类
@Test
public void simpleAuthenticationTest() throws AuthenticationFailureException, ValidationException, RepositoryException {
    Login login = fLoginBuilder.loadDefaultExample().build(false);
    login = fLoginRepo.save(login);

    SimpleAuthenticationService authenticationService = fInjector.getInstance(SimpleAuthenticationService.class);

    Fields fields = new Fields(
            Login.USER_EMAIL, login.get(Login.USER_EMAIL),
            Login.PASSWORD, login.get(Login.PASSWORD));

    AuthResponse response = authenticationService.authenticate(fields, Collections.<String>emptyList());

    assertThat(response, is(notNullValue()));
    assertThat((String) response.getMergeFields().get("authLoginId"), is(equalTo(login.getId())));
}
 
开发者ID:bioko,项目名称:system,代码行数:17,代码来源:SimpleAuthenticationServiceTest.java

示例8: create

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //导入依赖的package包/类
public static HashMap<Class<? extends BiokoException>, HttpError> create() {
	HashMap<Class<? extends BiokoException>, HttpError> exceptionMap = new HashMap<Class<? extends BiokoException>, HttpError>();
	exceptionMap.put(BadCommandInvocationException.class, new HttpError(400));
	exceptionMap.put(AuthenticationFailureException.class, new HttpError(401));
	exceptionMap.put(EntityNotFoundException.class, new HttpError(404));
	exceptionMap.put(CommandNotFoundException.class, new HttpError(404));
	
	exceptionMap.put(ValidationException.class, new HttpError(400));
	exceptionMap.put(CommandException.class, new HttpError(500));
	
	exceptionMap.put(EasterEggException.class, new HttpError(418));
	return exceptionMap;
}
 
开发者ID:bioko,项目名称:http-test,代码行数:14,代码来源:HttpResponseExceptionFactory.java

示例9: createInvalidLoginException

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //导入依赖的package包/类
public static AuthenticationFailureException createInvalidLoginException() {
	String[] message = sErrorMap.get(FieldNames.INVALID_LOGIN_CODE);
	Fields fields = new Fields(
			ErrorEntity.ERROR_CODE, FieldNames.INVALID_LOGIN_CODE,
			ErrorEntity.ERROR_MESSAGE, new StringBuilder()
				.append(message[0])
				.toString());
	
	ErrorEntity entity = new ErrorEntity();
	entity.setAll(fields);
	return new AuthenticationFailureException(entity);
}
 
开发者ID:bioko,项目名称:system,代码行数:13,代码来源:CommandExceptionsFactory.java

示例10: createTokenNotFoundException

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //导入依赖的package包/类
public static AuthenticationFailureException createTokenNotFoundException() {
	String[] message = sErrorMap.get(FieldNames.AUTHENTICATION_REQUIRED_CODE);
	Fields fields = new Fields(
			ErrorEntity.ERROR_CODE, FieldNames.AUTHENTICATION_REQUIRED_CODE,
			ErrorEntity.ERROR_MESSAGE, new StringBuilder()
				.append(message[0])
				.toString());

	ErrorEntity entity = new ErrorEntity();
	entity.setAll(fields);
	return new AuthenticationFailureException(entity);
}
 
开发者ID:bioko,项目名称:system,代码行数:13,代码来源:CommandExceptionsFactory.java

示例11: createUnauthorisedAccessException

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //导入依赖的package包/类
public static AuthenticationFailureException createUnauthorisedAccessException() {
	String[] message = sErrorMap.get(FieldNames.AUTHENTICATION_REQUIRED_CODE);
	Fields fields = new Fields(
			ErrorEntity.ERROR_CODE, FieldNames.AUTHENTICATION_REQUIRED_CODE,
			ErrorEntity.ERROR_MESSAGE, new StringBuilder()
				.append(message[0])
				.toString());
	
	ErrorEntity entity = new ErrorEntity();
	entity.setAll(fields);
	return new AuthenticationFailureException(entity);
}
 
开发者ID:bioko,项目名称:system,代码行数:13,代码来源:CommandExceptionsFactory.java

示例12: createInsufficientPrivilegesException

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //导入依赖的package包/类
public static AuthenticationFailureException createInsufficientPrivilegesException() {
	String[] message = sErrorMap.get(FieldNames.INSUFFICIENT_PRIVILEGES_CODE);
	Fields fields = new Fields(
			ErrorEntity.ERROR_CODE, FieldNames.INSUFFICIENT_PRIVILEGES_CODE,
			ErrorEntity.ERROR_MESSAGE, new StringBuilder()
				.append(message[0])
				.toString());
	
	ErrorEntity entity = new ErrorEntity();
	entity.setAll(fields);
	return new AuthenticationFailureException(entity);
}
 
开发者ID:bioko,项目名称:system,代码行数:13,代码来源:CommandExceptionsFactory.java

示例13: createTokenExpiredException

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //导入依赖的package包/类
public static AuthenticationFailureException createTokenExpiredException() {
	String[] message = sErrorMap.get(FieldNames.TOKEN_EXPIRED_CODE);
	Fields fields = new Fields(
			ErrorEntity.ERROR_CODE, FieldNames.TOKEN_EXPIRED_CODE,
			ErrorEntity.ERROR_MESSAGE, new StringBuilder()
				.append(message[0])
				.toString());
	
	ErrorEntity entity = new ErrorEntity();
	entity.setAll(fields);
	return new AuthenticationFailureException(entity);
}
 
开发者ID:bioko,项目名称:system,代码行数:13,代码来源:CommandExceptionsFactory.java

示例14: createFacebookAuthenticationFailure

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //导入依赖的package包/类
public static AuthenticationFailureException createFacebookAuthenticationFailure(String facebookErrorType) {
	String[] message = sErrorMap.get(FieldNames.FACEBOOK_AUTH_FAILURE_CODE);
	Fields fields = new Fields(
			ErrorEntity.ERROR_CODE, FieldNames.FACEBOOK_AUTH_FAILURE_CODE,
			ErrorEntity.ERROR_MESSAGE, new StringBuilder()
				.append(message[0])
				.append(facebookErrorType).toString());
	
	ErrorEntity entity = new ErrorEntity();
	entity.setAll(fields);
	return new AuthenticationFailureException(entity);
}
 
开发者ID:bioko,项目名称:system,代码行数:13,代码来源:CommandExceptionsFactory.java

示例15: authenticate

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //导入依赖的package包/类
@Override
public AuthResponse authenticate(Fields fields, List<String> requiredRoles) throws AuthenticationFailureException {
       String token = (String) fields.get(AUTH_TOKEN);
       if (token == null) {
           throw CommandExceptionsFactory.createUnauthorisedAccessException();
       }
       Authentication auth = fAuthRepo.retrieveByForeignKey(Authentication.TOKEN, token);
       if (auth == null) {
		throw CommandExceptionsFactory.createUnauthorisedAccessException();
       } else if (isExpired(auth)) {
           fAuthRepo.delete(auth.getId());
           throw CommandExceptionsFactory.createTokenExpiredException();
	} else if (!requiredRoles.isEmpty()) {
		String userRoles = auth.get(Authentication.ROLES);
		ensureRoles(requiredRoles, userRoles);
	}

       auth.set(Authentication.TOKEN_EXPIRE, renewAuthentication());
       try {
           fAuthRepo.save(auth);
       } catch (ValidationException|RepositoryException exception) {
           LOGGER.error("Unexpected error while updating authentication", exception);
           throw new AuthenticationFailureException(exception);
       }
	
	return new AuthResponse(
               new Fields(GenericFieldNames.AUTH_LOGIN_ID, auth.get(Authentication.LOGIN_ID)),
               new Fields(AUTH_TOKEN, token,
                       AUTH_TOKEN_EXPIRE, auth.get(Authentication.TOKEN_EXPIRE)));
}
 
开发者ID:bioko,项目名称:system,代码行数:31,代码来源:TokenAuthenticationServiceImpl.java


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