本文整理汇总了Java中org.apache.shiro.authz.UnauthenticatedException类的典型用法代码示例。如果您正苦于以下问题:Java UnauthenticatedException类的具体用法?Java UnauthenticatedException怎么用?Java UnauthenticatedException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnauthenticatedException类属于org.apache.shiro.authz包,在下文中一共展示了UnauthenticatedException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkImplies
import org.apache.shiro.authz.UnauthenticatedException; //导入依赖的package包/类
@Override
public boolean checkImplies(Permission requiredPermission) {
if (requiredPermission instanceof ProviderBasedPermission == false) {
return false;
}
ProviderBasedPermission requiredPerm = (ProviderBasedPermission) requiredPermission;
UserPrincipals user = (UserPrincipals) AuthUtils.getSubject().getSession().getAttribute(UserPrincipals.ATTRIBUTE_KEY);
if (user == null) {
throw new UnauthenticatedException("Permission denied: User not logged in: " + requiredPermission);
}
PermissionCheckProviderRequest request = PermissionCheckProviderRequest.createGet(
user.getAlternateIds(), user.getNetworkAddress(), requiredPerm.getPermissionString());
PermissionCheckProviderResult result = _provider.isPermitted(request);
result.checkErrors();
return result.isPermitted(requiredPerm.getPermissionString());
}
示例2: processAuthenticationError
import org.apache.shiro.authz.UnauthenticatedException; //导入依赖的package包/类
private PermissionCheckProviderResult processAuthenticationError(
PermissionCheckProviderRequest request, Exception ex) {
String msg = String.format("Bloomberg authentication failure for user: %s IpAddress: %s",
request.getUserIdBundle(), request.getNetworkAddress());
if (ex.getCause() == null) {
s_logger.warn(msg, ex);
return PermissionCheckProviderResult.ofAuthenticationError(
"Bloomberg authentication error: Unknown cause: " + ex.getMessage());
} else if (ex.getCause() instanceof UnauthenticatedException) {
s_logger.debug(msg);
return PermissionCheckProviderResult.ofAuthenticationError(
"Bloomberg authentication failed: " + ex.getCause().getMessage());
} else {
s_logger.warn(msg, ex.getCause());
return PermissionCheckProviderResult.ofAuthenticationError(
"Bloomberg authentication error: " + ex.getCause().getClass().getName() + ": " + ex.getMessage());
}
}
示例3: unauthorizedIdentity
import org.apache.shiro.authz.UnauthenticatedException; //导入依赖的package包/类
@Test(expectedExceptions = UnauthenticatedException.class)
public void unauthorizedIdentity() {
SessionProvider sessionProvider = null;
try {
BloombergConnector connector = BloombergTestUtils.getBloombergBipeConnector();
connector.getSessionOptions().setAuthenticationOptions(BloombergConstants.AUTH_APP_PREFIX + "UnknownAppName");
sessionProvider = new SessionProvider(connector, Lists.newArrayList(BloombergConstants.AUTH_SVC_NAME, BloombergConstants.MKT_DATA_SVC_NAME, BloombergConstants.REF_DATA_SVC_NAME));
sessionProvider.start();
BloombergBpipeApplicationUserIdentityProvider provider = new BloombergBpipeApplicationUserIdentityProvider(sessionProvider);
provider.getIdentity();
} finally {
if (sessionProvider != null) {
sessionProvider.stop();
}
}
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:18,代码来源:BloombergBpipeApplicationUserIdentityProviderTest.java
示例4: checkSubjectIs
import org.apache.shiro.authz.UnauthenticatedException; //导入依赖的package包/类
private void checkSubjectIs(String id) {
try {
Subject subject = SecurityUtils.getSubject();
if (subject.isAuthenticated()) {
if (id.equals( ((UserInfo)subject.getPrincipal()).getOpenid() ) || subject.hasRole(RegAuthorizationInfo.ADMINSTRATOR_ROLE) ) {
return;
} else {
throw new AuthorizationException("Cannot change credentials for another user");
}
} else {
throw new UnauthenticatedException();
}
} catch (UnavailableSecurityManagerException e) {
// Allow to proceed if no security system is configured
}
}
示例5: unauthenticated
import org.apache.shiro.authz.UnauthenticatedException; //导入依赖的package包/类
@ExceptionHandler(value = {UnauthenticatedException.class})
public RedirectView unauthenticated(WebRequest request) {
// @RequiresUser등으로 로그인으로 강제 전환이 이루어질때, 다시 돌아올 위치를 저장.
if (request instanceof ServletWebRequest) {
ServletWebRequest swr = (ServletWebRequest) request;
if (swr.getRequest() != null) {
// NOTE: ...이거 이외에도 ㅎㅎㅎ 페이지들 jsp으로 그대로 redirect해버림.
final String s = ObjectUtils.toString(swr.getRequest().getRequestURL());
if (false == (s.startsWith("/WEB-INF/") && s.endsWith(".jsp"))) {
LOG.debug(String.format("SAVE REQUEST FOR LOGIN-SUCCESS-REDIRECT = [%s]", swr.getRequest().getRequestURL()));
WebUtils.saveRequest(swr.getRequest());
}
}
}
return new RedirectView(String.format("%s/a/error/unauthenticated", WebappPath.getWebappPath()));
}
示例6: intercept
import org.apache.shiro.authz.UnauthenticatedException; //导入依赖的package包/类
@Override
public Object intercept(AnnotationInterceptChain chain, Response response, Request request, RequiresAuthentication annotation) throws Throwable {
if (!SecurityUtils.getSubject().isAuthenticated()) {
throw new UnauthenticatedException("The current Subject is not authenticated. Access denied.");
}
return chain.intercept();
}
示例7: toResponse
import org.apache.shiro.authz.UnauthenticatedException; //导入依赖的package包/类
@Override
public Response toResponse(UnauthenticatedException exception) {
ResponseBuilder builder = Response.status(Response.Status.UNAUTHORIZED);
builder.header("WWW-Authenticate", HttpServletRequest.BASIC_AUTH + " realm=\"" + appName + "\"");
if (exception.getMessage() != null)
builder = builder.entity(exception.getMessage()).type("text/plain");
return builder.build();
}
示例8: authHandler
import org.apache.shiro.authz.UnauthenticatedException; //导入依赖的package包/类
/**
* 没有认证
* @return
*/
@ExceptionHandler(value = UnauthenticatedException.class)
public ModelAndView authHandler(){
ModelAndView mv = new ModelAndView();
mv.setViewName("redirect:/login");
return mv;
}
示例9: invoke
import org.apache.shiro.authz.UnauthenticatedException; //导入依赖的package包/类
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
checkState(initialized);
Subject subject = subjectProvider.get();
if (subject.isAuthenticated()) {
return invocation.proceed();
} else {
// This is a special exception that will signal the BasicHttpAuthenticationFilter to send
// a 401 with a challenge. This is necessary at this layer since we only apply this
// interceptor to methods that require authentication.
throw new UnauthenticatedException();
}
}
示例10: handleUnauthenticated
import org.apache.shiro.authz.UnauthenticatedException; //导入依赖的package包/类
@Override
protected void handleUnauthenticated(
HttpServletRequest request,
HttpServletResponse response,
FilterChain chain) throws IOException, ServletException {
// Incoming request is unauthenticated, but some RPCs might be okay with that.
try {
chain.doFilter(request, response);
} catch (UnauthenticatedException e) {
super.handleUnauthenticated(request, response, chain);
}
}
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:14,代码来源:ShiroKerberosPermissiveAuthenticationFilter.java
示例11: testInterceptsUnauthenticatedException
import org.apache.shiro.authz.UnauthenticatedException; //导入依赖的package包/类
@Test
public void testInterceptsUnauthenticatedException() throws ServletException, IOException {
mockServlet.service(anyObject(HttpServletRequest.class), anyObject(HttpServletResponse.class));
expectLastCall().andThrow(new UnauthenticatedException());
replayAndStart();
ClientResponse clientResponse = getRequestBuilder(PATH).get(ClientResponse.class);
assertEquals(HttpServletResponse.SC_UNAUTHORIZED, clientResponse.getStatus());
assertEquals(
ShiroKerberosAuthenticationFilter.NEGOTIATE,
clientResponse.getHeaders().getFirst(HttpHeaders.WWW_AUTHENTICATE));
}
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:15,代码来源:ShiroKerberosPermissiveAuthenticationFilterTest.java
示例12: testInvokeNotAuthenticated
import org.apache.shiro.authz.UnauthenticatedException; //导入依赖的package包/类
@Test(expected = UnauthenticatedException.class)
public void testInvokeNotAuthenticated() throws Throwable {
expect(subject.isAuthenticated()).andReturn(false);
replayAndInitialize();
interceptor.invoke(methodInvocation);
}
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:9,代码来源:ShiroAuthenticatingThriftInterceptorTest.java
示例13: assertAuthzCheckPossible
import org.apache.shiro.authz.UnauthenticatedException; //导入依赖的package包/类
protected void assertAuthzCheckPossible() throws AuthorizationException {
if (!hasPrincipals()) {
String msg = "This subject is anonymous - it does not have any identifying principals and " +
"authorization operations require an identity to check against. A Subject instance will " +
"acquire these identifying principals automatically after a successful login is performed " +
"be executing " + Subject.class.getName() + ".login(AuthenticationToken) or when 'Remember Me' " +
"functionality is enabled by the SecurityManager. This exception can also occur when a " +
"previously logged-in Subject has logged out which " +
"makes it anonymous again. Because an identity is currently not known due to any of these " +
"conditions, authorization is denied.";
throw new UnauthenticatedException(msg);
}
}
示例14: cleanup
import org.apache.shiro.authz.UnauthenticatedException; //导入依赖的package包/类
/**
* Overrides the default behavior to call {@link #onAccessDenied} and swallow the exception if the exception is
* {@link UnauthenticatedException}.
*/
@Override
protected void cleanup(ServletRequest request, ServletResponse response, Exception existing) throws ServletException, IOException {
if (existing instanceof UnauthenticatedException || (existing instanceof ServletException && existing.getCause() instanceof UnauthenticatedException))
{
try {
onAccessDenied(request, response);
existing = null;
} catch (Exception e) {
existing = e;
}
}
super.cleanup(request, response, existing);
}
示例15: intercept
import org.apache.shiro.authz.UnauthenticatedException; //导入依赖的package包/类
@Override
public Object intercept(AnnotationInterceptChain chain, Response response, Request request, RequiresGuest annotation) throws Throwable {
if (SecurityUtils.getSubject().getPrincipal() != null) {
throw new UnauthenticatedException("Attempting to perform a guest-only operation. The current Subject is " +
"not a guest (they have been authenticated or remembered from a previous login). Access " +
"denied.");
}
return chain.intercept();
}