类javax.servlet.annotation.HttpConstraint源码实例Demo

下面列出了怎么用javax.servlet.annotation.HttpConstraint的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: packagedrone   文件: ChannelController.java
@Secured ( false )
@RequestMapping ( value = "/channel/{channelId}/view", method = RequestMethod.GET )
@HttpConstraint ( PERMIT )
public ModelAndView view ( @PathVariable ( "channelId" ) final String channelId, final HttpServletRequest request, final HttpServletResponse response ) throws ServletException, IOException
{
    final Optional<ChannelInformation> channel = this.channelService.getState ( By.name ( channelId ) );
    if ( channel.isPresent () )
    {
        return new ModelAndView ( String.format ( "redirect:/channel/%s/view", channel.get ().getId () ) );
    }
    else
    {
        request.getRequestDispatcher ( "tree" ).forward ( request, response );
        return null;
    }
}
 
源代码2 项目: packagedrone   文件: ChannelController.java
@Secured ( false )
@RequestMapping ( value = "/channel/{channelId}/validation", method = RequestMethod.GET )
@HttpConstraint ( PERMIT )
public ModelAndView viewValidation ( @PathVariable ( "channelId" ) final String channelId )
{
    try
    {
        return this.channelService.accessCall ( By.id ( channelId ), ReadableChannel.class, channel -> {
            final ModelAndView result = new ModelAndView ( "channel/validation" );

            result.put ( "channel", channel.getInformation () );
            result.put ( "messages", channel.getInformation ().getState ().getValidationMessages () );
            result.put ( "aspects", Activator.getAspects ().getAspectInformations () );

            return result;
        } );
    }
    catch ( final ChannelNotFoundException e )
    {
        return CommonController.createNotFound ( "channel", channelId );
    }
}
 
源代码3 项目: packagedrone   文件: ChannelController.java
@Secured ( false )
@RequestMapping ( value = "/channel/{channelId}/details", method = RequestMethod.GET )
@HttpConstraint ( PERMIT )
public ModelAndView details ( @PathVariable ( "channelId" ) final String channelId )
{
    final ModelAndView result = new ModelAndView ( "channel/details" );

    try
    {
        this.channelService.accessRun ( By.id ( channelId ), ReadableChannel.class, ( channel ) -> {
            result.put ( "channel", channel.getInformation () );
        } );
    }
    catch ( final ChannelNotFoundException e )
    {
        return CommonController.createNotFound ( "channel", channelId );
    }

    return result;
}
 
源代码4 项目: packagedrone   文件: ChannelController.java
@RequestMapping ( "/channel/{channelId}/help/p2" )
@Secured ( false )
@HttpConstraint ( PERMIT )
public ModelAndView helpP2 ( @PathVariable ( "channelId" ) final String channelId )
{
    return withChannel ( channelId, ReadableChannel.class, channel -> {
        final Map<String, Object> model = new HashMap<> ();

        model.put ( "channel", channel.getInformation () );
        model.put ( "sitePrefix", this.sitePrefix.getSitePrefix () );

        model.put ( "p2Active", channel.hasAspect ( "p2.repo" ) );

        return new ModelAndView ( "channel/help/p2", model );
    } );
}
 
源代码5 项目: packagedrone   文件: ChannelController.java
@RequestMapping ( value = "/channel/{channelId}/viewCacheEntry", method = RequestMethod.GET )
@HttpConstraint ( rolesAllowed = { "MANAGER", "ADMIN" } )
public ModelAndView viewCacheEntry ( @PathVariable ( "channelId" ) final String channelId, @RequestParameter ( "namespace" ) final String namespace, @RequestParameter ( "key" ) final String key, final HttpServletResponse response )
{
    return withChannel ( channelId, ReadableChannel.class, channel -> {

        if ( !channel.streamCacheEntry ( new MetaKey ( namespace, key ), entry -> {
            logger.trace ( "Length: {}, Mime: {}", entry.getSize (), entry.getMimeType () );

            response.setContentLengthLong ( entry.getSize () );
            response.setContentType ( entry.getMimeType () );
            response.setHeader ( "Content-Disposition", String.format ( "inline; filename=%s", URLEncoder.encode ( entry.getName (), "UTF-8" ) ) );
            // response.setHeader ( "Content-Disposition", String.format ( "attachment; filename=%s", entry.getName () ) );
            ByteStreams.copy ( entry.getStream (), response.getOutputStream () );
        } ) )
        {
            return CommonController.createNotFound ( "channel cache entry", String.format ( "%s:%s", namespace, key ) );
        }

        return null;
    } );
}
 
源代码6 项目: packagedrone   文件: StorageController.java
@HttpConstraint ( rolesAllowed = "ADMIN" )
@RequestMapping ( value = "/system/storage/exportAllFs", method = RequestMethod.POST )
public ModelAndView exportAllFsPost ( @Valid @FormData ( "command" ) final ExportAllFileSystemCommand command, final BindingResult result)
{
    if ( result.hasErrors () )
    {
        return new ModelAndView ( "exportAllFs" );
    }

    File location;
    try
    {
        location = performExport ( command );
    }
    catch ( final IOException e )
    {
        return CommonController.createError ( "Spool out", null, e, true );
    }

    final String bytes = Strings.bytes ( location.length () );

    return CommonController.createSuccess ( "Spool out", "to file system", String.format ( "<strong>Complete!</strong> Successfully spooled out all channels to <code>%s</code> (%s)", location, bytes ) );
}
 
源代码7 项目: packagedrone   文件: P2MetaDataController.java
@RequestMapping ( value = "/{channelId}/info" )
@Secured ( false )
@HttpConstraint ( PERMIT )
public ModelAndView info ( @PathVariable ( "channelId" ) final String channelId) throws Exception
{
    return Channels.withChannel ( this.service, channelId, ReadableChannel.class, channel -> {
        final Map<String, Object> model = new HashMap<> ();

        final Map<MetaKey, String> metaData = channel.getMetaData ();

        final P2MetaDataInformation channelInfo = new P2MetaDataInformation ();
        MetaKeys.bind ( channelInfo, metaData );

        model.put ( "channel", channel.getInformation () );
        model.put ( "channelInfo", channelInfo );

        return new ModelAndView ( "p2info", model );
    } );

}
 
源代码8 项目: packagedrone   文件: P2RepoController.java
@RequestMapping ( value = "/{channelId}/info" )
@Secured ( false )
@HttpConstraint ( PERMIT )
public ModelAndView info ( @PathVariable ( "channelId" ) final String channelId) throws Exception
{
    return Channels.withChannel ( this.service, channelId, ReadableChannel.class, channel -> {

        final Map<String, Object> model = new HashMap<> ();

        final Map<MetaKey, String> metaData = channel.getMetaData ();

        final P2ChannelInformation channelInfo = new P2ChannelInformation ();
        MetaKeys.bind ( channelInfo, metaData );

        model.put ( "channel", channel.getInformation () );
        model.put ( "channelInfo", channelInfo );

        return new ModelAndView ( "p2info", model );
    } );
}
 
源代码9 项目: packagedrone   文件: HttpConstraints.java
public static boolean isCallAllowed ( final ControllerMethod m, final HttpServletRequest request )
{
    HttpConstraint constraint = m.getMethod ().getAnnotation ( HttpConstraint.class );

    if ( constraint == null )
    {
        constraint = m.getControllerClazz ().getAnnotation ( HttpConstraint.class );
    }

    if ( constraint == null )
    {
        return true;
    }

    return HttpContraintControllerInterceptor.isAllowed ( constraint, request );
}
 
源代码10 项目: packagedrone   文件: UserController.java
@RequestMapping ( value = "/{userId}/view", method = RequestMethod.GET )
@HttpConstraint ( value = EmptyRoleSemantic.PERMIT )
public ModelAndView viewUser ( @PathVariable ( "userId" ) final String userId, final HttpServletRequest request )
{
    final boolean you = isYou ( userId, request );

    if ( !you && !request.isUserInRole ( "ADMIN" ) )
    {
        return CommonController.createAccessDenied ();
    }

    final DatabaseUserInformation user = this.storage.getUserDetails ( userId );

    if ( user == null || user.getDetails ( DatabaseDetails.class ) == null )
    {
        return CommonController.createNotFound ( "user", userId );
    }

    final ModelAndView model = new ModelAndView ( "user/view" );
    model.put ( "user", user );
    model.put ( "you", you );
    return model;
}
 
源代码11 项目: packagedrone   文件: ChannelController.java
@Secured ( false )
@RequestMapping ( value = "/channel", method = RequestMethod.GET )
@HttpConstraint ( PERMIT )
public ModelAndView list ( @RequestParameter ( value = "start", required = false ) final Integer startPage )
{
    final ModelAndView result = new ModelAndView ( "channel/list" );

    final List<ChannelListEntry> channels = this.channelService.list ().stream ().flatMap ( ChannelController::toEntry ).collect ( Collectors.toList () );
    channels.sort ( CHANNEL_LIST_ENTRY_COMPARATOR );

    result.put ( "channels", Pagination.paginate ( startPage, 10, channels ) );

    return result;
}
 
源代码12 项目: packagedrone   文件: ChannelController.java
@Secured ( false )
@RequestMapping ( value = "/channel/{channelId}/viewPlain", method = RequestMethod.GET )
@HttpConstraint ( PERMIT )
public ModelAndView viewPlain ( @PathVariable ( "channelId" ) final String channelId )
{
    try
    {
        return this.channelService.accessCall ( By.id ( channelId ), ReadableChannel.class, ( channel ) -> {

            final Map<String, Object> model = new HashMap<> ();

            model.put ( "channel", channel.getInformation () );

            final Collection<ArtifactInformation> artifacts = channel.getContext ().getArtifacts ().values ();

            if ( artifacts.size () > maxWebListSize () )
            {
                return viewTooMany ( channel );
            }

            // sort artifacts

            final List<ArtifactInformation> sortedArtifacts = new ArrayList<> ( artifacts );
            sortedArtifacts.sort ( Comparator.comparing ( ArtifactInformation::getName ) );
            model.put ( "sortedArtifacts", sortedArtifacts );

            return new ModelAndView ( "channel/view", model );
        } );
    }
    catch ( final ChannelNotFoundException e )
    {
        return CommonController.createNotFound ( "channel", channelId );
    }
}
 
源代码13 项目: packagedrone   文件: ChannelController.java
@RequestMapping ( "/channel/{channelId}/help/api" )
@Secured ( false )
@HttpConstraint ( PERMIT )
public ModelAndView helpApi ( @PathVariable ( "channelId" ) final String channelId, final HttpServletRequest request )
{
    return withChannel ( channelId, ReadableChannel.class, channel -> {
        final Map<String, Object> model = new HashMap<> ();

        model.put ( "channel", channel.getInformation () );
        model.put ( "sitePrefix", this.sitePrefix.getSitePrefix () );

        final String exampleKey;
        if ( request.isUserInRole ( "MANAGER" ) )
        {
            final Collection<DeployKey> keys = this.channelService.getChannelDeployKeys ( By.id ( channel.getId ().getId () ) ).orElse ( emptyList () );
            exampleKey = keys.stream ().map ( DeployKey::getKey ).findFirst ().orElse ( DEFAULT_EXAMPLE_KEY );
        }
        else
        {
            exampleKey = DEFAULT_EXAMPLE_KEY;
        }

        model.put ( "hasExampleKey", !DEFAULT_EXAMPLE_KEY.equals ( exampleKey ) );

        model.put ( "exampleKey", exampleKey );
        model.put ( "exampleSitePrefix", makeCredentialsPrefix ( this.sitePrefix.getSitePrefix (), "deploy", exampleKey ) );

        return new ModelAndView ( "channel/help/api", model );
    } );
}
 
源代码14 项目: packagedrone   文件: ChannelController.java
@RequestMapping ( value = "/channel/{channelId}/viewCache", method = RequestMethod.GET )
@HttpConstraint ( rolesAllowed = { "MANAGER", "ADMIN" } )
public ModelAndView viewCache ( @PathVariable ( "channelId" ) final String channelId )
{
    return withChannel ( channelId, ReadableChannel.class, channel -> {
        final Map<String, Object> model = new HashMap<> ();

        model.put ( "channel", channel.getInformation () );
        model.put ( "cacheEntries", channel.getCacheEntries ().values () );

        return new ModelAndView ( "channel/viewCache", model );
    } );
}
 
源代码15 项目: packagedrone   文件: StorageController.java
@RequestMapping ( value = "/system/storage" )
@HttpConstraint ( rolesAllowed = { "MANAGER", "ADMIN" } )
public ModelAndView index ()
{
    final Map<String, Object> model = new HashMap<> ();
    return new ModelAndView ( "index", model );
}
 
源代码16 项目: packagedrone   文件: ArtifactController.java
@RequestMapping ( value = "/channel/{channelId}/artifacts/{artifactId}/generate", method = RequestMethod.GET )
@HttpConstraint ( PERMIT )
public ModelAndView generate ( @PathVariable ( "channelId" ) final String channelId, @PathVariable ( "artifactId" ) final String artifactId)
{
    return Channels.withArtifact ( this.service, channelId, artifactId, ModifiableChannel.class, ( channel, artifact ) -> {
        channel.getContext ().regenerate ( artifact.getId () );
        return new ModelAndView ( "redirect:/channel/" + UrlEscapers.urlPathSegmentEscaper ().escape ( artifact.getChannelId ().getId () ) + "/view" );
    } );
}
 
源代码17 项目: packagedrone   文件: JobController.java
@RequestMapping ( value = "/{factoryId}/create", method = RequestMethod.POST )
@HttpConstraint ( rolesAllowed = { "MANAGER", "ADMIN" } )
public ModelAndView create ( @PathVariable ( "factoryId" ) final String factoryId, @RequestParameter (
        required = false, value = "data" ) final String data)
{
    final JobHandle job = this.manager.startJob ( factoryId, data );

    // forward to get loose of the POST request, so that we can reload the status page
    return new ModelAndView ( String.format ( "redirect:/job/%s/view", job.getId () ) );
}
 
源代码18 项目: packagedrone   文件: BackupController.java
@RequestMapping ( value = "/provision", method = RequestMethod.POST )
@Secured ( false )
@HttpConstraint ( PERMIT )
public void provision ( final HttpServletRequest request, final HttpServletResponse response ) throws IOException
{
    internalProvision ( request, response );
}
 
@Override
public RequestHandler before ( final Object controller, final Method m, final HttpServletRequest request, final HttpServletResponse response, final BiFunction<HttpServletRequest, HttpServletResponse, RequestHandler> next ) throws Exception
{
    HttpConstraint s = m.getAnnotation ( HttpConstraint.class );
    if ( s == null )
    {
        s = controller.getClass ().getAnnotation ( HttpConstraint.class );
    }

    logger.trace ( "Checking http contraints: {} for {}", s, request );

    if ( s == null )
    {
        return next.apply ( request, response );
    }

    if ( isAllowed ( s, request ) )
    {
        return next.apply ( request, response );
    }

    final Principal p = request.getUserPrincipal ();
    if ( p == null )
    {
        // make a different when no one is logged in
        return handleLoginRequired ( request, response );
    }

    return handleAccessDenied ( response );
}
 
public static boolean isAllowed ( final HttpConstraint constraint, final HttpServletRequest request )
{
    final EmptyRoleSemantic empty = constraint.value ();
    final String[] allowedRoles = constraint.rolesAllowed ();

    if ( allowedRoles == null || allowedRoles.length <= 0 )
    {
        // no roles
        if ( EmptyRoleSemantic.PERMIT.equals ( empty ) )
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        // check all roles .. one is ok

        for ( final String role : allowedRoles )
        {
            if ( request.isUserInRole ( role ) )
            {
                return true;
            }
        }

        // we ran out of options

        return false;
    }
}
 
源代码21 项目: packagedrone   文件: UserController.java
@RequestMapping ( "/{userId}/newPassword" )
@HttpConstraint ( value = EmptyRoleSemantic.PERMIT )
public ModelAndView changePassword ( @PathVariable ( "userId" ) final String userId, final HttpServletRequest request )
{
    final Map<String, Object> model = new HashMap<> ();

    final boolean you = isYou ( userId, request );
    if ( !you && !request.isUserInRole ( "ADMIN" ) )
    {
        return CommonController.createAccessDenied ();
    }

    final DatabaseUserInformation user = this.storage.getUserDetails ( userId );
    if ( user == null )
    {
        return CommonController.createNotFound ( "user", userId );
    }

    final DatabaseDetails details = user.getDetails ( DatabaseDetails.class );

    if ( details == null )
    {
        return CommonController.createNotFound ( "details", userId );
    }

    final NewPassword data = new NewPassword ();
    data.setEmail ( details.getEmail () );

    model.put ( "you", you );
    model.put ( "command", data );

    return new ModelAndView ( "user/newPassword", model );
}
 
源代码22 项目: packagedrone   文件: UserController.java
@RequestMapping ( value = "/{userId}/newPassword", method = RequestMethod.POST )
@HttpConstraint ( value = EmptyRoleSemantic.PERMIT )
public ModelAndView changePasswordPost ( @PathVariable ( "userId" ) final String userId, @Valid @FormData ( "command" ) final NewPassword data, final BindingResult result, final HttpServletRequest request )
{
    final boolean you = isYou ( userId, request );

    if ( !you && !request.isUserInRole ( "ADMIN" ) )
    {
        return CommonController.createAccessDenied ();
    }

    final Map<String, Object> model = new HashMap<> ();
    model.put ( "you", you );

    if ( result.hasErrors () )
    {
        model.put ( "command", data );
        return new ModelAndView ( "user/newPassword", model );
    }

    try
    {
        if ( !you /* but we are ADMIN */ )
        {
            this.storage.updatePassword ( userId, null, data.getPassword () );
        }
        else
        {
            this.storage.updatePassword ( userId, data.getCurrentPassword (), data.getPassword () );
        }

        return new ModelAndView ( "redirect:/user/" + userId + "/view" );
    }
    catch ( final Exception e )
    {
        return CommonController.createError ( "Error", "Failed to change password", e );
    }
}
 
源代码23 项目: piranha   文件: ServletSecurityElementTest.java
/**
 * Test constructor.
 */
@Test
public void testConstructor4() {
    ServletSecurity servletSecurity = new ServletSecurity() {
        @Override
        public HttpMethodConstraint[] httpMethodConstraints() {
            return new HttpMethodConstraint[]{
                new HttpMethodConstraint() {
                    @Override
                    public ServletSecurity.EmptyRoleSemantic emptyRoleSemantic() {
                        return ServletSecurity.EmptyRoleSemantic.PERMIT;
                    }

                    @Override
                    public String[] rolesAllowed() {
                        return new String[]{};
                    }

                    @Override
                    public ServletSecurity.TransportGuarantee transportGuarantee() {
                        return ServletSecurity.TransportGuarantee.NONE;
                    }

                    @Override
                    public String value() {
                        return "HEAD";
                    }

                    @Override
                    public Class<? extends Annotation> annotationType() {
                        throw new UnsupportedOperationException("Not supported yet.");
                    }
                }
            };
        }

        @Override
        public HttpConstraint value() {
            return new HttpConstraint() {
                @Override
                public String[] rolesAllowed() {
                    return new String[]{};
                }

                @Override
                public ServletSecurity.TransportGuarantee transportGuarantee() {
                    return ServletSecurity.TransportGuarantee.NONE;
                }

                @Override
                public ServletSecurity.EmptyRoleSemantic value() {
                    return ServletSecurity.EmptyRoleSemantic.PERMIT;
                }

                @Override
                public Class<? extends Annotation> annotationType() {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            };
        }

        @Override
        public Class<? extends Annotation> annotationType() {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    };
    ServletSecurityElement servletSecurityElement = new ServletSecurityElement(servletSecurity);
    assertNotNull(servletSecurityElement);
}
 
源代码24 项目: packagedrone   文件: TransferController.java
@RequestMapping ( value = "/channel/{channelId}/export", method = RequestMethod.GET )
@HttpConstraint ( value = EmptyRoleSemantic.PERMIT )
public ModelAndView exportChannel ( @PathVariable ( "channelId" ) final String channelId, final HttpServletResponse response )
{
    return performExport ( response, makeExportFileName ( channelId ), ( stream ) -> this.transferService.exportChannel ( channelId, stream ) );
}
 
源代码25 项目: packagedrone   文件: TransferController.java
@RequestMapping ( value = "/channel/export", method = RequestMethod.GET )
@HttpConstraint ( value = EmptyRoleSemantic.PERMIT )
public ModelAndView exportAll ( final HttpServletResponse response )
{
    return performExport ( response, makeExportFileName ( null ), this.transferService::exportAll );
}
 
源代码26 项目: packagedrone   文件: StorageController.java
@HttpConstraint ( rolesAllowed = "ADMIN" )
@RequestMapping ( value = "/system/storage/exportAllFs", method = RequestMethod.GET )
public ModelAndView exportAllFs ()
{
    return new ModelAndView ( "exportAllFs" );
}
 
 类所在包
 类方法
 同包方法